Pārlūkot izejas kodu

set most exceptions as global

Guénaël Muller 6 gadus atpakaļ
vecāks
revīzija
8258bc2edb

+ 32 - 6
tracim/__init__.py Parādīt failu

1
 # -*- coding: utf-8 -*-
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
 from pyramid.config import Configurator
7
 from pyramid.config import Configurator
6
 from pyramid.authentication import BasicAuthAuthenticationPolicy
8
 from pyramid.authentication import BasicAuthAuthenticationPolicy
15
 from tracim.lib.utils.authentification import BASIC_AUTH_WEBUI_REALM
17
 from tracim.lib.utils.authentification import BASIC_AUTH_WEBUI_REALM
16
 from tracim.lib.utils.authorization import AcceptAllAuthorizationPolicy
18
 from tracim.lib.utils.authorization import AcceptAllAuthorizationPolicy
17
 from tracim.lib.utils.authorization import TRACIM_DEFAULT_PERM
19
 from tracim.lib.utils.authorization import TRACIM_DEFAULT_PERM
20
+from tracim.lib.utils.cors import add_cors_support
18
 from tracim.lib.webdav import WebdavAppFactory
21
 from tracim.lib.webdav import WebdavAppFactory
19
 from tracim.views import BASE_API_V2
22
 from tracim.views import BASE_API_V2
20
 from tracim.views.contents_api.html_document_controller import HTMLDocumentController  # nopep8
23
 from tracim.views.contents_api.html_document_controller import HTMLDocumentController  # nopep8
25
 from tracim.views.core_api.workspace_controller import WorkspaceController
28
 from tracim.views.core_api.workspace_controller import WorkspaceController
26
 from tracim.views.contents_api.comment_controller import CommentController
29
 from tracim.views.contents_api.comment_controller import CommentController
27
 from tracim.views.errors import ErrorSchema
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
 def web(global_config, **local_settings):
42
 def web(global_config, **local_settings):
66
         debug=app_config.DEBUG,
77
         debug=app_config.DEBUG,
67
     )
78
     )
68
     hapic.set_context(context)
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
     # Add controllers
98
     # Add controllers
73
     session_controller = SessionController()
99
     session_controller = SessionController()
74
     system_controller = SystemController()
100
     system_controller = SystemController()

+ 2 - 2
tracim/tests/functional/test_user.py Parādīt failu

118
         assert 'message' in res.json.keys()
118
         assert 'message' in res.json.keys()
119
         assert 'details' in res.json.keys()
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
         Check obtain all workspaces reachables for one user who does
123
         Check obtain all workspaces reachables for one user who does
124
         not exist
124
         not exist
131
                 'admin@admin.admin'
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
         assert isinstance(res.json, dict)
135
         assert isinstance(res.json, dict)
136
         assert 'code' in res.json.keys()
136
         assert 'code' in res.json.keys()
137
         assert 'message' in res.json.keys()
137
         assert 'message' in res.json.keys()

+ 12 - 12
tracim/tests/functional/test_workspaces.py Parādīt failu

83
         assert sidebar_entry['hexcolor'] == "#757575"
83
         assert sidebar_entry['hexcolor'] == "#757575"
84
         assert sidebar_entry['fa_icon'] == "calendar"
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
         Check obtain workspace unreachable for user
88
         Check obtain workspace unreachable for user
89
         """
89
         """
94
                 'foobarbaz'
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
         assert isinstance(res.json, dict)
98
         assert isinstance(res.json, dict)
99
         assert 'code' in res.json.keys()
99
         assert 'code' in res.json.keys()
100
         assert 'message' in res.json.keys()
100
         assert 'message' in res.json.keys()
117
         assert 'message' in res.json.keys()
117
         assert 'message' in res.json.keys()
118
         assert 'details' in res.json.keys()
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
         Check obtain workspace who does not exist with an existing user.
122
         Check obtain workspace who does not exist with an existing user.
123
         """
123
         """
128
                 'admin@admin.admin'
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
         assert isinstance(res.json, dict)
132
         assert isinstance(res.json, dict)
133
         assert 'code' in res.json.keys()
133
         assert 'code' in res.json.keys()
134
         assert 'message' in res.json.keys()
134
         assert 'message' in res.json.keys()
164
         # by correct value when avatar feature will be enabled
164
         # by correct value when avatar feature will be enabled
165
         assert user_role['user']['avatar_url'] is None
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
         Check obtain workspace members list with an unreachable workspace for
169
         Check obtain workspace members list with an unreachable workspace for
170
         user
170
         user
176
                 'foobarbaz'
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
         assert isinstance(res.json, dict)
180
         assert isinstance(res.json, dict)
181
         assert 'code' in res.json.keys()
181
         assert 'code' in res.json.keys()
182
         assert 'message' in res.json.keys()
182
         assert 'message' in res.json.keys()
199
         assert 'message' in res.json.keys()
199
         assert 'message' in res.json.keys()
200
         assert 'details' in res.json.keys()
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
         Check obtain workspace members list with an existing user but
204
         Check obtain workspace members list with an existing user but
205
         an unexisting workspace
205
         an unexisting workspace
211
                 'admin@admin.admin'
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
         assert isinstance(res.json, dict)
215
         assert isinstance(res.json, dict)
216
         assert 'code' in res.json.keys()
216
         assert 'code' in res.json.keys()
217
         assert 'message' in res.json.keys()
217
         assert 'message' in res.json.keys()
739
 
739
 
740
     # Error case
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
         Check obtain workspace content list with an unreachable workspace for
744
         Check obtain workspace content list with an unreachable workspace for
745
         user
745
         user
751
                 'foobarbaz'
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
         assert isinstance(res.json, dict)
755
         assert isinstance(res.json, dict)
756
         assert 'code' in res.json.keys()
756
         assert 'code' in res.json.keys()
757
         assert 'message' in res.json.keys()
757
         assert 'message' in res.json.keys()
774
         assert 'message' in res.json.keys()
774
         assert 'message' in res.json.keys()
775
         assert 'details' in res.json.keys()
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
         Check obtain workspace contents list with an existing user but
779
         Check obtain workspace contents list with an existing user but
780
         an unexisting workspace
780
         an unexisting workspace
786
                 'admin@admin.admin'
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
         assert isinstance(res.json, dict)
790
         assert isinstance(res.json, dict)
791
         assert 'code' in res.json.keys()
791
         assert 'code' in res.json.keys()
792
         assert 'message' in res.json.keys()
792
         assert 'message' in res.json.keys()

+ 0 - 12
tracim/views/contents_api/comment_controller.py Parādīt failu

33
 class CommentController(Controller):
33
 class CommentController(Controller):
34
 
34
 
35
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
36
     @require_workspace_role(UserRoleInWorkspace.READER)
41
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
37
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
42
     @hapic.output_body(CommentSchema(many=True))
38
     @hapic.output_body(CommentSchema(many=True))
63
         ]
59
         ]
64
 
60
 
65
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
62
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
71
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
63
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
72
     @hapic.input_body(SetCommentSchema())
64
     @hapic.input_body(SetCommentSchema())
95
         return api.get_content_in_context(comment)
87
         return api.get_content_in_context(comment)
96
 
88
 
97
     @hapic.with_api_doc(tags=[COMMENT_ENDPOINTS_TAG])
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
     @require_comment_ownership_or_role(
90
     @require_comment_ownership_or_role(
103
         minimal_required_role_for_anyone=UserRoleInWorkspace.WORKSPACE_MANAGER,
91
         minimal_required_role_for_anyone=UserRoleInWorkspace.WORKSPACE_MANAGER,
104
         minimal_required_role_for_owner=UserRoleInWorkspace.CONTRIBUTOR,
92
         minimal_required_role_for_owner=UserRoleInWorkspace.CONTRIBUTOR,

+ 0 - 17
tracim/views/contents_api/html_document_controller.py Parādīt failu

40
 class HTMLDocumentController(Controller):
40
 class HTMLDocumentController(Controller):
41
 
41
 
42
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
43
     @require_workspace_role(UserRoleInWorkspace.READER)
49
     @require_content_types([html_documents_type])
44
     @require_content_types([html_documents_type])
50
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
45
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
66
         return api.get_content_in_context(content)
61
         return api.get_content_in_context(content)
67
 
62
 
68
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
64
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
74
     @require_content_types([html_documents_type])
65
     @require_content_types([html_documents_type])
75
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
66
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
104
         return api.get_content_in_context(content)
95
         return api.get_content_in_context(content)
105
 
96
 
106
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
98
     @require_workspace_role(UserRoleInWorkspace.READER)
112
     @require_content_types([html_documents_type])
99
     @require_content_types([html_documents_type])
113
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
100
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
138
         ]
125
         ]
139
 
126
 
140
     @hapic.with_api_doc(tags=[HTML_DOCUMENT_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
128
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
146
     @require_content_types([html_documents_type])
129
     @require_content_types([html_documents_type])
147
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
130
     @hapic.input_path(WorkspaceAndContentIdPathSchema())

+ 0 - 17
tracim/views/contents_api/threads_controller.py Parādīt failu

38
 class ThreadController(Controller):
38
 class ThreadController(Controller):
39
 
39
 
40
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
41
     @require_workspace_role(UserRoleInWorkspace.READER)
47
     @require_content_types([thread_type])
42
     @require_content_types([thread_type])
48
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
43
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
64
         return api.get_content_in_context(content)
59
         return api.get_content_in_context(content)
65
 
60
 
66
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
62
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
72
     @require_content_types([thread_type])
63
     @require_content_types([thread_type])
73
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
64
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
102
         return api.get_content_in_context(content)
93
         return api.get_content_in_context(content)
103
 
94
 
104
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
96
     @require_workspace_role(UserRoleInWorkspace.READER)
110
     @require_content_types([thread_type])
97
     @require_content_types([thread_type])
111
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
98
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
136
         ]
123
         ]
137
 
124
 
138
     @hapic.with_api_doc(tags=[THREAD_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
126
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
144
     @require_content_types([thread_type])
127
     @require_content_types([thread_type])
145
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
128
     @hapic.input_path(WorkspaceAndContentIdPathSchema())

+ 0 - 3
tracim/views/core_api/session_controller.py Parādīt failu

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

+ 1 - 4
tracim/views/core_api/system_controller.py Parādīt failu

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

+ 0 - 3
tracim/views/core_api/user_controller.py Parādīt failu

26
 class UserController(Controller):
26
 class UserController(Controller):
27
 
27
 
28
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
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
     @require_same_user_or_profile(Group.TIM_ADMIN)
29
     @require_same_user_or_profile(Group.TIM_ADMIN)
33
     @hapic.input_path(UserIdPathSchema())
30
     @hapic.input_path(UserIdPathSchema())
34
     @hapic.output_body(WorkspaceDigestSchema(many=True),)
31
     @hapic.output_body(WorkspaceDigestSchema(many=True),)

+ 0 - 27
tracim/views/core_api/workspace_controller.py Parādīt failu

40
 class WorkspaceController(Controller):
40
 class WorkspaceController(Controller):
41
 
41
 
42
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
43
     @require_workspace_role(UserRoleInWorkspace.READER)
47
     @hapic.input_path(WorkspaceIdPathSchema())
44
     @hapic.input_path(WorkspaceIdPathSchema())
48
     @hapic.output_body(WorkspaceSchema())
45
     @hapic.output_body(WorkspaceSchema())
60
         return wapi.get_workspace_with_context(request.current_workspace)
57
         return wapi.get_workspace_with_context(request.current_workspace)
61
 
58
 
62
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
60
     @require_workspace_role(UserRoleInWorkspace.READER)
67
     @hapic.input_path(WorkspaceIdPathSchema())
61
     @hapic.input_path(WorkspaceIdPathSchema())
68
     @hapic.output_body(WorkspaceMemberSchema(many=True))
62
     @hapic.output_body(WorkspaceMemberSchema(many=True))
89
         ]
83
         ]
90
 
84
 
91
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.READER)
86
     @require_workspace_role(UserRoleInWorkspace.READER)
96
     @hapic.input_path(WorkspaceIdPathSchema())
87
     @hapic.input_path(WorkspaceIdPathSchema())
97
     @hapic.input_query(FilterContentQuerySchema())
88
     @hapic.input_query(FilterContentQuerySchema())
125
         return contents
116
         return contents
126
 
117
 
127
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
119
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
132
     @hapic.input_path(WorkspaceIdPathSchema())
120
     @hapic.input_path(WorkspaceIdPathSchema())
133
     @hapic.input_body(ContentCreationSchema())
121
     @hapic.input_body(ContentCreationSchema())
158
         return content
146
         return content
159
 
147
 
160
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
149
     @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
165
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
150
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
166
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
151
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
213
         return api.get_content_in_context(updated_content)
198
         return api.get_content_in_context(updated_content)
214
 
199
 
215
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
201
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
220
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
202
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
221
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
203
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
248
         return
230
         return
249
 
231
 
250
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
233
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
255
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
234
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
256
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
235
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
284
         return
263
         return
285
 
264
 
286
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
266
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
291
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
267
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
292
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
268
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
316
         return
292
         return
317
 
293
 
318
     @hapic.with_api_doc(tags=[WORKSPACE_ENDPOINTS_TAG])
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
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
295
     @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
323
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
296
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
324
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
297
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8