Преглед на файлове

add do_notify param to endpoints for roles

Guénaël Muller преди 6 години
родител
ревизия
42ce2dd685

+ 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 Целия файл

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

+ 16 - 0
backend/tracim_backend/tests/functional/test_workspaces.py Целия файл

@@ -901,6 +901,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
901 901
         assert user_role['user']['public_name'] == 'Global manager'
902 902
         assert user_role['user']['user_id'] == 1
903 903
         assert user_role['is_active'] is True
904
+        assert user_role['do_notify'] is True
904 905
         # TODO - G.M - 24-05-2018 - [Avatar] Replace
905 906
         # by correct value when avatar feature will be enabled
906 907
         assert user_role['user']['avatar_url'] is None
@@ -975,6 +976,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
975 976
             'user_id': 2,
976 977
             'user_email_or_public_name': None,
977 978
             'role': 'content-manager',
979
+            'do_notify': False,
978 980
         }
979 981
         res = self.testapp.post_json(
980 982
             '/api/v2/workspaces/1/members',
@@ -987,6 +989,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
987 989
         assert user_role_found['workspace_id'] == 1
988 990
         assert user_role_found['newly_created'] is False
989 991
         assert user_role_found['email_sent'] is False
992
+        assert user_role_found['do_notify'] is False
990 993
 
991 994
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
992 995
         assert len(res) == 2
@@ -1016,6 +1019,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1016 1019
             'user_id': None,
1017 1020
             'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
1018 1021
             'role': 'content-manager',
1022
+            'do_notify': 'True',
1019 1023
         }
1020 1024
         res = self.testapp.post_json(
1021 1025
             '/api/v2/workspaces/1/members',
@@ -1028,6 +1032,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1028 1032
         assert user_role_found['workspace_id'] == 1
1029 1033
         assert user_role_found['newly_created'] is False
1030 1034
         assert user_role_found['email_sent'] is False
1035
+        assert user_role_found['do_notify'] is True
1031 1036
 
1032 1037
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
1033 1038
         assert len(res) == 2
@@ -1057,6 +1062,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1057 1062
             'user_id': None,
1058 1063
             'user_email_or_public_name': 'Lawrence L.',
1059 1064
             'role': 'content-manager',
1065
+            'do_notify': True,
1060 1066
         }
1061 1067
         res = self.testapp.post_json(
1062 1068
             '/api/v2/workspaces/1/members',
@@ -1069,6 +1075,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1069 1075
         assert user_role_found['workspace_id'] == 1
1070 1076
         assert user_role_found['newly_created'] is False
1071 1077
         assert user_role_found['email_sent'] is False
1078
+        assert user_role_found['do_notify'] is True
1072 1079
 
1073 1080
         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8
1074 1081
         assert len(res) == 2
@@ -1098,6 +1105,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1098 1105
             'user_id': None,
1099 1106
             'user_email_or_public_name': None,
1100 1107
             'role': 'content-manager',
1108
+            'do_notify': True,
1101 1109
         }
1102 1110
         res = self.testapp.post_json(
1103 1111
             '/api/v2/workspaces/1/members',
@@ -1122,6 +1130,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1122 1130
             'user_id': 47,
1123 1131
             'user_email_or_public_name': None,
1124 1132
             'role': 'content-manager',
1133
+            'do_notify': True,
1125 1134
         }
1126 1135
         res = self.testapp.post_json(
1127 1136
             '/api/v2/workspaces/1/members',
@@ -1146,6 +1155,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1146 1155
             'user_id': None,
1147 1156
             'user_email_or_public_name': 'nothing@nothing.nothing',
1148 1157
             'role': 'content-manager',
1158
+            'do_notify': True,
1149 1159
         }
1150 1160
         res = self.testapp.post_json(
1151 1161
             '/api/v2/workspaces/1/members',
@@ -1159,6 +1169,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1159 1169
         assert user_role_found['workspace_id'] == 1
1160 1170
         assert user_role_found['newly_created'] is True
1161 1171
         assert user_role_found['email_sent'] is False
1172
+        assert user_role_found['do_notify'] is True
1162 1173
 
1163 1174
         res = self.testapp.get('/api/v2/workspaces/1/members',
1164 1175
                                status=200).json_body  # nopep8
@@ -1193,6 +1204,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1193 1204
         # update workspace role
1194 1205
         params = {
1195 1206
             'role': 'content-manager',
1207
+            'do_notify': False,
1196 1208
         }
1197 1209
         res = self.testapp.put_json(
1198 1210
             '/api/v2/workspaces/1/members/1',
@@ -1208,6 +1220,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
1208 1220
         assert len(res) == 1
1209 1221
         user_role = res[0]
1210 1222
         assert user_role['role'] == 'content-manager'
1223
+        assert user_role['do_notify'] is False
1211 1224
         assert user_role['user_id'] == 1
1212 1225
         assert user_role['workspace_id'] == 1
1213 1226
 
@@ -1350,6 +1363,7 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
1350 1363
             'user_id': None,
1351 1364
             'user_email_or_public_name': 'bob@bob.bob',
1352 1365
             'role': 'content-manager',
1366
+            'do_notify': True,
1353 1367
         }
1354 1368
         res = self.testapp.post_json(
1355 1369
             '/api/v2/workspaces/1/members',
@@ -1363,6 +1377,7 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
1363 1377
         assert user_role_found['workspace_id'] == 1
1364 1378
         assert user_role_found['newly_created'] is True
1365 1379
         assert user_role_found['email_sent'] is True
1380
+        assert user_role_found['do_notify'] is True
1366 1381
 
1367 1382
         # check mail received
1368 1383
         response = requests.get('http://127.0.0.1:8025/api/v1/messages')
@@ -1399,6 +1414,7 @@ class TestUserInvitationWithMailActivatedASync(FunctionalTest):
1399 1414
             'user_id': None,
1400 1415
             'user_email_or_public_name': 'bob@bob.bob',
1401 1416
             'role': 'content-manager',
1417
+            'do_notify': True,
1402 1418
         }
1403 1419
         res = self.testapp.post_json(
1404 1420
             '/api/v2/workspaces/1/members',

+ 10 - 0
backend/tracim_backend/views/core_api/schemas.py Целия файл

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