Przeglądaj źródła

Fix issue with user command and user email already exist

Guénaël Muller 5 lat temu
rodzic
commit
61060ac76b

+ 5 - 4
backend/tracim_backend/command/user.py Wyświetl plik

@@ -127,7 +127,8 @@ class UserCommand(AppContextCommand):
127 127
                     "You must provide -p/--password parameter"
128 128
                 )
129 129
             password = ''
130
-
130
+        if self._user_api.check_email_already_in_db(login):
131
+            raise UserAlreadyExistError()
131 132
         try:
132 133
             user = self._user_api.create_user(
133 134
                 email=login,
@@ -140,12 +141,12 @@ class UserCommand(AppContextCommand):
140 141
             # daemons = DaemonsManager()
141 142
             # daemons.run('radicale', RadicaleDaemon)
142 143
             self._user_api.execute_created_user_actions(user)
143
-        except IntegrityError:
144
+        except IntegrityError as exception:
144 145
             self._session.rollback()
145
-            raise UserAlreadyExistError()
146
+            raise UserAlreadyExistError() from exception
146 147
         except NotificationNotSend as exception:
147 148
             self._session.rollback()
148
-            raise exception
149
+            raise exception from exception
149 150
 
150 151
         return user
151 152
 

+ 2 - 2
backend/tracim_backend/lib/core/user.py Wyświetl plik

@@ -275,14 +275,14 @@ class UserApi(object):
275 275
         if not is_email_correct:
276 276
             raise EmailValidationFailed(
277 277
                 'Email given form {} is uncorrect'.format(email))  # nopep8
278
-        email_already_exist_in_db = self._check_email_already_in_db(email)
278
+        email_already_exist_in_db = self.check_email_already_in_db(email)
279 279
         if email_already_exist_in_db:
280 280
             raise EmailAlreadyExistInDb(
281 281
                 'Email given {} already exist, please choose something else'.format(email)  # nopep8
282 282
             )
283 283
         return True
284 284
 
285
-    def _check_email_already_in_db(self, email: str) -> bool:
285
+    def check_email_already_in_db(self, email: str) -> bool:
286 286
         """
287 287
         Verify if given email does not already exist in db
288 288
         """