|
@@ -18,6 +18,8 @@ from formencode import Schema
|
18
|
18
|
from formencode.validators import FieldsMatch
|
19
|
19
|
|
20
|
20
|
from tracim.controllers import TIMRestController
|
|
21
|
+from tracim.controllers.user import UserWorkspaceRestController
|
|
22
|
+
|
21
|
23
|
from tracim.lib import CST
|
22
|
24
|
from tracim.lib import helpers as h
|
23
|
25
|
from tracim.lib.base import logger
|
|
@@ -212,6 +214,52 @@ class UserPasswordAdminRestController(TIMRestController):
|
212
|
214
|
tg.redirect(next_url)
|
213
|
215
|
|
214
|
216
|
|
|
217
|
+class UserWorkspaceRestController(TIMRestController):
|
|
218
|
+
|
|
219
|
+ def _before(self, *args, **kw):
|
|
220
|
+ """
|
|
221
|
+ Instantiate the current workspace in tg.tmpl_context
|
|
222
|
+ :param args:
|
|
223
|
+ :param kw:
|
|
224
|
+ :return:
|
|
225
|
+ """
|
|
226
|
+ super(self.__class__, self)._before(args, kw)
|
|
227
|
+
|
|
228
|
+ api = UserApi(tg.tmpl_context.current_user)
|
|
229
|
+ user_id = tg.request.controller_state.routing_args.get('user_id')
|
|
230
|
+ user = api.get_one(user_id)
|
|
231
|
+ tg.tmpl_context.user_id = user_id
|
|
232
|
+ tg.tmpl_context.user = user
|
|
233
|
+
|
|
234
|
+ @tg.expose()
|
|
235
|
+ def enable_notifications(self, workspace_id, next_url=None):
|
|
236
|
+ workspace_id = int(workspace_id)
|
|
237
|
+ api = WorkspaceApi(tg.tmpl_context.current_user)
|
|
238
|
+
|
|
239
|
+ workspace = api.get_one(workspace_id)
|
|
240
|
+ api.enable_notifications(tg.tmpl_context.user, workspace)
|
|
241
|
+ tg.flash(_('User {}: notification enabled for workspace {}').format(
|
|
242
|
+ tg.tmpl_context.user.get_display_name(), workspace.label))
|
|
243
|
+
|
|
244
|
+ if next_url:
|
|
245
|
+ tg.redirect(tg.url(next_url))
|
|
246
|
+ tg.redirect(self.parent_controller.url(None, 'me'))
|
|
247
|
+
|
|
248
|
+ @tg.expose()
|
|
249
|
+ def disable_notifications(self, workspace_id, next_url=None):
|
|
250
|
+ workspace_id = int(workspace_id)
|
|
251
|
+ api = WorkspaceApi(tg.tmpl_context.current_user)
|
|
252
|
+
|
|
253
|
+ workspace = api.get_one(workspace_id)
|
|
254
|
+ api.disable_notifications(tg.tmpl_context.user, workspace)
|
|
255
|
+ tg.flash(_('User {}: notification disabled for workspace {}').format(
|
|
256
|
+ tg.tmpl_context.user.get_display_name(), workspace.label))
|
|
257
|
+
|
|
258
|
+ if next_url:
|
|
259
|
+ tg.redirect(tg.url(next_url))
|
|
260
|
+ tg.redirect(self.parent_controller.url(None, 'me'))
|
|
261
|
+
|
|
262
|
+
|
215
|
263
|
class UserRestController(TIMRestController):
|
216
|
264
|
"""
|
217
|
265
|
CRUD Controller allowing to manage Users
|
|
@@ -220,6 +268,7 @@ class UserRestController(TIMRestController):
|
220
|
268
|
|
221
|
269
|
password = UserPasswordAdminRestController()
|
222
|
270
|
profile = UserProfileAdminRestController()
|
|
271
|
+ workspaces = UserWorkspaceRestController()
|
223
|
272
|
|
224
|
273
|
@classmethod
|
225
|
274
|
def current_item_id_key_in_context(cls):
|
|
@@ -289,10 +338,14 @@ class UserRestController(TIMRestController):
|
289
|
338
|
|
290
|
339
|
user = api.get_one(user_id) # FIXME
|
291
|
340
|
|
292
|
|
- dictified_user = Context(CTX.USER).toDict(user, 'user')
|
|
341
|
+ role_api = RoleApi(tg.tmpl_context.current_user)
|
|
342
|
+ role_list = role_api.get_roles_for_select_field()
|
|
343
|
+
|
|
344
|
+ dictified_user = Context(CTX.ADMIN_USER).toDict(user, 'user')
|
293
|
345
|
current_user_content = Context(CTX.CURRENT_USER).toDict(tmpl_context.current_user)
|
294
|
|
- fake_api_content = DictLikeClass(current_user=current_user_content)
|
295
|
|
- fake_api = Context(CTX.WORKSPACE).toDict(fake_api_content)
|
|
346
|
+ fake_api_content = DictLikeClass(current_user=current_user_content,
|
|
347
|
+ role_types=role_list)
|
|
348
|
+ fake_api = Context(CTX.ADMIN_USER).toDict(fake_api_content)
|
296
|
349
|
|
297
|
350
|
return DictLikeClass(result = dictified_user, fake_api=fake_api)
|
298
|
351
|
|