Browse Source

Fix issue with user command and user email already exist

Guénaël Muller 6 years ago
parent
commit
61060ac76b

+ 5 - 4
backend/tracim_backend/command/user.py View File

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

+ 2 - 2
backend/tracim_backend/lib/core/user.py View File

275
         if not is_email_correct:
275
         if not is_email_correct:
276
             raise EmailValidationFailed(
276
             raise EmailValidationFailed(
277
                 'Email given form {} is uncorrect'.format(email))  # nopep8
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
         if email_already_exist_in_db:
279
         if email_already_exist_in_db:
280
             raise EmailAlreadyExistInDb(
280
             raise EmailAlreadyExistInDb(
281
                 'Email given {} already exist, please choose something else'.format(email)  # nopep8
281
                 'Email given {} already exist, please choose something else'.format(email)  # nopep8
282
             )
282
             )
283
         return True
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
         Verify if given email does not already exist in db
287
         Verify if given email does not already exist in db
288
         """
288
         """