Exemplo n.º 1
0
 def add_content_type(
     self,
     label: str,
     slug: str,
     creation_label: str,
     available_statuses: typing.List['ContentStatus'],
     slug_alias: typing.List[str] = None,
     allow_sub_content: bool = False,
     file_extension: typing.Optional[str] = None,
     minimal_role_content_creation: WorkspaceRoles = WorkspaceRoles.
     CONTRIBUTOR,
 ):
     content_type = ContentType(
         slug=slug,
         fa_icon=self.fa_icon,
         label=label,
         hexcolor=self.hexcolor,
         creation_label=creation_label,
         available_statuses=available_statuses,
         slug_alias=slug_alias,
         allow_sub_content=allow_sub_content,
         file_extension=file_extension,
         minimal_role_content_creation=minimal_role_content_creation,
     )
     self.content_types.append(content_type)
Exemplo n.º 2
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())
Exemplo n.º 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())