Exemple #1
0
    def create_workspace(
        self,
        label: str = '',
        description: str = '',
        calendar_enabled: bool = False,
        save_now: bool = False,
    ) -> Workspace:
        if not label:
            label = self.generate_label()

        workspace = Workspace()
        workspace.label = label
        workspace.description = description
        workspace.calendar_enabled = calendar_enabled

        # By default, we force the current user to be the workspace manager
        # And to receive email notifications
        role = RoleApi(self._user).create_one(
            self._user,
            workspace,
            UserRoleInWorkspace.WORKSPACE_MANAGER,
            with_notif=True)

        DBSession.add(workspace)
        DBSession.add(role)

        if save_now:
            DBSession.flush()

        if calendar_enabled:
            self.ensure_calendar_exist(workspace)
        else:
            self.disable_calendar(workspace)

        return workspace
Exemple #2
0
    def create_workspace(
            self,
            label: str='',
            description: str='',
            calendar_enabled: bool=False,
            save_now: bool=False,
    ) -> Workspace:
        if not label:
            label = self.generate_label()

        workspace = Workspace()
        workspace.label = label
        workspace.description = description
        workspace.calendar_enabled = calendar_enabled

        # By default, we force the current user to be the workspace manager
        # And to receive email notifications
        role = RoleApi(self._user).create_one(self._user, workspace,
                                              UserRoleInWorkspace.WORKSPACE_MANAGER,
                                              with_notif=True)

        DBSession.add(workspace)
        DBSession.add(role)

        if save_now:
            DBSession.flush()

        if calendar_enabled:
            self.ensure_calendar_exist(workspace)
        else:
            self.disable_calendar(workspace)

        return workspace
Exemple #3
0
    def test_creates(self):
        eq_(
            0,
            DBSession.query(ContentRevisionRO).filter(
                ContentRevisionRO.label == 'TEST_CONTENT_1').count())
        eq_(
            0,
            DBSession.query(Workspace).filter(
                Workspace.label == 'TEST_WORKSPACE_1').count())

        user_admin = DBSession.query(User).filter(
            User.email == '*****@*****.**').one()
        workspace = Workspace(label="TEST_WORKSPACE_1")
        DBSession.add(workspace)
        DBSession.flush()
        eq_(
            1,
            DBSession.query(Workspace).filter(
                Workspace.label == 'TEST_WORKSPACE_1').count())

        first_content = self._create_content(
            owner=user_admin,
            workspace=workspace,
            type=ContentType.Page,
            label='TEST_CONTENT_1',
            description='TEST_CONTENT_DESCRIPTION_1',
            revision_type=ActionDescription.CREATION,
            is_deleted=False,  # TODO: pk ?
            is_archived=False,  # TODO: pk ?
            # file_content=None,  # TODO: pk ? (J'ai du mettre nullable=True)
        )

        eq_(
            1,
            DBSession.query(ContentRevisionRO).filter(
                ContentRevisionRO.label == 'TEST_CONTENT_1').count())

        content = DBSession.query(Content).filter(
            Content.id == first_content.id).one()
        eq_('TEST_CONTENT_1', content.label)
        eq_('TEST_CONTENT_DESCRIPTION_1', content.description)

        # Create a second content
        second_content = self._create_content(
            owner=user_admin,
            workspace=workspace,
            type=ContentType.Page,
            label='TEST_CONTENT_2',
            description='TEST_CONTENT_DESCRIPTION_2',
            revision_type=ActionDescription.CREATION)

        eq_(
            1,
            DBSession.query(ContentRevisionRO).filter(
                ContentRevisionRO.label == 'TEST_CONTENT_2').count())

        content = DBSession.query(Content).filter(
            Content.id == second_content.id).one()
        eq_('TEST_CONTENT_2', content.label)
        eq_('TEST_CONTENT_DESCRIPTION_2', content.description)
Exemple #4
0
    def test_create(self, key='1'):
        eq_(0, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())
        eq_(0, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())

        user_admin = DBSession.query(User).filter(User.email == '*****@*****.**').one()
        workspace = Workspace(label="TEST_WORKSPACE_%s" % key)
        DBSession.add(workspace)
        DBSession.flush()
        eq_(1, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())

        created_content = self._create_content(
            owner=user_admin,
            workspace=workspace,
            type=ContentType.Page,
            label='TEST_CONTENT_%s' % key,
            description='TEST_CONTENT_DESCRIPTION_%s' % key,
            revision_type=ActionDescription.CREATION
        )

        eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())

        content = DBSession.query(Content).filter(Content.id == created_content.id).one()
        eq_('TEST_CONTENT_%s' % key, content.label)
        eq_('TEST_CONTENT_DESCRIPTION_%s' % key, content.description)

        return created_content
Exemple #5
0
    def create_workspace(self, label: str, description: str='', save_now:bool=False) -> Workspace:
        workspace = Workspace()
        workspace.label = label
        workspace.description = description

        # By default, we force the current user to be the workspace manager
        # And to receive email notifications
        role = RoleApi(self._user).create_one(self._user, workspace,
                                              UserRoleInWorkspace.WORKSPACE_MANAGER,
                                              with_notif=True)

        DBSession.add(workspace)
        DBSession.add(role)

        if save_now:
            DBSession.flush()

        return workspace
Exemple #6
0
    def test_serialize_Content_comment_THREAD(self):
        wor = Workspace()
        wor.workspace_id = 4

        fol = Content()
        fol.type = ContentType.Folder
        fol.content_id = 72
        fol.workspace = wor

        par = Content()
        par.type = ContentType.Thread
        par.content_id = 37
        par.parent = fol
        par.workspace = wor
        par.created = datetime.now()

        obj = Content()
        obj.type = ContentType.Comment
        obj.content_id = 132
        obj.label = 'some label'
        obj.description = 'Some Description'
        obj.parent = par
        obj.created = datetime.now()

        print('LANGUAGES #2 ARE', tg.i18n.get_lang())
        res = Context(CTX.THREAD).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)

        ok_('label' in res.keys())
        eq_(obj.label, res.label, res)

        ok_('content' in res.keys())
        eq_(obj.description, res.content, res)

        ok_('created' in res.keys())

        ok_('icon' in res.keys())
        eq_(ContentType.get_icon(obj.type), res.icon, res)

        ok_('delete' in res.urls.keys())

        eq_(10, len(res.keys()), len(res.keys()))
Exemple #7
0
    def test_serialize_Content_comment_THREAD(self):
        wor = Workspace()
        wor.workspace_id = 4

        fol = Content()
        fol.type = ContentType.Folder
        fol.content_id = 72
        fol.workspace = wor

        par = Content()
        par.type = ContentType.Thread
        par.content_id = 37
        par.parent = fol
        par.workspace = wor
        par.created = datetime.now()

        obj = Content()
        obj.type = ContentType.Comment
        obj.content_id = 132
        obj.label = 'some label'
        obj.description = 'Some Description'
        obj.parent = par
        obj.created = datetime.now()

        print('LANGUAGES #2 ARE', tg.i18n.get_lang())
        res = Context(CTX.THREAD).toDict(obj)
        eq_(res.__class__, DictLikeClass, res)

        ok_('label' in res.keys())
        eq_(obj.label, res.label, res)

        ok_('content' in res.keys())
        eq_(obj.description, res.content, res)

        ok_('created' in res.keys())

        ok_('icon' in res.keys())
        eq_(ContentType.get_icon(obj.type), res.icon, res)

        ok_('delete' in res.urls.keys())

        eq_(10, len(res.keys()), len(res.keys()))
Exemple #8
0
def serialize_workspace_complete(workspace: pmd.Workspace, context: Context):
    result = DictLikeClass()
    result['id'] = workspace.workspace_id
    result['label'] = workspace.label
    result['description'] = workspace.description
    result['created'] = workspace.created
    result['members'] = context.toDict(workspace.roles)
    result['member_nb'] = len(workspace.roles)
    result['allowed_content_types'] = context.toDict(workspace.get_allowed_content_types())

    return result
Exemple #9
0
 def _create_content_from_nothing(self):
     user_admin = self._get_user()
     workspace = Workspace(label="TEST_WORKSPACE_1")
     content = self._create_content(
         owner=user_admin,
         workspace=workspace,
         type=ContentType.File,
         label='TEST_CONTENT_1',
         description='TEST_CONTENT_DESCRIPTION_1',
         revision_type=ActionDescription.CREATION,
     )
     return content
Exemple #10
0
def serialize_workspace_complete(workspace: pmd.Workspace, context: Context):
    result = DictLikeClass()
    result['id'] = workspace.workspace_id
    result['label'] = workspace.label
    result['description'] = workspace.description
    result['created'] = workspace.created
    result['members'] = context.toDict(workspace.roles)
    result['member_nb'] = len(workspace.roles)
    result['allowed_content_types'] = context.toDict(workspace.get_allowed_content_types())
    result['calendar_enabled'] = workspace.calendar_enabled
    result['calendar_url'] = workspace.calendar_url

    return result
Exemple #11
0
    def create_workspace(self,
                         label: str,
                         description: str = '',
                         save_now: bool = False) -> Workspace:
        workspace = Workspace()
        workspace.label = label
        workspace.description = description

        # By default, we force the current user to be the workspace manager
        # And to receive email notifications
        role = RoleApi(self._user).create_one(
            self._user,
            workspace,
            UserRoleInWorkspace.WORKSPACE_MANAGER,
            with_notif=True)

        DBSession.add(workspace)
        DBSession.add(role)

        if save_now:
            DBSession.flush()

        return workspace