|
@@ -50,7 +50,7 @@ class AcceptAllAuthorizationPolicy(object):
|
50
|
50
|
# We prefer to use decorators
|
51
|
51
|
|
52
|
52
|
|
53
|
|
-def require_same_user_or_profile(group: int):
|
|
53
|
+def require_same_user_or_profile(group: int) -> typing.Callable:
|
54
|
54
|
"""
|
55
|
55
|
Decorator for view to restrict access of tracim request if candidate user
|
56
|
56
|
is distinct from authenticated user and not with high enough profile.
|
|
@@ -58,9 +58,9 @@ def require_same_user_or_profile(group: int):
|
58
|
58
|
like Group.TIM_USER or Group.TIM_MANAGER
|
59
|
59
|
:return:
|
60
|
60
|
"""
|
61
|
|
- def decorator(func):
|
|
61
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
62
|
62
|
@functools.wraps(func)
|
63
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
63
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
64
|
64
|
auth_user = request.current_user
|
65
|
65
|
candidate_user = request.candidate_user
|
66
|
66
|
if auth_user.user_id == candidate_user.user_id or \
|
|
@@ -71,7 +71,7 @@ def require_same_user_or_profile(group: int):
|
71
|
71
|
return decorator
|
72
|
72
|
|
73
|
73
|
|
74
|
|
-def require_profile(group: int):
|
|
74
|
+def require_profile(group: int) -> typing.Callable:
|
75
|
75
|
"""
|
76
|
76
|
Decorator for view to restrict access of tracim request if profile is
|
77
|
77
|
not high enough
|
|
@@ -79,9 +79,9 @@ def require_profile(group: int):
|
79
|
79
|
like Group.TIM_USER or Group.TIM_MANAGER
|
80
|
80
|
:return:
|
81
|
81
|
"""
|
82
|
|
- def decorator(func):
|
|
82
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
83
|
83
|
@functools.wraps(func)
|
84
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
84
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
85
|
85
|
user = request.current_user
|
86
|
86
|
if user.profile.id >= group:
|
87
|
87
|
return func(self, context, request)
|
|
@@ -90,7 +90,7 @@ def require_profile(group: int):
|
90
|
90
|
return decorator
|
91
|
91
|
|
92
|
92
|
|
93
|
|
-def require_workspace_role(minimal_required_role: int):
|
|
93
|
+def require_workspace_role(minimal_required_role: int) -> typing.Callable:
|
94
|
94
|
"""
|
95
|
95
|
Restricts access to endpoint to minimal role or raise an exception.
|
96
|
96
|
Check role for current_workspace.
|
|
@@ -98,9 +98,9 @@ def require_workspace_role(minimal_required_role: int):
|
98
|
98
|
UserRoleInWorkspace.CONTRIBUTOR or UserRoleInWorkspace.READER
|
99
|
99
|
:return: decorator
|
100
|
100
|
"""
|
101
|
|
- def decorator(func):
|
|
101
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
102
|
102
|
@functools.wraps(func)
|
103
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
103
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
104
|
104
|
user = request.current_user
|
105
|
105
|
workspace = request.current_workspace
|
106
|
106
|
if workspace.get_user_role(user) >= minimal_required_role:
|
|
@@ -111,7 +111,7 @@ def require_workspace_role(minimal_required_role: int):
|
111
|
111
|
return decorator
|
112
|
112
|
|
113
|
113
|
|
114
|
|
-def require_candidate_workspace_role(minimal_required_role: int):
|
|
114
|
+def require_candidate_workspace_role(minimal_required_role: int) -> typing.Callable: # nopep8
|
115
|
115
|
"""
|
116
|
116
|
Restricts access to endpoint to minimal role or raise an exception.
|
117
|
117
|
Check role for candidate_workspace.
|
|
@@ -119,9 +119,9 @@ def require_candidate_workspace_role(minimal_required_role: int):
|
119
|
119
|
UserRoleInWorkspace.CONTRIBUTOR or UserRoleInWorkspace.READER
|
120
|
120
|
:return: decorator
|
121
|
121
|
"""
|
122
|
|
- def decorator(func):
|
|
122
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
123
|
123
|
|
124
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
124
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
125
|
125
|
user = request.current_user
|
126
|
126
|
workspace = request.candidate_workspace
|
127
|
127
|
|
|
@@ -133,19 +133,19 @@ def require_candidate_workspace_role(minimal_required_role: int):
|
133
|
133
|
return decorator
|
134
|
134
|
|
135
|
135
|
|
136
|
|
-def require_content_types(content_types: typing.List['NewContentType']):
|
|
136
|
+def require_content_types(content_types: typing.List['NewContentType']) -> typing.Callable: # nopep8
|
137
|
137
|
"""
|
138
|
138
|
Restricts access to specific file type or raise an exception.
|
139
|
139
|
Check role for candidate_workspace.
|
140
|
140
|
:param content_types: list of NewContentType object
|
141
|
141
|
:return: decorator
|
142
|
142
|
"""
|
143
|
|
- def decorator(func):
|
|
143
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
144
|
144
|
@functools.wraps(func)
|
145
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
145
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
146
|
146
|
content = request.current_content
|
147
|
147
|
current_content_type_slug = ContentType(content.type).slug
|
148
|
|
- content_types_slug = [content_type.slug for content_type in content_types]
|
|
148
|
+ content_types_slug = [content_type.slug for content_type in content_types] # nopep8
|
149
|
149
|
if current_content_type_slug in content_types_slug:
|
150
|
150
|
return func(self, context, request)
|
151
|
151
|
raise ContentTypeNotAllowed()
|
|
@@ -156,19 +156,19 @@ def require_content_types(content_types: typing.List['NewContentType']):
|
156
|
156
|
def require_comment_ownership_or_role(
|
157
|
157
|
minimal_required_role_for_owner: int,
|
158
|
158
|
minimal_required_role_for_anyone: int,
|
159
|
|
-) -> None:
|
|
159
|
+) -> typing.Callable:
|
160
|
160
|
"""
|
161
|
161
|
Decorator for view to restrict access of tracim request if role is
|
162
|
162
|
not high enough and user is not owner of the current_content
|
163
|
|
- :param minimal_required_role_for_owner_access: minimal role for owner
|
|
163
|
+ :param minimal_required_role_for_owner: minimal role for owner
|
164
|
164
|
of current_content to access to this view
|
165
|
165
|
:param minimal_required_role_for_anyone: minimal role for anyone to
|
166
|
166
|
access to this view.
|
167
|
167
|
:return:
|
168
|
168
|
"""
|
169
|
|
- def decorator(func):
|
|
169
|
+ def decorator(func: typing.Callable) -> typing.Callable:
|
170
|
170
|
@functools.wraps(func)
|
171
|
|
- def wrapper(self, context, request: 'TracimRequest'):
|
|
171
|
+ def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
|
172
|
172
|
user = request.current_user
|
173
|
173
|
workspace = request.current_workspace
|
174
|
174
|
comment = request.current_comment
|
|
@@ -182,4 +182,4 @@ def require_comment_ownership_or_role(
|
182
|
182
|
return func(self, context, request)
|
183
|
183
|
raise InsufficientUserWorkspaceRole()
|
184
|
184
|
return wrapper
|
185
|
|
- return decorator
|
|
185
|
+ return decorator
|