|
@@ -20,6 +20,7 @@ from formencode.validators import FieldsMatch
|
20
|
20
|
from tracim.controllers import TIMRestController
|
21
|
21
|
from tracim.lib import CST
|
22
|
22
|
from tracim.lib import helpers as h
|
|
23
|
+from tracim.lib.base import logger
|
23
|
24
|
from tracim.lib.user import UserApi
|
24
|
25
|
from tracim.lib.group import GroupApi
|
25
|
26
|
from tracim.lib.user import UserStaticApi
|
|
@@ -36,7 +37,17 @@ class UserProfileAdminRestController(TIMRestController):
|
36
|
37
|
"""
|
37
|
38
|
allow_only = predicates.in_any_group(Group.TIM_ADMIN_GROUPNAME)
|
38
|
39
|
|
39
|
|
- allowed_profiles = ['tracim-user', 'tracim-manager', 'tracim-admin']
|
|
40
|
+ _ALLOWED_PROFILE_USER = 'tracim-profile-user'
|
|
41
|
+ _ALLOWED_PROFILE_MANAGER = 'tracim-profile-manager'
|
|
42
|
+ _ALLOWED_PROFILE_ADMIN = 'tracim-profile-admin'
|
|
43
|
+
|
|
44
|
+ @property
|
|
45
|
+ def allowed_profiles(self):
|
|
46
|
+ return [
|
|
47
|
+ UserProfileAdminRestController._ALLOWED_PROFILE_USER,
|
|
48
|
+ UserProfileAdminRestController._ALLOWED_PROFILE_MANAGER,
|
|
49
|
+ UserProfileAdminRestController._ALLOWED_PROFILE_ADMIN
|
|
50
|
+ ]
|
40
|
51
|
|
41
|
52
|
def _before(self, *args, **kw):
|
42
|
53
|
"""
|
|
@@ -86,7 +97,7 @@ class UserProfileAdminRestController(TIMRestController):
|
86
|
97
|
|
87
|
98
|
flash_message = _('User updated.') # this is the default value ; should never appear
|
88
|
99
|
|
89
|
|
- if new_profile=='tracim-user':
|
|
100
|
+ if new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_USER:
|
90
|
101
|
if pod_user_group not in user.groups:
|
91
|
102
|
user.groups.append(pod_user_group)
|
92
|
103
|
|
|
@@ -102,7 +113,7 @@ class UserProfileAdminRestController(TIMRestController):
|
102
|
113
|
|
103
|
114
|
flash_message = _('User {} is now a basic user').format(user.get_display_name())
|
104
|
115
|
|
105
|
|
- elif new_profile=='tracim-manager':
|
|
116
|
+ elif new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_MANAGER:
|
106
|
117
|
if pod_user_group not in user.groups:
|
107
|
118
|
user.groups.append(pod_user_group)
|
108
|
119
|
if pod_manager_group not in user.groups:
|
|
@@ -116,7 +127,7 @@ class UserProfileAdminRestController(TIMRestController):
|
116
|
127
|
flash_message = _('User {} can now workspaces').format(user.get_display_name())
|
117
|
128
|
|
118
|
129
|
|
119
|
|
- elif new_profile=='tracim-admin':
|
|
130
|
+ elif new_profile==UserProfileAdminRestController._ALLOWED_PROFILE_ADMIN:
|
120
|
131
|
if pod_user_group not in user.groups:
|
121
|
132
|
user.groups.append(pod_user_group)
|
122
|
133
|
if pod_manager_group not in user.groups:
|
|
@@ -126,8 +137,12 @@ class UserProfileAdminRestController(TIMRestController):
|
126
|
137
|
|
127
|
138
|
flash_message = _('User {} is now an administrator').format(user.get_display_name())
|
128
|
139
|
|
129
|
|
- DBSession.flush()
|
|
140
|
+ else:
|
|
141
|
+ logger.error(self, 'Trying to change user {} profile with unexpected profile {}'.format(user.user_id, new_profile))
|
|
142
|
+ tg.flash(_('Unknown profile'), CST.STATUS_ERROR)
|
|
143
|
+ tg.redirect(redirect_url)
|
130
|
144
|
|
|
145
|
+ DBSession.flush()
|
131
|
146
|
tg.flash(flash_message, CST.STATUS_OK)
|
132
|
147
|
tg.redirect(redirect_url)
|
133
|
148
|
|
|
@@ -231,15 +246,15 @@ class UserRestController(TIMRestController):
|
231
|
246
|
|
232
|
247
|
@tg.require(predicates.in_group(Group.TIM_MANAGER_GROUPNAME))
|
233
|
248
|
@tg.expose()
|
234
|
|
- def post(self, name, email, password, is_pod_manager='off', is_pod_admin='off'):
|
235
|
|
- is_pod_manager = h.on_off_to_boolean(is_pod_manager)
|
236
|
|
- is_pod_admin = h.on_off_to_boolean(is_pod_admin)
|
|
249
|
+ def post(self, name, email, password, is_tracim_manager='off', is_pod_admin='off'):
|
|
250
|
+ is_tracim_manager = h.on_off_to_boolean(is_tracim_manager)
|
|
251
|
+ is_tracim_admin = h.on_off_to_boolean(is_pod_admin)
|
237
|
252
|
current_user = tmpl_context.current_user
|
238
|
253
|
current_user = User()
|
239
|
254
|
if current_user.profile.id < Group.TIM_ADMIN:
|
240
|
255
|
# A manager can't give large rights
|
241
|
|
- is_pod_manager = False
|
242
|
|
- is_pod_admin = False
|
|
256
|
+ is_tracim_manager = False
|
|
257
|
+ is_tracim_admin = False
|
243
|
258
|
|
244
|
259
|
|
245
|
260
|
api = UserApi(current_user)
|
|
@@ -258,9 +273,9 @@ class UserRestController(TIMRestController):
|
258
|
273
|
# Now add the user to related groups
|
259
|
274
|
group_api = GroupApi(current_user)
|
260
|
275
|
user.groups.append(group_api.get_one(Group.TIM_USER))
|
261
|
|
- if is_pod_manager:
|
|
276
|
+ if is_tracim_manager:
|
262
|
277
|
user.groups.append(group_api.get_one(Group.TIM_MANAGER))
|
263
|
|
- if is_pod_admin:
|
|
278
|
+ if is_tracim_admin:
|
264
|
279
|
user.groups.append(group_api.get_one(Group.TIM_ADMIN))
|
265
|
280
|
|
266
|
281
|
api.save(user)
|