diff --git a/tracim/exceptions.py b/tracim/exceptions.py index ba0b848..c5cc66c 100644 --- a/tracim/exceptions.py +++ b/tracim/exceptions.py @@ -117,5 +117,5 @@ class UserNotFoundInTracimRequest(TracimException): pass -class NotSameWorkspace(TracimException): - pass \ No newline at end of file +class WorkspacesDoNotMatch(TracimException): + pass diff --git a/tracim/lib/core/content.py b/tracim/lib/core/content.py index b513a05..9f254b6 100644 --- a/tracim/lib/core/content.py +++ b/tracim/lib/core/content.py @@ -25,7 +25,7 @@ from tracim.lib.utils.utils import cmp_to_key from tracim.lib.core.notifications import NotifierFactory from tracim.exceptions import SameValueError -from tracim.exceptions import NotSameWorkspace +from tracim.exceptions import WorkspacesDoNotMatch from tracim.lib.utils.utils import current_date_for_filename from tracim.models.revision_protection import new_revision from tracim.models.auth import User @@ -878,7 +878,7 @@ def move(self, item.workspace = new_workspace if new_parent and \ new_parent.workspace_id != new_workspace.workspace_id: - raise NotSameWorkspace( + raise WorkspacesDoNotMatch( 'new parent workspace and new workspace should be the same.' ) else: diff --git a/tracim/lib/utils/authorization.py b/tracim/lib/utils/authorization.py index 93344d2..d85c76f 100644 --- a/tracim/lib/utils/authorization.py +++ b/tracim/lib/utils/authorization.py @@ -8,9 +8,8 @@ except ImportError: # python3.4 JSONDecodeError = ValueError -from tracim.exceptions import InsufficientUserWorkspaceRole, \ - InsufficientUserProfile, WorkspaceNotFoundInTracimRequest - +from tracim.exceptions import InsufficientUserWorkspaceRole +from tracim.exceptions import InsufficientUserProfile if TYPE_CHECKING: from tracim import TracimRequest ### diff --git a/tracim/lib/utils/request.py b/tracim/lib/utils/request.py index 3071f38..a172197 100644 --- a/tracim/lib/utils/request.py +++ b/tracim/lib/utils/request.py @@ -2,7 +2,8 @@ from pyramid.request import Request from sqlalchemy.orm.exc import NoResultFound -from tracim.exceptions import NotAuthenticated, WorkspaceNotFoundInTracimRequest +from tracim.exceptions import NotAuthenticated +from tracim.exceptions import WorkspaceNotFoundInTracimRequest from tracim.exceptions import UserNotFoundInTracimRequest from tracim.exceptions import UserDoesNotExist from tracim.exceptions import WorkspaceNotFound @@ -59,7 +60,7 @@ def current_workspace(self) -> Workspace: :return: Workspace of the request """ if self._current_workspace is None: - self.current_workspace = self._get_current_workspace(self.current_user, self) + self._current_workspace = self._get_current_workspace(self.current_user, self) return self._current_workspace @current_workspace.setter @@ -108,10 +109,8 @@ def candidate_user(self) -> User: @property def candidate_workspace(self) -> Workspace: """ - Get user from headers/body request. This user is not - the one found by authentication mecanism. This user - can help user to know about who one page is about in - a similar way as current_workspace. + Get workspace from headers/body request. This workspace is not + the one found from path. Its the one from json body. """ if self._candidate_workspace is None: self._candidate_workspace = self._get_candidate_workspace( diff --git a/tracim/lib/utils/ttest b/tracim/lib/utils/ttest deleted file mode 100644 index 1c969a1..0000000 --- a/tracim/lib/utils/ttest +++ /dev/null @@ -1,341 +0,0 @@ - -definitions: - CommentSchema: - properties: - content_id: - example: 6 - format: int32 - type: integer - parent_id: - example: 34 - format: int32 - type: integer - x-nullable: true - content: - type: string - example: "Coucou !" - author: - $ref: '#/definitions/UserDigestSchema' - UserDigestSchema: - properties: - user_id: - example: 3 - format: int32 - readOnly: true - type: integer - avatar_url: - description: avatar_url is the url to the image file. If no avatar, then set - it to null (and frontend will interpret this with a default avatar) - example: /api/v2/assets/avatars/suri-cate.jpg - format: url - type: string - x-nullable: true - public_name: - example: Suri Cate - type: string - HtmlPageContentSchema: - properties: - content_type: - enum: - - thread - - file - - markdownpage - - page - - folder - example: htmlpage - type: string - content_id: - example: 6 - format: int32 - type: integer - is_archived: - example: false - type: boolean - is_deleted: - example: false - type: boolean - label: - example: Intervention Report 12 - type: string - parent_id: - example: 34 - format: int32 - type: integer - x-nullable: true - show_in_ui: - description: if false, then do not show content in the treeview. This may - his maybe used for specific contents or for sub-contents. Default is True. - In first version of the API, this field is always True - example: true - type: boolean - slug: - example: intervention-report-12 - type: string - status_slug: - description: this slug is found in content_type available statuses - enum: - - open - - closed-validated - - closed-unvalidated - - closed-deprecated - example: closed-deprecated - type: string - sub_content_types: - description: list of content types allowed as sub contents. This field is - required for folder contents, set it to empty list in other cases - items: - type: string - type: array - workspace_id: - example: 19 - format: int32 - type: integer - current_revision_id: - type: integer - example: 74 - created: - format: date-time - type: string - author: - $ref: '#/definitions/UserDigestSchema' - modified: - format: date-time - type: string - last_modifier: - $ref: '#/definitions/UserDigestSchema' - content: - example: '

Coucou

' - type: string - type: object - HtmlPageRevisionSchema: - properties: - content_type: - enum: - - thread - - file - - markdownpage - - page - - folder - example: htmlpage - type: string - content_id: - example: 6 - format: int32 - type: integer - is_archived: - example: false - type: boolean - is_deleted: - example: false - type: boolean - label: - example: Intervention Report 12 - type: string - parent_id: - example: 34 - format: int32 - type: integer - x-nullable: true - show_in_ui: - description: if false, then do not show content in the treeview. This may - his maybe used for specific contents or for sub-contents. Default is True. - In first version of the API, this field is always True - example: true - type: boolean - slug: - example: intervention-report-12 - type: string - status_slug: - description: this slug is found in content_type available statuses - enum: - - open - - closed-validated - - closed-unvalidated - - closed-deprecated - example: closed-deprecated - type: string - sub_content_types: - description: list of content types allowed as sub contents. This field is - required for folder contents, set it to empty list in other cases - items: - type: string - type: array - workspace_id: - example: 19 - format: int32 - type: integer - revision_id: - type: integer - example: 74 - created: - format: date-time - type: string - author: - $ref: '#/definitions/UserDigestSchema' - content: - example: '

Coucou

' - type: string - type: object - HtmlPageRevisionListSchema: - properties: - revisions: - type: array - items: - $ref: '#/definitions/HtmlPageRevisionSchema' - revision_nb: - type: integer - example: 40 - HtmlPageModifySchema: - type: object - properties: - label: - example: "My Page" - type: string - content: - example: '

Coucou

' - type: string - ContentSetStatusSchema: - type: object - properties: - status: - example: "open-workinprogress" - type: string - NoContentSchema: - type: object -info: - description: API of Tracim v2 - title: Tracim v2 API - version: 1.0.0 -parameters: {} -paths: - "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}": - get: - description: "get htmlpage content" - parameters: - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "htmlpage_id" - in: path - required: true - type: integer - description: content id of htmlpage. - responses: - '200': - description: "nominal case" - schema: - $ref: '#/definitions/HtmlPageContentSchema' - put: - description: "modify htmlpage label or/and content" - parameters: - - in: body - name: "body" - schema: - $ref: '#/definitions/HtmlPageModifySchema' - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "htmlpage_id" - in: path - required: true - type: integer - description: content id of htmlpage. - responses: - '200': - description: "nominal case" - schema: - $ref: '#/definitions/HtmlPageContentSchema' - "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}/revisions": - get: - description: "gets all htmlpages revisions (sorted by" - parameters: - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "htmlpage_id" - in: path - required: true - type: integer - description: content id of htmlpage. - responses: - '200': - description: "nominal case" - schema: - $ref: '#/definitions/HtmlPageRevisionListSchema' - "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}/status": - put: - description: "set htmlpage content status" - parameters: - - in: body - name: "body" - schema: - $ref: '#/definitions/ContentSetStatusSchema' - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "htmlpage_id" - in: path - required: true - type: integer - description: content id of htmlpage. - responses: - '200': - description: "nominal case" - schema: - $ref: '#/definitions/NoContentSchema' - "/api/v2/workspaces/{workspace_id}/contents/{content_id}/comments": - get: - description: "get all comments related to a content" - parameters: - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "content_id" - in: path - required: true - type: integer - description: content id. - responses: - '200': - description: "nominal case" - schema: - type: array - items: - $ref: '#/definitions/CommentSchema' - - "/api/v2/workspaces/{workspace_id}/contents/{content_id}/comments/{comments_id}": - delete: - description: "delete one comment" - parameters: - - name: "workspace_id" - in: path - required: true - type: integer - description: id of the current workspace. - - name: "content_id" - in: path - required: true - type: integer - description: content id. - - name: "comments_id" - in: path - required: true - type: integer - description: id of a comment related to content content_id. - responses: - '204': - description: "nominal case" - schema: - $ref: '#/definitions/NoContentSchema' -swagger: '2.0' -tags: [] diff --git a/tracim/views/core_api/workspace_controller.py b/tracim/views/core_api/workspace_controller.py index f201f65..b364197 100644 --- a/tracim/views/core_api/workspace_controller.py +++ b/tracim/views/core_api/workspace_controller.py @@ -19,7 +19,7 @@ from tracim.models.context_models import ContentInContext from tracim.exceptions import NotAuthenticated, InsufficientUserWorkspaceRole from tracim.exceptions import WorkspaceNotFoundInTracimRequest -from tracim.exceptions import NotSameWorkspace +from tracim.exceptions import WorkspacesDoNotMatch from tracim.exceptions import InsufficientUserProfile from tracim.exceptions import WorkspaceNotFound from tracim.views.controllers import Controller @@ -163,7 +163,7 @@ def create_generic_empty_content( @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN) @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN) @hapic.handle_exception(InsufficientUserWorkspaceRole, HTTPStatus.FORBIDDEN) - @hapic.handle_exception(NotSameWorkspace, HTTPStatus.BAD_REQUEST) + @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST) @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR) @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR) @hapic.input_path(WorkspaceAndContentIdPathSchema())