|
@@ -1,6 +1,7 @@
|
1
|
1
|
import typing
|
2
|
2
|
import transaction
|
3
|
3
|
from pyramid.config import Configurator
|
|
4
|
+from pyramid.httpexceptions import HTTPFound
|
4
|
5
|
|
5
|
6
|
from tracim_backend.lib.core.user import UserApi
|
6
|
7
|
from tracim_backend.models.roles import WorkspaceRoles
|
|
@@ -11,6 +12,7 @@ except ImportError:
|
11
|
12
|
from http import client as HTTPStatus
|
12
|
13
|
|
13
|
14
|
from tracim_backend import hapic
|
|
15
|
+from tracim_backend import BASE_API_V2
|
14
|
16
|
from tracim_backend import TracimRequest
|
15
|
17
|
from tracim_backend.lib.core.workspace import WorkspaceApi
|
16
|
18
|
from tracim_backend.lib.core.content import ContentApi
|
|
@@ -308,6 +310,33 @@ class WorkspaceController(Controller):
|
308
|
310
|
|
309
|
311
|
@hapic.with_api_doc(tags=[SWAGGER_TAG_WORKSPACE_ENDPOINTS])
|
310
|
312
|
@hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
|
|
313
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
314
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
315
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.FOUND) # nopep8
|
|
316
|
+ def get_content(
|
|
317
|
+ self,
|
|
318
|
+ context,
|
|
319
|
+ request: TracimRequest,
|
|
320
|
+ hapic_data=None,
|
|
321
|
+ ) -> None:
|
|
322
|
+ """
|
|
323
|
+ redirect to correct content file endpoint
|
|
324
|
+ """
|
|
325
|
+ app_config = request.registry.settings['CFG']
|
|
326
|
+ content = request.current_content
|
|
327
|
+ content_type = CONTENT_TYPES.get_one_by_slug(content.type).slug
|
|
328
|
+ # TODO - G.M - 2018-08-03 - Jsonify redirect response ?
|
|
329
|
+ raise HTTPFound(
|
|
330
|
+ "{base_url}workspaces/{workspace_id}/{content_type}s/{content_id}".format(
|
|
331
|
+ base_url=BASE_API_V2,
|
|
332
|
+ workspace_id=content.workspace_id,
|
|
333
|
+ content_type=content_type,
|
|
334
|
+ content_id=content.content_id,
|
|
335
|
+ )
|
|
336
|
+ )
|
|
337
|
+
|
|
338
|
+ @hapic.with_api_doc(tags=[SWAGGER_TAG_WORKSPACE_ENDPOINTS])
|
|
339
|
+ @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
|
311
|
340
|
@require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
|
312
|
341
|
@require_candidate_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
|
313
|
342
|
@hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
@@ -515,6 +544,9 @@ class WorkspaceController(Controller):
|
515
|
544
|
# Create Generic Content
|
516
|
545
|
configurator.add_route('create_generic_content', '/workspaces/{workspace_id}/contents', request_method='POST') # nopep8
|
517
|
546
|
configurator.add_view(self.create_generic_empty_content, route_name='create_generic_content') # nopep8
|
|
547
|
+ # Get Content
|
|
548
|
+ configurator.add_route('get_content', '/workspaces/{workspace_id}/contents/{content_id}', request_method='GET') # nopep8
|
|
549
|
+ configurator.add_view(self.get_content, route_name='get_content')
|
518
|
550
|
# Move Content
|
519
|
551
|
configurator.add_route('move_content', '/workspaces/{workspace_id}/contents/{content_id}/move', request_method='PUT') # nopep8
|
520
|
552
|
configurator.add_view(self.move_content, route_name='move_content') # nopep8
|