|
@@ -28,6 +28,42 @@ from tracim.model.serializers import DictLikeClass
|
28
|
28
|
class RoleApi(object):
|
29
|
29
|
|
30
|
30
|
ALL_ROLE_VALUES = UserRoleInWorkspace.get_all_role_values()
|
|
31
|
+ # Dict containing readable members roles for given role
|
|
32
|
+ members_read_rights = {
|
|
33
|
+ UserRoleInWorkspace.NOT_APPLICABLE: [],
|
|
34
|
+ UserRoleInWorkspace.READER: [
|
|
35
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
36
|
+ ],
|
|
37
|
+ UserRoleInWorkspace.CONTRIBUTOR: [
|
|
38
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
39
|
+ UserRoleInWorkspace.CONTENT_MANAGER,
|
|
40
|
+ UserRoleInWorkspace.CONTRIBUTOR,
|
|
41
|
+ ],
|
|
42
|
+ UserRoleInWorkspace.CONTENT_MANAGER: [
|
|
43
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
44
|
+ UserRoleInWorkspace.CONTENT_MANAGER,
|
|
45
|
+ UserRoleInWorkspace.CONTRIBUTOR,
|
|
46
|
+ UserRoleInWorkspace.READER,
|
|
47
|
+ ],
|
|
48
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER: [
|
|
49
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
50
|
+ UserRoleInWorkspace.CONTENT_MANAGER,
|
|
51
|
+ UserRoleInWorkspace.CONTRIBUTOR,
|
|
52
|
+ UserRoleInWorkspace.READER,
|
|
53
|
+ ],
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @classmethod
|
|
57
|
+ def role_can_read_member_role(cls, reader_role: int, tested_role: int) \
|
|
58
|
+ -> bool:
|
|
59
|
+ """
|
|
60
|
+ :param reader_role: role as viewer
|
|
61
|
+ :param tested_role: role as viwed
|
|
62
|
+ :return: True if given role can view member role in workspace.
|
|
63
|
+ """
|
|
64
|
+ if reader_role in cls.members_read_rights:
|
|
65
|
+ return tested_role in cls.members_read_rights[reader_role]
|
|
66
|
+ return False
|
31
|
67
|
|
32
|
68
|
def __init__(self, current_user: User):
|
33
|
69
|
self._user = current_user
|