Beispiel #1
0
    def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_role_in_workspace(
            self):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.groups.append(
            Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME))
        current_workspace = Workspace(workspace_id=3)
        candidate_content_type = ContentType(
            slug="test",
            fa_icon="",
            hexcolor="",
            label="Test",
            creation_label="Test",
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER,
        )
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTRIBUTOR.level)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.add(role)
        self.session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> ContentType:
                return candidate_content_type

        class FakeTracimContext(TracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

            @property
            def candidate_content_type(self):
                return candidate_content_type

        with pytest.raises(InsufficientUserRoleInWorkspace):
            assert ContentTypeCreationChecker(FakeContentTypeList()).check(
                FakeTracimContext())
Beispiel #2
0
    def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_role_in_workspace(
            self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        current_workspace = Workspace(workspace_id=3, owner=current_user)
        candidate_content_type = TracimContentType(
            slug="test",
            fa_icon="",
            label="Test",
            creation_label="Test",
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER,
        )
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTRIBUTOR.level)
        session.add(current_user)
        session.add(current_workspace)
        session.add(role)
        session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> TracimContentType:
                return candidate_content_type

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

            @property
            def candidate_content_type(self):
                return candidate_content_type

        with pytest.raises(InsufficientUserRoleInWorkspace):
            assert ContentTypeCreationChecker(FakeContentTypeList()).check(
                FakeBaseFakeTracimContext())
Beispiel #3
0
    def test__unit__ContentTypeCreationChecker__ok__explicit(self):

        current_user = User(user_id=2, email='*****@*****.**')
        current_user.groups.append(
            Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME))
        current_workspace = Workspace(workspace_id=3)
        candidate_content_type = ContentType(
            slug='test',
            fa_icon='',
            hexcolor='',
            label='Test',
            creation_label='Test',
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER)
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTENT_MANAGER.level)
        self.session.add(current_user)
        self.session.add(current_workspace)
        self.session.add(role)
        self.session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> ContentType:
                return candidate_content_type

        class FakeTracimContext(TracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

        assert ContentTypeCreationChecker(FakeContentTypeList(),
                                          content_type_slug='test').check(
                                              FakeTracimContext())
Beispiel #4
0
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)
    @hapic.input_path(WorkspaceIdPathSchema())