소스 검색

Merge pull request #26 from tracim/feature/750_do_notify_in_roles_endpoints

Bastien Sevajol 6 년 전
부모
커밋
1bfc72d21f
No account linked to committer's email

+ 1 - 1
backend/tracim_backend/lib/core/userworkspace.py 파일 보기

@@ -115,7 +115,7 @@ class RoleApi(object):
115 115
         """
116 116
         role.role = role_level
117 117
         if with_notif is not None:
118
-            role.do_notify == with_notif
118
+            role.do_notify = with_notif
119 119
         if save_now:
120 120
             self.save(role)
121 121
 

+ 8 - 0
backend/tracim_backend/models/context_models.py 파일 보기

@@ -263,8 +263,10 @@ class RoleUpdate(object):
263 263
     def __init__(
264 264
         self,
265 265
         role: str,
266
+        do_notify: bool,
266 267
     ):
267 268
         self.role = role
269
+        self.do_notify = do_notify
268 270
 
269 271
 
270 272
 class WorkspaceMemberInvitation(object):
@@ -276,10 +278,12 @@ class WorkspaceMemberInvitation(object):
276 278
         user_id: int,
277 279
         user_email_or_public_name: str,
278 280
         role: str,
281
+        do_notify: str,
279 282
     ):
280 283
         self.role = role
281 284
         self.user_email_or_public_name = user_email_or_public_name
282 285
         self.user_id = user_id
286
+        self.do_notify = do_notify
283 287
 
284 288
 
285 289
 class WorkspaceUpdate(object):
@@ -574,6 +578,10 @@ class UserRoleWorkspaceInContext(object):
574 578
         return self.user.is_active
575 579
 
576 580
     @property
581
+    def do_notify(self) -> bool:
582
+        return self.user_role.do_notify
583
+
584
+    @property
577 585
     def user(self) -> UserInContext:
578 586
         """
579 587
         User who has this role, with context data

+ 16 - 0
backend/tracim_backend/tests/functional/test_workspaces.py 파일 보기

@@ -905,6 +905,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
905 905
         assert user_role['user']['public_name'] == 'Global manager'
906 906
         assert user_role['user']['user_id'] == 1
907 907
         assert user_role['is_active'] is True
908
+        assert user_role['do_notify'] is True
908 909
         # TODO - G.M - 24-05-2018 - [Avatar] Replace
909 910
         # by correct value when avatar feature will be enabled
910 911
         assert user_role['user']['avatar_url'] is None
@@ -979,6 +980,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
979 980
             'user_id': 2,
980 981
             'user_email_or_public_name': None,
981 982
             'role': 'content-manager',
983
+            'do_notify': False,
982 984
         }
983 985
         res = self.testapp.post_json(
984 986
             '/api/v2/workspaces/1/members',
@@ -991,6 +993,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
991 993
         assert user_role_found['workspace_id'] == 1
992 994
         assert user_role_found['newly_created'] is False
993 995
         assert user_role_found['email_sent'] is False
996
+        assert user_role_found['do_notify'] is False
994 997
 
995 998
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
996 999
         assert len(res) == 2
@@ -1020,6 +1023,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1020 1023
             'user_id': None,
1021 1024
             'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
1022 1025
             'role': 'content-manager',
1026
+            'do_notify': 'True',
1023 1027
         }
1024 1028
         res = self.testapp.post_json(
1025 1029
             '/api/v2/workspaces/1/members',
@@ -1032,6 +1036,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1032 1036
         assert user_role_found['workspace_id'] == 1
1033 1037
         assert user_role_found['newly_created'] is False
1034 1038
         assert user_role_found['email_sent'] is False
1039
+        assert user_role_found['do_notify'] is True
1035 1040
 
1036 1041
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
1037 1042
         assert len(res) == 2
@@ -1061,6 +1066,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1061 1066
             'user_id': None,
1062 1067
             'user_email_or_public_name': 'Lawrence L.',
1063 1068
             'role': 'content-manager',
1069
+            'do_notify': True,
1064 1070
         }
1065 1071
         res = self.testapp.post_json(
1066 1072
             '/api/v2/workspaces/1/members',
@@ -1073,6 +1079,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1073 1079
         assert user_role_found['workspace_id'] == 1
1074 1080
         assert user_role_found['newly_created'] is False
1075 1081
         assert user_role_found['email_sent'] is False
1082
+        assert user_role_found['do_notify'] is True
1076 1083
 
1077 1084
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
1078 1085
         assert len(res) == 2
@@ -1102,6 +1109,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1102 1109
             'user_id': None,
1103 1110
             'user_email_or_public_name': None,
1104 1111
             'role': 'content-manager',
1112
+            'do_notify': True,
1105 1113
         }
1106 1114
         res = self.testapp.post_json(
1107 1115
             '/api/v2/workspaces/1/members',
@@ -1126,6 +1134,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1126 1134
             'user_id': 47,
1127 1135
             'user_email_or_public_name': None,
1128 1136
             'role': 'content-manager',
1137
+            'do_notify': True,
1129 1138
         }
1130 1139
         res = self.testapp.post_json(
1131 1140
             '/api/v2/workspaces/1/members',
@@ -1150,6 +1159,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1150 1159
             'user_id': None,
1151 1160
             'user_email_or_public_name': 'nothing@nothing.nothing',
1152 1161
             'role': 'content-manager',
1162
+            'do_notify': True,
1153 1163
         }
1154 1164
         res = self.testapp.post_json(
1155 1165
             '/api/v2/workspaces/1/members',
@@ -1163,6 +1173,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1163 1173
         assert user_role_found['workspace_id'] == 1
1164 1174
         assert user_role_found['newly_created'] is True
1165 1175
         assert user_role_found['email_sent'] is False
1176
+        assert user_role_found['do_notify'] is True
1166 1177
 
1167 1178
         res = self.testapp.get('/api/v2/workspaces/1/members',
1168 1179
                                status=200).json_body  # nopep8
@@ -1197,6 +1208,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1197 1208
         # update workspace role
1198 1209
         params = {
1199 1210
             'role': 'content-manager',
1211
+            'do_notify': False,
1200 1212
         }
1201 1213
         res = self.testapp.put_json(
1202 1214
             '/api/v2/workspaces/1/members/1',
@@ -1212,6 +1224,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1212 1224
         assert len(res) == 1
1213 1225
         user_role = res[0]
1214 1226
         assert user_role['role'] == 'content-manager'
1227
+        assert user_role['do_notify'] is False
1215 1228
         assert user_role['user_id'] == 1
1216 1229
         assert user_role['workspace_id'] == 1
1217 1230
 
@@ -1354,6 +1367,7 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
1354 1367
             'user_id': None,
1355 1368
             'user_email_or_public_name': 'bob@bob.bob',
1356 1369
             'role': 'content-manager',
1370
+            'do_notify': True,
1357 1371
         }
1358 1372
         res = self.testapp.post_json(
1359 1373
             '/api/v2/workspaces/1/members',
@@ -1367,6 +1381,7 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
1367 1381
         assert user_role_found['workspace_id'] == 1
1368 1382
         assert user_role_found['newly_created'] is True
1369 1383
         assert user_role_found['email_sent'] is True
1384
+        assert user_role_found['do_notify'] is True
1370 1385
 
1371 1386
         # check mail received
1372 1387
         response = requests.get('http://127.0.0.1:8025/api/v1/messages')
@@ -1403,6 +1418,7 @@ class TestUserInvitationWithMailActivatedASync(FunctionalTest):
1403 1418
             'user_id': None,
1404 1419
             'user_email_or_public_name': 'bob@bob.bob',
1405 1420
             'role': 'content-manager',
1421
+            'do_notify': True,
1406 1422
         }
1407 1423
         res = self.testapp.post_json(
1408 1424
             '/api/v2/workspaces/1/members',

+ 10 - 0
backend/tracim_backend/views/core_api/schemas.py 파일 보기

@@ -439,6 +439,12 @@ class RoleUpdateSchema(marshmallow.Schema):
439 439
         example='contributor',
440 440
         validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
441 441
     )
442
+    do_notify = marshmallow.fields.Bool(
443
+        description='has user enabled notification for this workspace',
444
+        example=True,
445
+        default=None,
446
+        allow_none=True,
447
+    )
442 448
 
443 449
     @post_load
444 450
     def make_role(self, data):
@@ -577,6 +583,10 @@ class WorkspaceMemberSchema(marshmallow.Schema):
577 583
         WorkspaceDigestSchema(exclude=('sidebar_entries',))
578 584
     )
579 585
     is_active = marshmallow.fields.Bool()
586
+    do_notify = marshmallow.fields.Bool(
587
+        description='has user enabled notification for this workspace',
588
+        example=True,
589
+    )
580 590
 
581 591
     class Meta:
582 592
         description = 'Workspace Member information'

+ 3 - 2
backend/tracim_backend/views/core_api/workspace_controller.py 파일 보기

@@ -221,7 +221,8 @@ class WorkspaceController(Controller):
221 221
         workspace_role = WorkspaceRoles.get_role_from_slug(hapic_data.body.role)
222 222
         role = rapi.update_role(
223 223
             role,
224
-            role_level=workspace_role.level
224
+            role_level=workspace_role.level,
225
+            with_notif=hapic_data.body.do_notify
225 226
         )
226 227
         return rapi.get_user_role_workspace_with_context(role)
227 228
 
@@ -302,7 +303,7 @@ class WorkspaceController(Controller):
302 303
             user=user,
303 304
             workspace=request.current_workspace,
304 305
             role_level=WorkspaceRoles.get_role_from_slug(hapic_data.body.role).level,  # nopep8
305
-            with_notif=False,
306
+            with_notif=hapic_data.body.do_notify or False,  # nopep8, default value as false
306 307
             flush=True,
307 308
         )
308 309
         return rapi.get_user_role_workspace_with_context(