Browse Source

add do_notify param to endpoints for roles

Guénaël Muller 6 years ago
parent
commit
42ce2dd685

+ 1 - 1
backend/tracim_backend/lib/core/userworkspace.py View File

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

+ 8 - 0
backend/tracim_backend/models/context_models.py View File

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

+ 16 - 0
backend/tracim_backend/tests/functional/test_workspaces.py View File

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

+ 10 - 0
backend/tracim_backend/views/core_api/schemas.py View File

437
         example='contributor',
437
         example='contributor',
438
         validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
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
     @post_load
447
     @post_load
442
     def make_role(self, data):
448
     def make_role(self, data):
575
         WorkspaceDigestSchema(exclude=('sidebar_entries',))
581
         WorkspaceDigestSchema(exclude=('sidebar_entries',))
576
     )
582
     )
577
     is_active = marshmallow.fields.Bool()
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
     class Meta:
589
     class Meta:
580
         description = 'Workspace Member information'
590
         description = 'Workspace Member information'

+ 3 - 2
backend/tracim_backend/views/core_api/workspace_controller.py View File

221
         workspace_role = WorkspaceRoles.get_role_from_slug(hapic_data.body.role)
221
         workspace_role = WorkspaceRoles.get_role_from_slug(hapic_data.body.role)
222
         role = rapi.update_role(
222
         role = rapi.update_role(
223
             role,
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
         return rapi.get_user_role_workspace_with_context(role)
227
         return rapi.get_user_role_workspace_with_context(role)
227
 
228
 
302
             user=user,
303
             user=user,
303
             workspace=request.current_workspace,
304
             workspace=request.current_workspace,
304
             role_level=WorkspaceRoles.get_role_from_slug(hapic_data.body.role).level,  # nopep8
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
             flush=True,
307
             flush=True,
307
         )
308
         )
308
         return rapi.get_user_role_workspace_with_context(
309
         return rapi.get_user_role_workspace_with_context(