|
@@ -12,6 +12,7 @@ from tracim.command import Extender
|
12
|
12
|
#from tracim.lib.daemons import RadicaleDaemon
|
13
|
13
|
#from tracim.lib.email import get_email_manager
|
14
|
14
|
from tracim.exceptions import AlreadyExistError
|
|
15
|
+from tracim.exceptions import NotificationNotSend
|
15
|
16
|
from tracim.exceptions import CommandAbortedError
|
16
|
17
|
from tracim.lib.core.group import GroupApi
|
17
|
18
|
from tracim.lib.core.user import UserApi
|
|
@@ -106,7 +107,13 @@ class UserCommand(AppContextCommand):
|
106
|
107
|
group.users.remove(user)
|
107
|
108
|
self._session.flush()
|
108
|
109
|
|
109
|
|
- def _create_user(self, login: str, password: str, **kwargs) -> User:
|
|
110
|
+ def _create_user(
|
|
111
|
+ self,
|
|
112
|
+ login: str,
|
|
113
|
+ password: str,
|
|
114
|
+ do_notify: bool,
|
|
115
|
+ **kwargs
|
|
116
|
+ ) -> User:
|
110
|
117
|
if not password:
|
111
|
118
|
if self._password_required():
|
112
|
119
|
raise CommandAbortedError(
|
|
@@ -115,18 +122,23 @@ class UserCommand(AppContextCommand):
|
115
|
122
|
password = ''
|
116
|
123
|
|
117
|
124
|
try:
|
118
|
|
- user = self._user_api.create_minimal_user(email=login)
|
119
|
|
- user.password = password
|
120
|
|
- self._user_api.save(user)
|
|
125
|
+ user = self._user_api.create_user(
|
|
126
|
+ email=login,
|
|
127
|
+ password=password,
|
|
128
|
+ do_save=True,
|
|
129
|
+ do_notify=do_notify,
|
|
130
|
+ )
|
121
|
131
|
# TODO - G.M - 04-04-2018 - [Caldav] Check this code
|
122
|
132
|
# # We need to enable radicale if it not already done
|
123
|
133
|
# daemons = DaemonsManager()
|
124
|
134
|
# daemons.run('radicale', RadicaleDaemon)
|
125
|
|
-
|
126
|
135
|
self._user_api.execute_created_user_actions(user)
|
127
|
136
|
except IntegrityError:
|
128
|
137
|
self._session.rollback()
|
129
|
138
|
raise AlreadyExistError()
|
|
139
|
+ except NotificationNotSend as exception:
|
|
140
|
+ self._session.rollback()
|
|
141
|
+ raise exception
|
130
|
142
|
|
131
|
143
|
return user
|
132
|
144
|
|
|
@@ -166,10 +178,13 @@ class UserCommand(AppContextCommand):
|
166
|
178
|
try:
|
167
|
179
|
user = self._create_user(
|
168
|
180
|
login=parsed_args.login,
|
169
|
|
- password=parsed_args.password
|
|
181
|
+ password=parsed_args.password,
|
|
182
|
+ do_notify=parsed_args.send_email,
|
170
|
183
|
)
|
171
|
184
|
except AlreadyExistError:
|
172
|
185
|
raise CommandAbortedError("Error: User already exist (use `user update` command instead)")
|
|
186
|
+ except NotificationNotSend:
|
|
187
|
+ raise CommandAbortedError("Error: Cannot send email notification, user not created.")
|
173
|
188
|
# TODO - G.M - 04-04-2018 - [Email] Check this code
|
174
|
189
|
# if parsed_args.send_email:
|
175
|
190
|
# email_manager = get_email_manager()
|