Example #1
0
    def test__unit__ContentTypeChecker__ok_nominal_test(self):
        class FakeTracimContext(TracimContext):
            current_content = Content(content_id=15,
                                      type=content_type_list.Thread.slug)

        assert ContentTypeChecker([
            content_type_list.File.slug, content_type_list.Thread.slug,
            content_type_list.Comment.slug
        ]).check(FakeTracimContext())
        assert ContentTypeChecker([content_type_list.Thread.slug
                                   ]).check(FakeTracimContext())
Example #2
0
    def test__unit__ContentTypeChecker__err_content_type_not_allowed(self):
        class FakeTracimContext(TracimContext):
            current_content = Content(content_id=15,
                                      type=content_type_list.Thread.slug)

        with pytest.raises(ContentTypeNotAllowed):
            assert ContentTypeChecker(
                [content_type_list.File.slug,
                 content_type_list.Comment.slug]).check(FakeTracimContext())

        with pytest.raises(ContentTypeNotAllowed):
            assert ContentTypeChecker([content_type_list.File.slug
                                       ]).check(FakeTracimContext())
Example #3
0
    def test__unit__ContentTypeChecker__err_content_type_not_exist(self):
        class FakeTracimContext(TracimContext):
            current_content = Content(content_id=15, type="unexistent_type")

        with pytest.raises(ContentTypeNotExist):
            assert ContentTypeChecker([
                "unexistent_type", content_type_list.File.slug,
                content_type_list.Comment.slug
            ]).check(FakeTracimContext())

        with pytest.raises(ContentTypeNotExist):
            assert ContentTypeChecker(["unexistent_type"
                                       ]).check(FakeTracimContext())
Example #4
0
from tracim_backend.lib.utils.authorization import ContentTypeChecker
from tracim_backend.lib.utils.authorization import check_right
from tracim_backend.lib.utils.authorization import is_content_manager
from tracim_backend.lib.utils.authorization import is_contributor
from tracim_backend.lib.utils.request import TracimRequest
from tracim_backend.lib.utils.utils import generate_documentation_swagger_tag
from tracim_backend.views.controllers import Controller
from tracim_backend.views.core_api.schemas import NoContentSchema
from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
from tracim_backend.views.swagger_generic_section import SWAGGER_TAG__CONTENT_ENDPOINTS

SWAGGER_TAG__CONTENT_SHARE_SECTION = "Share"
SWAGGER_TAG__CONTENT_FILE_ENDPOINTS = generate_documentation_swagger_tag(
    SWAGGER_TAG__CONTENT_ENDPOINTS, SWAGGER_TAG__CONTENT_SHARE_SECTION)
shareables_content_type = [FILE_TYPE]
is_shareable_content_type = ContentTypeChecker(shareables_content_type)


class ShareController(Controller):
    """
    Endpoints for Share Content
    """
    @hapic.with_api_doc(tags=[SWAGGER_TAG__CONTENT_FILE_ENDPOINTS])
    @hapic.handle_exception(WorkspacePublicDownloadDisabledException,
                            HTTPStatus.BAD_REQUEST)
    @check_right(is_content_manager)
    @check_right(is_shareable_content_type)
    @check_right(has_public_download_enabled)
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
    @hapic.input_body(ShareCreationBodySchema())
    @hapic.output_body(ContentShareSchema(many=True))
Example #5
0
from tracim_backend.views.core_api.schemas import SetContentStatusSchema
from tracim_backend.views.core_api.schemas import TextBasedContentModifySchema
from tracim_backend.views.core_api.schemas import TextBasedContentSchema
from tracim_backend.views.core_api.schemas import TextBasedRevisionSchema
from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
from tracim_backend.views.swagger_generic_section import SWAGGER_TAG__CONTENT_ENDPOINTS

try:  # Python 3.5+
    from http import HTTPStatus
except ImportError:
    from http import client as HTTPStatus

SWAGGER_TAG__CONTENT_THREAD_SECTION = "Threads"
SWAGGER_TAG__CONTENT_THREAD_ENDPOINTS = generate_documentation_swagger_tag(
    SWAGGER_TAG__CONTENT_ENDPOINTS, SWAGGER_TAG__CONTENT_THREAD_SECTION)
is_thread_content = ContentTypeChecker([THREAD_TYPE])


class ThreadController(Controller):
    @hapic.with_api_doc(tags=[SWAGGER_TAG__CONTENT_THREAD_ENDPOINTS])
    @check_right(is_reader)
    @check_right(is_thread_content)
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
    @hapic.output_body(TextBasedContentSchema())
    def get_thread(self,
                   context,
                   request: TracimRequest,
                   hapic_data=None) -> ContentInContext:
        """
        Get thread content
        """
Example #6
0
from tracim_backend.views.core_api.schemas import SetContentStatusSchema
from tracim_backend.views.core_api.schemas import SimpleFileSchema
from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
from tracim_backend.views.core_api.schemas import WorkspaceIdPathSchema
from tracim_backend.views.swagger_generic_section import SWAGGER_TAG__CONTENT_ENDPOINTS

try:  # Python 3.5+
    from http import HTTPStatus
except ImportError:
    from http import client as HTTPStatus

SWAGGER_TAG__CONTENT_FILE_SECTION = "Files"
SWAGGER_TAG__CONTENT_FILE_ENDPOINTS = generate_documentation_swagger_tag(
    SWAGGER_TAG__CONTENT_ENDPOINTS, SWAGGER_TAG__CONTENT_FILE_SECTION
)
is_file_content = ContentTypeChecker([FILE_TYPE])
can_create_file = ContentTypeCreationChecker(content_type_list, FILE_TYPE)


class FileController(Controller):
    """
    Endpoints for File Content
    """

    # File data
    @hapic.with_api_doc(tags=[SWAGGER_TAG__CONTENT_FILE_ENDPOINTS])
    @hapic.handle_exception(EmptyLabelNotAllowed, HTTPStatus.BAD_REQUEST)
    @hapic.handle_exception(UnallowedSubContent, HTTPStatus.BAD_REQUEST)
    @hapic.handle_exception(ContentFilenameAlreadyUsedInFolder, HTTPStatus.BAD_REQUEST)
    @hapic.handle_exception(ParentNotFound, HTTPStatus.BAD_REQUEST)
    @check_right(can_create_file)
Example #7
0
from tracim_backend.views.core_api.schemas import SetContentStatusSchema
from tracim_backend.views.core_api.schemas import TextBasedContentModifySchema
from tracim_backend.views.core_api.schemas import TextBasedContentSchema
from tracim_backend.views.core_api.schemas import TextBasedRevisionSchema
from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
from tracim_backend.views.swagger_generic_section import SWAGGER_TAG__CONTENT_ENDPOINTS

try:  # Python 3.5+
    from http import HTTPStatus
except ImportError:
    from http import client as HTTPStatus

SWAGGER_TAG__CONTENT_HTML_DOCUMENT_SECTION = "HTML documents"
SWAGGER_TAG__CONTENT_HTML_DOCUMENT_ENDPOINTS = generate_documentation_swagger_tag(
    SWAGGER_TAG__CONTENT_ENDPOINTS, SWAGGER_TAG__CONTENT_HTML_DOCUMENT_SECTION)
is_html_document_content = ContentTypeChecker([HTML_DOCUMENTS_TYPE])


class HTMLDocumentController(Controller):
    @hapic.with_api_doc(tags=[SWAGGER_TAG__CONTENT_HTML_DOCUMENT_ENDPOINTS])
    @check_right(is_reader)
    @check_right(is_html_document_content)
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
    @hapic.output_body(TextBasedContentSchema())
    def get_html_document(self,
                          context,
                          request: TracimRequest,
                          hapic_data=None) -> ContentInContext:
        """
        Get html document content
        """
Example #8
0
from tracim_backend.views.core_api.schemas import NoContentSchema
from tracim_backend.views.core_api.schemas import SetContentStatusSchema
from tracim_backend.views.core_api.schemas import TextBasedContentSchema
from tracim_backend.views.core_api.schemas import TextBasedRevisionSchema
from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
from tracim_backend.views.swagger_generic_section import SWAGGER_TAG__CONTENT_ENDPOINTS

try:  # Python 3.5+
    from http import HTTPStatus
except ImportError:
    from http import client as HTTPStatus

SWAGGER_TAG__CONTENT_FOLDER_SECTION = "Folders"
SWAGGER_TAG__CONTENT_FOLDER_ENDPOINTS = generate_documentation_swagger_tag(
    SWAGGER_TAG__CONTENT_ENDPOINTS, SWAGGER_TAG__CONTENT_FOLDER_SECTION)
is_folder_content = ContentTypeChecker([FOLDER_TYPE])


class FolderController(Controller):
    @hapic.with_api_doc(tags=[SWAGGER_TAG__CONTENT_FOLDER_ENDPOINTS])
    @check_right(is_reader)
    @check_right(is_folder_content)
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
    @hapic.output_body(TextBasedContentSchema())
    def get_folder(self,
                   context,
                   request: TracimRequest,
                   hapic_data=None) -> ContentInContext:
        """
        Get folder info
        """