Browse Source

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

Bastien Sevajol 6 years ago
parent
commit
1bfc72d21f
No account linked to committer's email

+ 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

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

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

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

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

439
         example='contributor',
439
         example='contributor',
440
         validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
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
     @post_load
449
     @post_load
444
     def make_role(self, data):
450
     def make_role(self, data):
577
         WorkspaceDigestSchema(exclude=('sidebar_entries',))
583
         WorkspaceDigestSchema(exclude=('sidebar_entries',))
578
     )
584
     )
579
     is_active = marshmallow.fields.Bool()
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
     class Meta:
591
     class Meta:
582
         description = 'Workspace Member information'
592
         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(