Bladeren bron

fix returned schema for adding member_role

Guénaël Muller 6 jaren geleden
bovenliggende
commit
063073eccc

+ 5 - 1
tracim/lib/core/userworkspace.py Bestand weergeven

58
 
58
 
59
     def get_user_role_workspace_with_context(
59
     def get_user_role_workspace_with_context(
60
             self,
60
             self,
61
-            user_role: UserRoleInWorkspace
61
+            user_role: UserRoleInWorkspace,
62
+            newly_created:bool = None,
63
+            email_sent: bool = None,
62
     ) -> UserRoleWorkspaceInContext:
64
     ) -> UserRoleWorkspaceInContext:
63
         """
65
         """
64
         Return WorkspaceInContext object from Workspace
66
         Return WorkspaceInContext object from Workspace
68
             user_role=user_role,
70
             user_role=user_role,
69
             dbsession=self._session,
71
             dbsession=self._session,
70
             config=self._config,
72
             config=self._config,
73
+            newly_created=newly_created,
74
+            email_sent=email_sent,
71
         )
75
         )
72
         return workspace
76
         return workspace
73
 
77
 

+ 6 - 0
tracim/models/context_models.py Bestand weergeven

310
             user_role: UserRoleInWorkspace,
310
             user_role: UserRoleInWorkspace,
311
             dbsession: Session,
311
             dbsession: Session,
312
             config: CFG,
312
             config: CFG,
313
+            # Extended params
314
+            newly_created:bool = None,
315
+            email_sent: bool = None
313
     )-> None:
316
     )-> None:
314
         self.user_role = user_role
317
         self.user_role = user_role
315
         self.dbsession = dbsession
318
         self.dbsession = dbsession
316
         self.config = config
319
         self.config = config
320
+        # Extended params
321
+        self.newly_created = newly_created
322
+        self.email_sent = email_sent
317
 
323
 
318
     @property
324
     @property
319
     def user_id(self) -> int:
325
     def user_id(self) -> int:

+ 34 - 3
tracim/tests/functional/test_workspaces.py Bestand weergeven

376
         assert user_role_found['role'] == 'content-manager'
376
         assert user_role_found['role'] == 'content-manager'
377
         assert user_role_found['user_id'] == 2
377
         assert user_role_found['user_id'] == 2
378
         assert user_role_found['workspace_id'] == 1
378
         assert user_role_found['workspace_id'] == 1
379
+        assert user_role_found['newly_created'] is False
380
+        assert user_role_found['email_sent'] is False
379
 
381
 
380
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
382
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
381
         assert len(res) == 2
383
         assert len(res) == 2
384
         assert user_role['user_id'] == 1
386
         assert user_role['user_id'] == 1
385
         assert user_role['workspace_id'] == 1
387
         assert user_role['workspace_id'] == 1
386
         user_role = res[1]
388
         user_role = res[1]
387
-        assert user_role_found == user_role
389
+        assert user_role_found['role'] == user_role['role']
390
+        assert user_role_found['user_id'] == user_role['user_id']
391
+        assert user_role_found['workspace_id'] == user_role['workspace_id']
388
 
392
 
389
     def test_api__create_workspace_member_role__ok_200__user_email(self):
393
     def test_api__create_workspace_member_role__ok_200__user_email(self):
390
         """
394
         """
413
         assert user_role_found['role'] == 'content-manager'
417
         assert user_role_found['role'] == 'content-manager'
414
         assert user_role_found['user_id'] == 2
418
         assert user_role_found['user_id'] == 2
415
         assert user_role_found['workspace_id'] == 1
419
         assert user_role_found['workspace_id'] == 1
420
+        assert user_role_found['newly_created'] is False
421
+        assert user_role_found['email_sent'] is False
416
 
422
 
417
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
423
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
418
         assert len(res) == 2
424
         assert len(res) == 2
421
         assert user_role['user_id'] == 1
427
         assert user_role['user_id'] == 1
422
         assert user_role['workspace_id'] == 1
428
         assert user_role['workspace_id'] == 1
423
         user_role = res[1]
429
         user_role = res[1]
424
-        assert user_role_found == user_role
430
+        assert user_role_found['role'] == user_role['role']
431
+        assert user_role_found['user_id'] == user_role['user_id']
432
+        assert user_role_found['workspace_id'] == user_role['workspace_id']
425
 
433
 
426
     def test_api__create_workspace_member_role__ok_200__user_public_name(self):
434
     def test_api__create_workspace_member_role__ok_200__user_public_name(self):
427
         """
435
         """
450
         assert user_role_found['role'] == 'content-manager'
458
         assert user_role_found['role'] == 'content-manager'
451
         assert user_role_found['user_id'] == 2
459
         assert user_role_found['user_id'] == 2
452
         assert user_role_found['workspace_id'] == 1
460
         assert user_role_found['workspace_id'] == 1
461
+        assert user_role_found['newly_created'] is False
462
+        assert user_role_found['email_sent'] is False
453
 
463
 
454
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
464
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
455
         assert len(res) == 2
465
         assert len(res) == 2
458
         assert user_role['user_id'] == 1
468
         assert user_role['user_id'] == 1
459
         assert user_role['workspace_id'] == 1
469
         assert user_role['workspace_id'] == 1
460
         user_role = res[1]
470
         user_role = res[1]
461
-        assert user_role_found == user_role
471
+        assert user_role_found['role'] == user_role['role']
472
+        assert user_role_found['user_id'] == user_role['user_id']
473
+        assert user_role_found['workspace_id'] == user_role['workspace_id']
462
 
474
 
463
     def test_api__create_workspace_member_role__err_400__nothing(self):
475
     def test_api__create_workspace_member_role__err_400__nothing(self):
464
         """
476
         """
531
             status=200,
543
             status=200,
532
             params=params,
544
             params=params,
533
         )
545
         )
546
+        user_role_found = res.json_body
547
+        assert user_role_found['role'] == 'content-manager'
548
+        assert user_role_found['user_id']
549
+        user_id = user_role_found['user_id']
550
+        assert user_role_found['workspace_id'] == 1
551
+        assert user_role_found['newly_created'] is True
552
+        assert user_role_found['email_sent'] is False
553
+
554
+        res = self.testapp.get('/api/v2/workspaces/1/members',
555
+                               status=200).json_body  # nopep8
556
+        assert len(res) == 2
557
+        user_role = res[0]
558
+        assert user_role['role'] == 'workspace-manager'
559
+        assert user_role['user_id'] == 1
560
+        assert user_role['workspace_id'] == 1
561
+        user_role = res[1]
562
+        assert user_role_found['role'] == user_role['role']
563
+        assert user_role_found['user_id'] == user_role['user_id']
564
+        assert user_role_found['workspace_id'] == user_role['workspace_id']
534
 
565
 
535
     def test_api__update_workspace_member_role__ok_200__nominal_case(self):
566
     def test_api__update_workspace_member_role__ok_200__nominal_case(self):
536
         """
567
         """

+ 14 - 0
tracim/views/core_api/schemas.py Bestand weergeven

301
         description = 'Workspace Member information'
301
         description = 'Workspace Member information'
302
 
302
 
303
 
303
 
304
+class WorkspaceMemberCreationSchema(WorkspaceMemberSchema):
305
+    newly_created = marshmallow.fields.Bool(
306
+        exemple=False,
307
+        description='Is the user completely new '
308
+                    '(and account was just created) or not ?',
309
+    )
310
+    email_sent = marshmallow.fields.Bool(
311
+        exemple=False,
312
+        description='Has an email been sent to user to inform him about '
313
+                    'this new workspace registration and eventually his account'
314
+                    'creation'
315
+    )
316
+
317
+
304
 class ApplicationConfigSchema(marshmallow.Schema):
318
 class ApplicationConfigSchema(marshmallow.Schema):
305
     pass
319
     pass
306
     #  TODO - G.M - 24-05-2018 - Set this
320
     #  TODO - G.M - 24-05-2018 - Set this

+ 10 - 2
tracim/views/core_api/workspace_controller.py Bestand weergeven

30
 from tracim.exceptions import WorkspacesDoNotMatch
30
 from tracim.exceptions import WorkspacesDoNotMatch
31
 from tracim.views.controllers import Controller
31
 from tracim.views.controllers import Controller
32
 from tracim.views.core_api.schemas import FilterContentQuerySchema
32
 from tracim.views.core_api.schemas import FilterContentQuerySchema
33
+from tracim.views.core_api.schemas import WorkspaceMemberCreationSchema
33
 from tracim.views.core_api.schemas import WorkspaceMemberInviteSchema
34
 from tracim.views.core_api.schemas import WorkspaceMemberInviteSchema
34
 from tracim.views.core_api.schemas import RoleUpdateSchema
35
 from tracim.views.core_api.schemas import RoleUpdateSchema
35
 from tracim.views.core_api.schemas import WorkspaceCreationSchema
36
 from tracim.views.core_api.schemas import WorkspaceCreationSchema
176
     @require_workspace_role(UserRoleInWorkspace.WORKSPACE_MANAGER)
177
     @require_workspace_role(UserRoleInWorkspace.WORKSPACE_MANAGER)
177
     @hapic.input_path(WorkspaceIdPathSchema())
178
     @hapic.input_path(WorkspaceIdPathSchema())
178
     @hapic.input_body(WorkspaceMemberInviteSchema())
179
     @hapic.input_body(WorkspaceMemberInviteSchema())
179
-    @hapic.output_body(WorkspaceMemberSchema())
180
+    @hapic.output_body(WorkspaceMemberCreationSchema())
180
     def create_workspaces_members_role(
181
     def create_workspaces_members_role(
181
             self,
182
             self,
182
             context,
183
             context,
186
         """
187
         """
187
         Add Members to this workspace
188
         Add Members to this workspace
188
         """
189
         """
190
+        newly_created = False
191
+        email_sent = False
189
         app_config = request.registry.settings['CFG']
192
         app_config = request.registry.settings['CFG']
190
         rapi = RoleApi(
193
         rapi = RoleApi(
191
             current_user=request.current_user,
194
             current_user=request.current_user,
211
                     hapic_data.body.user_email_or_public_name,
214
                     hapic_data.body.user_email_or_public_name,
212
                     do_notify=False
215
                     do_notify=False
213
                 )  # nopep8
216
                 )  # nopep8
217
+                newly_created = True
214
             except EmailValidationFailed:
218
             except EmailValidationFailed:
215
                 raise UserCreationFailed('no valid mail given')
219
                 raise UserCreationFailed('no valid mail given')
216
         role = rapi.create_one(
220
         role = rapi.create_one(
220
             with_notif=False,
224
             with_notif=False,
221
             flush=True,
225
             flush=True,
222
         )
226
         )
223
-        return rapi.get_user_role_workspace_with_context(role)
227
+        return rapi.get_user_role_workspace_with_context(
228
+            role,
229
+            newly_created=newly_created,
230
+            email_sent=email_sent,
231
+        )
224
 
232
 
225
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
233
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
226
     @require_workspace_role(UserRoleInWorkspace.READER)
234
     @require_workspace_role(UserRoleInWorkspace.READER)