Browse Source

fix returned schema for adding member_role

Guénaël Muller 6 years ago
parent
commit
063073eccc

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

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

+ 6 - 0
tracim/models/context_models.py View File

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

+ 34 - 3
tracim/tests/functional/test_workspaces.py View File

@@ -376,6 +376,8 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
376 376
         assert user_role_found['role'] == 'content-manager'
377 377
         assert user_role_found['user_id'] == 2
378 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 382
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
381 383
         assert len(res) == 2
@@ -384,7 +386,9 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
384 386
         assert user_role['user_id'] == 1
385 387
         assert user_role['workspace_id'] == 1
386 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 393
     def test_api__create_workspace_member_role__ok_200__user_email(self):
390 394
         """
@@ -413,6 +417,8 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
413 417
         assert user_role_found['role'] == 'content-manager'
414 418
         assert user_role_found['user_id'] == 2
415 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 423
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
418 424
         assert len(res) == 2
@@ -421,7 +427,9 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
421 427
         assert user_role['user_id'] == 1
422 428
         assert user_role['workspace_id'] == 1
423 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 434
     def test_api__create_workspace_member_role__ok_200__user_public_name(self):
427 435
         """
@@ -450,6 +458,8 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
450 458
         assert user_role_found['role'] == 'content-manager'
451 459
         assert user_role_found['user_id'] == 2
452 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 464
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
455 465
         assert len(res) == 2
@@ -458,7 +468,9 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
458 468
         assert user_role['user_id'] == 1
459 469
         assert user_role['workspace_id'] == 1
460 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 475
     def test_api__create_workspace_member_role__err_400__nothing(self):
464 476
         """
@@ -531,6 +543,25 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
531 543
             status=200,
532 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 566
     def test_api__update_workspace_member_role__ok_200__nominal_case(self):
536 567
         """

+ 14 - 0
tracim/views/core_api/schemas.py View File

@@ -301,6 +301,20 @@ class WorkspaceMemberSchema(marshmallow.Schema):
301 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 318
 class ApplicationConfigSchema(marshmallow.Schema):
305 319
     pass
306 320
     #  TODO - G.M - 24-05-2018 - Set this

+ 10 - 2
tracim/views/core_api/workspace_controller.py View File

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