Преглед изворни кода

set most exceptions as global

Guénaël Muller пре 6 година
родитељ
комит
8258bc2edb

+ 32 - 6
tracim/__init__.py Прегледај датотеку

@@ -1,6 +1,8 @@
1 1
 # -*- coding: utf-8 -*-
2
-import json
3
-import time
2
+try:  # Python 3.5+
3
+    from http import HTTPStatus
4
+except ImportError:
5
+    from http import client as HTTPStatus
4 6
 
5 7
 from pyramid.config import Configurator
6 8
 from pyramid.authentication import BasicAuthAuthenticationPolicy
@@ -15,6 +17,7 @@ from tracim.lib.utils.authentification import basic_auth_check_credentials
15 17
 from tracim.lib.utils.authentification import BASIC_AUTH_WEBUI_REALM
16 18
 from tracim.lib.utils.authorization import AcceptAllAuthorizationPolicy
17 19
 from tracim.lib.utils.authorization import TRACIM_DEFAULT_PERM
20
+from tracim.lib.utils.cors import add_cors_support
18 21
 from tracim.lib.webdav import WebdavAppFactory
19 22
 from tracim.views import BASE_API_V2
20 23
 from tracim.views.contents_api.html_document_controller import HTMLDocumentController  # nopep8
@@ -25,7 +28,15 @@ from tracim.views.core_api.user_controller import UserController
25 28
 from tracim.views.core_api.workspace_controller import WorkspaceController
26 29
 from tracim.views.contents_api.comment_controller import CommentController
27 30
 from tracim.views.errors import ErrorSchema
28
-from tracim.lib.utils.cors import add_cors_support
31
+from tracim.exceptions import NotAuthenticated
32
+from tracim.exceptions import InsufficientUserProfile
33
+from tracim.exceptions import InsufficientUserRoleInWorkspace
34
+from tracim.exceptions import WorkspaceNotFoundInTracimRequest
35
+from tracim.exceptions import UserNotFoundInTracimRequest
36
+from tracim.exceptions import WorkspaceNotFound
37
+from tracim.exceptions import UserDoesNotExist
38
+from tracim.exceptions import AuthenticationFailed
39
+from tracim.exceptions import ContentTypeNotAllowed
29 40
 
30 41
 
31 42
 def web(global_config, **local_settings):
@@ -66,9 +77,24 @@ def web(global_config, **local_settings):
66 77
         debug=app_config.DEBUG,
67 78
     )
68 79
     hapic.set_context(context)
69
-    context.handle_exception(NotFound, 404)
70
-    context.handle_exception(OperationalError, 500)
71
-    context.handle_exception(Exception, 500)
80
+    # INFO - G.M - 2018-07-04 - global-context exceptions
81
+    # Not found
82
+    context.handle_exception(NotFound, HTTPStatus.NOT_FOUND)
83
+    # Bad request
84
+    context.handle_exception(WorkspaceNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
85
+    context.handle_exception(UserNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST)  # nopep8
86
+    context.handle_exception(WorkspaceNotFound, HTTPStatus.BAD_REQUEST)
87
+    context.handle_exception(UserDoesNotExist, HTTPStatus.BAD_REQUEST)
88
+    context.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
89
+    # Auth exception
90
+    context.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
91
+    context.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
92
+    context.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)  # nopep8
93
+    context.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
94
+    # Internal server error
95
+    context.handle_exception(OperationalError, HTTPStatus.INTERNAL_SERVER_ERROR)
96
+    context.handle_exception(Exception, HTTPStatus.INTERNAL_SERVER_ERROR)
97
+
72 98
     # Add controllers
73 99
     session_controller = SessionController()
74 100
     system_controller = SystemController()

+ 2 - 2
tracim/tests/functional/test_user.py Прегледај датотеку

@@ -118,7 +118,7 @@ class TestUserWorkspaceEndpoint(FunctionalTest):
118 118
         assert 'message' in res.json.keys()
119 119
         assert 'details' in res.json.keys()
120 120
 
121
-    def test_api__get_user_workspaces__err_404__user_does_not_exist(self):
121
+    def test_api__get_user_workspaces__err_400__user_does_not_exist(self):
122 122
         """
123 123
         Check obtain all workspaces reachables for one user who does
124 124
         not exist
@@ -131,7 +131,7 @@ class TestUserWorkspaceEndpoint(FunctionalTest):
131 131
                 'admin@admin.admin'
132 132
             )
133 133
         )
134
-        res = self.testapp.get('/api/v2/users/5/workspaces', status=404)
134
+        res = self.testapp.get('/api/v2/users/5/workspaces', status=400)
135 135
         assert isinstance(res.json, dict)
136 136
         assert 'code' in res.json.keys()
137 137
         assert 'message' in res.json.keys()

+ 12 - 12
tracim/tests/functional/test_workspaces.py Прегледај датотеку

@@ -83,7 +83,7 @@ class TestWorkspaceEndpoint(FunctionalTest):
83 83
         assert sidebar_entry['hexcolor'] == "#757575"
84 84
         assert sidebar_entry['fa_icon'] == "calendar"
85 85
 
86
-    def test_api__get_workspace__err_403__unallowed_user(self) -> None:
86
+    def test_api__get_workspace__err_400__unallowed_user(self) -> None:
87 87
         """
88 88
         Check obtain workspace unreachable for user
89 89
         """
@@ -94,7 +94,7 @@ class TestWorkspaceEndpoint(FunctionalTest):
94 94
                 'foobarbaz'
95 95
             )
96 96
         )
97
-        res = self.testapp.get('/api/v2/workspaces/1', status=403)
97
+        res = self.testapp.get('/api/v2/workspaces/1', status=400)
98 98
         assert isinstance(res.json, dict)
99 99
         assert 'code' in res.json.keys()
100 100
         assert 'message' in res.json.keys()
@@ -117,7 +117,7 @@ class TestWorkspaceEndpoint(FunctionalTest):
117 117
         assert 'message' in res.json.keys()
118 118
         assert 'details' in res.json.keys()
119 119
 
120
-    def test_api__get_workspace__err_403__workspace_does_not_exist(self) -> None:  # nopep8
120
+    def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None:  # nopep8
121 121
         """
122 122
         Check obtain workspace who does not exist with an existing user.
123 123
         """
@@ -128,7 +128,7 @@ class TestWorkspaceEndpoint(FunctionalTest):
128 128
                 'admin@admin.admin'
129 129
             )
130 130
         )
131
-        res = self.testapp.get('/api/v2/workspaces/5', status=403)
131
+        res = self.testapp.get('/api/v2/workspaces/5', status=400)
132 132
         assert isinstance(res.json, dict)
133 133
         assert 'code' in res.json.keys()
134 134
         assert 'message' in res.json.keys()
@@ -164,7 +164,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
164 164
         # by correct value when avatar feature will be enabled
165 165
         assert user_role['user']['avatar_url'] is None
166 166
 
167
-    def test_api__get_workspace_members__err_403__unallowed_user(self):
167
+    def test_api__get_workspace_members__err_400__unallowed_user(self):
168 168
         """
169 169
         Check obtain workspace members list with an unreachable workspace for
170 170
         user
@@ -176,7 +176,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
176 176
                 'foobarbaz'
177 177
             )
178 178
         )
179
-        res = self.testapp.get('/api/v2/workspaces/3/members', status=403)
179
+        res = self.testapp.get('/api/v2/workspaces/3/members', status=400)
180 180
         assert isinstance(res.json, dict)
181 181
         assert 'code' in res.json.keys()
182 182
         assert 'message' in res.json.keys()
@@ -199,7 +199,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
199 199
         assert 'message' in res.json.keys()
200 200
         assert 'details' in res.json.keys()
201 201
 
202
-    def test_api__get_workspace_members__err_403__workspace_does_not_exist(self):  # nopep8
202
+    def test_api__get_workspace_members__err_400__workspace_does_not_exist(self):  # nopep8
203 203
         """
204 204
         Check obtain workspace members list with an existing user but
205 205
         an unexisting workspace
@@ -211,7 +211,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
211 211
                 'admin@admin.admin'
212 212
             )
213 213
         )
214
-        res = self.testapp.get('/api/v2/workspaces/5/members', status=403)
214
+        res = self.testapp.get('/api/v2/workspaces/5/members', status=400)
215 215
         assert isinstance(res.json, dict)
216 216
         assert 'code' in res.json.keys()
217 217
         assert 'message' in res.json.keys()
@@ -739,7 +739,7 @@ class TestWorkspaceContents(FunctionalTest):
739 739
 
740 740
     # Error case
741 741
 
742
-    def test_api__get_workspace_content__err_403__unallowed_user(self):
742
+    def test_api__get_workspace_content__err_400__unallowed_user(self):
743 743
         """
744 744
         Check obtain workspace content list with an unreachable workspace for
745 745
         user
@@ -751,7 +751,7 @@ class TestWorkspaceContents(FunctionalTest):
751 751
                 'foobarbaz'
752 752
             )
753 753
         )
754
-        res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
754
+        res = self.testapp.get('/api/v2/workspaces/3/contents', status=400)
755 755
         assert isinstance(res.json, dict)
756 756
         assert 'code' in res.json.keys()
757 757
         assert 'message' in res.json.keys()
@@ -774,7 +774,7 @@ class TestWorkspaceContents(FunctionalTest):
774 774
         assert 'message' in res.json.keys()
775 775
         assert 'details' in res.json.keys()
776 776
 
777
-    def test_api__get_workspace_content__err_403__workspace_does_not_exist(self):  # nopep8
777
+    def test_api__get_workspace_content__err_400__workspace_does_not_exist(self):  # nopep8
778 778
         """
779 779
         Check obtain workspace contents list with an existing user but
780 780
         an unexisting workspace
@@ -786,7 +786,7 @@ class TestWorkspaceContents(FunctionalTest):
786 786
                 'admin@admin.admin'
787 787
             )
788 788
         )
789
-        res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
789
+        res = self.testapp.get('/api/v2/workspaces/5/contents', status=400)
790 790
         assert isinstance(res.json, dict)
791 791
         assert 'code' in res.json.keys()
792 792
         assert 'message' in res.json.keys()

+ 0 - 12
tracim/views/contents_api/comment_controller.py Прегледај датотеку

@@ -33,10 +33,6 @@ COMMENT_ENDPOINTS_TAG = 'Comments'
33 33
 class CommentController(Controller):
34 34
 
35 35
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
36
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
37
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
38
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
39
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
40 36
     @require_workspace_role(UserRoleInWorkspace.READER)
41 37
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
42 38
     @hapic.output_body(CommentSchema(many=True))
@@ -63,10 +59,6 @@ class CommentController(Controller):
63 59
         ]
64 60
 
65 61
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
66
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
67
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
68
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
69
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
70 62
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
71 63
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
72 64
     @hapic.input_body(SetCommentSchema())
@@ -95,10 +87,6 @@ class CommentController(Controller):
95 87
         return api.get_content_in_context(comment)
96 88
 
97 89
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
98
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
99
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
100
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
101
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
102 90
     @require_comment_ownership_or_role(
103 91
         minimal_required_role_for_anyone=UserRoleInWorkspace.WORKSPACE_MANAGER,
104 92
         minimal_required_role_for_owner=UserRoleInWorkspace.CONTRIBUTOR,

+ 0 - 17
tracim/views/contents_api/html_document_controller.py Прегледај датотеку

@@ -40,11 +40,6 @@ HTML_DOCUMENT_ENDPOINTS_TAG = 'HTML documents'
40 40
 class HTMLDocumentController(Controller):
41 41
 
42 42
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
43
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
44
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
45
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
46
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
47
-    @hapic.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
48 43
     @require_workspace_role(UserRoleInWorkspace.READER)
49 44
     @require_content_types([html_documents_type])
50 45
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -66,10 +61,6 @@ class HTMLDocumentController(Controller):
66 61
         return api.get_content_in_context(content)
67 62
 
68 63
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
69
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
70
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
71
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
72
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
73 64
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
74 65
     @require_content_types([html_documents_type])
75 66
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -104,10 +95,6 @@ class HTMLDocumentController(Controller):
104 95
         return api.get_content_in_context(content)
105 96
 
106 97
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
107
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
108
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
109
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
110
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
111 98
     @require_workspace_role(UserRoleInWorkspace.READER)
112 99
     @require_content_types([html_documents_type])
113 100
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -138,10 +125,6 @@ class HTMLDocumentController(Controller):
138 125
         ]
139 126
 
140 127
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
141
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
142
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
143
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
144
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
145 128
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
146 129
     @require_content_types([html_documents_type])
147 130
     @hapic.input_path(WorkspaceAndContentIdPathSchema())

+ 0 - 17
tracim/views/contents_api/threads_controller.py Прегледај датотеку

@@ -38,11 +38,6 @@ THREAD_ENDPOINTS_TAG = 'Threads'
38 38
 class ThreadController(Controller):
39 39
 
40 40
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
41
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
42
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
43
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
44
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
45
-    @hapic.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
46 41
     @require_workspace_role(UserRoleInWorkspace.READER)
47 42
     @require_content_types([thread_type])
48 43
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -64,10 +59,6 @@ class ThreadController(Controller):
64 59
         return api.get_content_in_context(content)
65 60
 
66 61
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
67
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
68
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
69
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
70
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
71 62
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
72 63
     @require_content_types([thread_type])
73 64
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -102,10 +93,6 @@ class ThreadController(Controller):
102 93
         return api.get_content_in_context(content)
103 94
 
104 95
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
105
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
106
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
107
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
108
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
109 96
     @require_workspace_role(UserRoleInWorkspace.READER)
110 97
     @require_content_types([thread_type])
111 98
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
@@ -136,10 +123,6 @@ class ThreadController(Controller):
136 123
         ]
137 124
 
138 125
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
139
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
140
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
141
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
142
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
143 126
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
144 127
     @require_content_types([thread_type])
145 128
     @hapic.input_path(WorkspaceAndContentIdPathSchema())

+ 0 - 3
tracim/views/core_api/session_controller.py Прегледај датотеку

@@ -24,11 +24,9 @@ class SessionController(Controller):
24 24
     @hapic.with_api_doc(tags=[SESSION_ENDPOINTS_TAG])
25 25
     @hapic.input_headers(LoginOutputHeaders())
26 26
     @hapic.input_body(BasicAuthSchema())
27
-    @hapic.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
28 27
     # TODO - G.M - 17-04-2018 - fix output header ?
29 28
     # @hapic.output_headers()
30 29
     @hapic.output_body(UserSchema(),)
31
-    #@hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
32 30
     def login(self, context, request: TracimRequest, hapic_data=None):
33 31
         """
34 32
         Logs user into the system
@@ -54,7 +52,6 @@ class SessionController(Controller):
54 52
         return
55 53
 
56 54
     @hapic.with_api_doc(tags=[SESSION_ENDPOINTS_TAG])
57
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
58 55
     @hapic.output_body(UserSchema(),)
59 56
     def whoami(self, context, request: TracimRequest, hapic_data=None):
60 57
         """

+ 1 - 4
tracim/views/core_api/system_controller.py Прегледај датотеку

@@ -20,11 +20,10 @@ from tracim.views.core_api.schemas import ContentTypeSchema
20 20
 
21 21
 SYSTEM_ENDPOINTS_TAG = 'System'
22 22
 
23
+
23 24
 class SystemController(Controller):
24 25
 
25 26
     @hapic.with_api_doc(tags=[SYSTEM_ENDPOINTS_TAG])
26
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
27
-    @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
28 27
     @require_profile(Group.TIM_USER)
29 28
     @hapic.output_body(ApplicationSchema(many=True),)
30 29
     def applications(self, context, request: TracimRequest, hapic_data=None):
@@ -34,8 +33,6 @@ class SystemController(Controller):
34 33
         return applications
35 34
 
36 35
     @hapic.with_api_doc(tags=[SYSTEM_ENDPOINTS_TAG])
37
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
38
-    @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
39 36
     @require_profile(Group.TIM_USER)
40 37
     @hapic.output_body(ContentTypeSchema(many=True),)
41 38
     def content_types(self, context, request: TracimRequest, hapic_data=None):

+ 0 - 3
tracim/views/core_api/user_controller.py Прегледај датотеку

@@ -26,9 +26,6 @@ USER_ENDPOINTS_TAG = 'Users'
26 26
 class UserController(Controller):
27 27
 
28 28
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
29
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
30
-    @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
31
-    @hapic.handle_exception(UserDoesNotExist, HTTPStatus.NOT_FOUND)
32 29
     @require_same_user_or_profile(Group.TIM_ADMIN)
33 30
     @hapic.input_path(UserIdPathSchema())
34 31
     @hapic.output_body(WorkspaceDigestSchema(many=True),)

+ 0 - 27
tracim/views/core_api/workspace_controller.py Прегледај датотеку

@@ -40,9 +40,6 @@ WORKSPACE_ENDPOINTS_TAG = 'Workspaces'
40 40
 class WorkspaceController(Controller):
41 41
 
42 42
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
43
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
44
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
45
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
46 43
     @require_workspace_role(UserRoleInWorkspace.READER)
47 44
     @hapic.input_path(WorkspaceIdPathSchema())
48 45
     @hapic.output_body(WorkspaceSchema())
@@ -60,9 +57,6 @@ class WorkspaceController(Controller):
60 57
         return wapi.get_workspace_with_context(request.current_workspace)
61 58
 
62 59
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
63
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
64
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
65
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
66 60
     @require_workspace_role(UserRoleInWorkspace.READER)
67 61
     @hapic.input_path(WorkspaceIdPathSchema())
68 62
     @hapic.output_body(WorkspaceMemberSchema(many=True))
@@ -89,9 +83,6 @@ class WorkspaceController(Controller):
89 83
         ]
90 84
 
91 85
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
92
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
93
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
94
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
95 86
     @require_workspace_role(UserRoleInWorkspace.READER)
96 87
     @hapic.input_path(WorkspaceIdPathSchema())
97 88
     @hapic.input_query(FilterContentQuerySchema())
@@ -125,9 +116,6 @@ class WorkspaceController(Controller):
125 116
         return contents
126 117
 
127 118
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
128
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
129
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
130
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
131 119
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
132 120
     @hapic.input_path(WorkspaceIdPathSchema())
133 121
     @hapic.input_body(ContentCreationSchema())
@@ -158,9 +146,6 @@ class WorkspaceController(Controller):
158 146
         return content
159 147
 
160 148
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
161
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
162
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
163
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
164 149
     @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
165 150
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
166 151
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
@@ -213,9 +198,6 @@ class WorkspaceController(Controller):
213 198
         return api.get_content_in_context(updated_content)
214 199
 
215 200
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
216
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
217
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
218
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
219 201
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
220 202
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
221 203
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
@@ -248,9 +230,6 @@ class WorkspaceController(Controller):
248 230
         return
249 231
 
250 232
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
251
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
252
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
253
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
254 233
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
255 234
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
256 235
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
@@ -284,9 +263,6 @@ class WorkspaceController(Controller):
284 263
         return
285 264
 
286 265
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
287
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
288
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
289
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
290 266
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
291 267
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
292 268
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
@@ -316,9 +292,6 @@ class WorkspaceController(Controller):
316 292
         return
317 293
 
318 294
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
319
-    @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
320
-    @hapic.handle_exception(InsufficientUserRoleInWorkspace, HTTPStatus.FORBIDDEN)
321
-    @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
322 295
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
323 296
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
324 297
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8