Browse Source

Merge pull request #346 from tracim/fix/302/role_api_notification_parameter

Damien Accorsi 6 years ago
parent
commit
5e03a99a28

+ 15 - 4
tracim/tracim/controllers/admin/workspace.py View File

@@ -82,17 +82,28 @@ class RoleInWorkspaceRestController(TIMRestController, BaseController):
82 82
     def undelete(self, user_id, old_role):
83 83
         user_id = int(user_id)
84 84
         role_id = int(old_role)
85
-        self._add_user_with_role(user_id, role_id, None, _('User {} restored in workspace {} as {}'))
85
+        self._add_user_with_role(user_id, role_id, False, _('User {} restored in workspace {} as {}'))
86 86
         tg.redirect(self.parent_controller.url(tg.tmpl_context.workspace_id))
87 87
 
88 88
     @tg.expose()
89
-    def post(self, user_id, role_id, with_notif=False):
89
+    def post(self, user_id: str, role_id: str, with_notif: str='off'):
90 90
         user_id = int(user_id)
91 91
         role_id = int(role_id)
92
-        self._add_user_with_role(user_id, role_id, with_notif, _('User {} added to workspace {} as {}'))
92
+        self._add_user_with_role(
93
+            user_id,
94
+            role_id,
95
+            on_off_to_boolean(with_notif),
96
+            _('User {} added to workspace {} as {}')
97
+        )
93 98
         tg.redirect(self.parent_controller.url(tg.tmpl_context.workspace_id))
94 99
 
95
-    def _add_user_with_role(self, user_id: int, role_id: int, with_notif: bool, flash_msg_template)-> UserRoleInWorkspace:
100
+    def _add_user_with_role(
101
+            self,
102
+            user_id: int,
103
+            role_id: int,
104
+            with_notif: bool,
105
+            flash_msg_template: str
106
+    )-> UserRoleInWorkspace:
96 107
         user_api = UserApi(tg.tmpl_context.current_user)
97 108
         user = user_api.get_one(user_id)
98 109
 

+ 1 - 5
tracim/tracim/lib/userworkspace.py View File

@@ -86,16 +86,12 @@ class RoleApi(object):
86 86
     def get_one(self, user_id, workspace_id):
87 87
         return self._get_one_rsc(user_id, workspace_id).one()
88 88
 
89
-    # TODO - A.P - fix with_notif: bool vs with_notif: str
90
-    # https://github.com/tracim/tracim/issues/302
91 89
     def create_one(self, user: User, workspace: Workspace, role_level: int, with_notif: bool, flush: bool=True) -> UserRoleInWorkspace:
92 90
         role = self.create_role()
93 91
         role.user_id = user.user_id
94 92
         role.workspace = workspace
95 93
         role.role = role_level
96
-        if with_notif is not None:
97
-            from tracim.lib.helpers import on_off_to_boolean
98
-            role.do_notify = on_off_to_boolean(with_notif)
94
+        role.do_notify = with_notif
99 95
         if flush:
100 96
             DBSession.flush()
101 97
         return role

+ 6 - 7
tracim/tracim/tests/library/test_workspace.py View File

@@ -39,7 +39,7 @@ class TestThread(BaseTestThread, TestStandard):
39 39
         u = uapi.create_user(email='u.u@u.u', save_now=True)
40 40
         eq_([], wapi.get_notifiable_roles(workspace=w))
41 41
         rapi = RoleApi(u)
42
-        r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif='on')
42
+        r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True)
43 43
         eq_([r, ], wapi.get_notifiable_roles(workspace=w))
44 44
         u.is_active = False
45 45
         eq_([], wapi.get_notifiable_roles(workspace=w))
@@ -62,14 +62,13 @@ class TestThread(BaseTestThread, TestStandard):
62 62
         u = uapi.create_user('u.s@e.r', [gapi.get_one(Group.TIM_USER)], True)
63 63
         wapi = WorkspaceApi(current_user=u)
64 64
         rapi = RoleApi(current_user=u)
65
-        off = 'off'
66
-        rapi.create_one(u, w4, UserRoleInWorkspace.READER, off)
67
-        rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, off)
68
-        rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, off)
69
-        rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
65
+        rapi.create_one(u, w4, UserRoleInWorkspace.READER, False)
66
+        rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False)
67
+        rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False)
68
+        rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
70 69
         eq_([], wapi.get_all_manageable())
71 70
         # Checks a manager gets only its own workspaces.
72 71
         u.groups.append(gapi.get_one(Group.TIM_MANAGER))
73 72
         rapi.delete_one(u.user_id, w2.workspace_id)
74
-        rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
73
+        rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
75 74
         eq_([w1, w2], wapi.get_all_manageable())