Пример #1
0
    def test_unit__cant_get_non_access_content__ok__nominal_case(self):
        admin = DBSession.query(User)\
            .filter(User.email == '*****@*****.**').one()
        bob = DBSession.query(User)\
            .filter(User.email == '*****@*****.**').one()

        bob_workspace = WorkspaceApi(bob).create_workspace(
            'bob_workspace',
            save_now=True,
        )
        admin_workspace = WorkspaceApi(admin).create_workspace(
            'admin_workspace',
            save_now=True,
        )

        bob_page = ContentApi(bob).create(
            content_type=ContentType.Page,
            workspace=bob_workspace,
            label='bob_page',
            do_save=True,
        )

        admin_page = ContentApi(bob).create(
            content_type=ContentType.Page,
            workspace=admin_workspace,
            label='admin_page',
            do_save=True,
        )

        bob_viewable = ContentApi(bob).get_all()
        eq_(1, len(bob_viewable), 'Bob should view only one content')
        eq_(
            'bob_page',
            bob_viewable[0].label, 'Bob should not view "{0}" content'.format(
                bob_viewable[0].label, ))
Пример #2
0
    def test_get_all_with_parent_id(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)
        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        item = api.create(ContentType.Folder, workspace, None, 'parent', True)
        item2 = api.create(ContentType.File, workspace, item, 'file1', True)
        item3 = api.create(ContentType.File, workspace, None, 'file2', True)
        parent_id = item.content_id
        child_id = item2.content_id
        uid = user.user_id
        wid = workspace.workspace_id
        transaction.commit()

        # Refresh instances after commit
        user = uapi.get_one(uid)
        workspace = WorkspaceApi(user).get_one(wid)
        api = ContentApi(user)

        items = api.get_all(None, ContentType.Any, workspace)
        eq_(3, len(items))

        items2 = api.get_all(parent_id, ContentType.File, workspace)
        eq_(1, len(items2))
        eq_(child_id, items2[0].content_id)
Пример #3
0
 def test_unit__get_all_manageable(self):
     admin = DBSession.query(User) \
         .filter(User.email == '*****@*****.**').one()
     uapi = UserApi(admin)
     # Checks a case without workspaces.
     wapi = WorkspaceApi(current_user=admin)
     eq_([], wapi.get_all_manageable())
     # Checks an admin gets all workspaces.
     w4 = wapi.create_workspace(label='w4')
     w3 = wapi.create_workspace(label='w3')
     w2 = wapi.create_workspace(label='w2')
     w1 = wapi.create_workspace(label='w1')
     eq_([w1, w2, w3, w4], wapi.get_all_manageable())
     # Checks a regular user gets none workspace.
     gapi = GroupApi(None)
     u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True)
     wapi = WorkspaceApi(current_user=u)
     rapi = RoleApi(current_user=u)
     off = 'off'
     rapi.create_one(u, w4, UserRoleInWorkspace.READER, off)
     rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, off)
     rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, off)
     rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
     eq_([], wapi.get_all_manageable())
     # Checks a manager gets only its own workspaces.
     u.groups.append(gapi.get_one(Group.TIM_MANAGER))
     rapi.delete_one(u.user_id, w2.workspace_id)
     rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
     eq_([w1, w2], wapi.get_all_manageable())
Пример #4
0
    def test_archive(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)
        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        item = api.create(ContentType.Folder, workspace, None, 'not_archived',
                          True)
        item2 = api.create(ContentType.Folder, workspace, None, 'to_archive',
                           True)
        uid = user.user_id
        wid = workspace.workspace_id
        transaction.commit()

        # Refresh instances after commit
        user = uapi.get_one(uid)
        workspace = WorkspaceApi(user).get_one(wid)
        api = ContentApi(user)

        items = api.get_all(None, ContentType.Any, workspace)
        eq_(2, len(items))

        items = api.get_all(None, ContentType.Any, workspace)
        with new_revision(items[0]):
            api.archive(items[0])
        transaction.commit()

        # Refresh instances after commit
        user = uapi.get_one(uid)
        workspace = WorkspaceApi(user).get_one(wid)
        api = ContentApi(user)

        items = api.get_all(None, ContentType.Any, workspace)
        eq_(1, len(items))
        transaction.commit()

        # Refresh instances after commit
        user = uapi.get_one(uid)
        workspace = WorkspaceApi(user).get_one(wid)
        api = ContentApi(user)

        # Test that the item is still available if "show deleted" is activated
        api = ContentApi(None, show_archived=True)
        items = api.get_all(None, ContentType.Any, workspace)
        eq_(2, len(items))
Пример #5
0
    def test_func__rights_read_workspace_calendar__fail__as_unauthorized(self):
        lawrence = DBSession.query(User).filter(
            User.email == '*****@*****.**'
        ).one()
        workspace = WorkspaceApi(lawrence).create_workspace(
            'workspace_1',
            save_now=False
        )
        workspace.calendar_enabled = True
        DBSession.flush()

        workspace_calendar_url = CalendarManager.get_workspace_calendar_url(
            workspace.workspace_id
        )

        transaction.commit()

        radicale_base_url = CalendarManager.get_base_url()
        client = caldav.DAVClient(
            radicale_base_url,
            username='******',
            password='******'
        )
        caldav.Calendar(
            parent=client,
            client=client,
            url=workspace_calendar_url
        ).events()
Пример #6
0
    def _build_sibling_list_of_workspaces(
            self,
            workspace: Workspace,
            child_contents: [NodeTreeItem],
            select_active_workspace=False,
            all_workspaces=True) -> [NodeTreeItem]:

        root_items = []
        api = WorkspaceApi(tmpl_context.current_user)
        workspaces = api.get_all_for_user(tmpl_context.current_user)

        if not all_workspaces:
            # Show only current workspace - this is used for "move item" screen
            # which must not allow to move from a workspace to another
            item = NodeTreeItem(workspace, child_contents)
            item.is_selected = select_active_workspace
            root_items.append(item)
        else:
            for workspace_cursor in workspaces:
                item = None
                if workspace_cursor == workspace:
                    item = NodeTreeItem(workspace_cursor, child_contents)
                else:
                    item = NodeTreeItem(workspace_cursor, [])

                item.is_selected = select_active_workspace and workspace_cursor == workspace

                root_items.append(item)

        return root_items
Пример #7
0
    def test_set_status_ok(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)
        api = ContentApi(user)
        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
        with new_revision(c):
            for new_status in [
                    'open', 'closed-validated', 'closed-unvalidated',
                    'closed-deprecated'
            ]:
                api.set_status(c, new_status)

                eq_(new_status, c.status)
                eq_(ActionDescription.STATUS_UPDATE, c.revision_type)
Пример #8
0
    def test_create_comment_ok(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
        c = api.create_comment(workspace, p, 'this is the comment', True)

        eq_(Content, c.__class__)
        eq_(p.content_id, c.parent_id)
        eq_(user, c.owner)
        eq_(workspace, c.workspace)
        eq_(ContentType.Comment, c.type)
        eq_('this is the comment', c.description)
        eq_('', c.label)
        eq_(ActionDescription.COMMENT, c.revision_type)
Пример #9
0
    def test_search_in_description(self):
        # HACK - D.A. - 2015-03-09
        # This test is based on a bug which does NOT return results found
        # at root of a workspace (eg a folder)

        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        a = api.create(ContentType.Folder, workspace, None,
                       'this is randomized folder', True)
        p = api.create(ContentType.Page, workspace, a,
                       'this is dummy label content', True)

        with new_revision(p):
            p.description = 'This is some amazing test'

        api.save(p)
        original_id = p.content_id

        res = api.search(['dummy'])
        eq_(1, len(res.all()))
        item = res.all()[0]
        eq_(original_id, item.content_id)
Пример #10
0
    def put(self, id, name, description, calendar_enabled: str = 'off'):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        calendar_enabled = on_off_to_boolean(calendar_enabled)
        workspace = workspace_api_controller.get_one(id)

        # Display error page to user if chosen label is in conflict
        if name != workspace.label and \
                not self._path_validation.workspace_label_is_free(name):
            return render_invalid_integrity_chosen_path(name)

        workspace.label = name
        workspace.description = description
        workspace.calendar_enabled = calendar_enabled
        workspace_api_controller.save(workspace)

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

        tg.flash(
            _('{} workspace updated.').format(workspace.label), CST.STATUS_OK)
        tg.redirect(self.url(workspace.workspace_id))
        return
Пример #11
0
Файл: api.py Проект: qyqx/tracim
    def index(self):
        # NOTE BS 20161025: I can't use tmpl_context.current_user,
        # I d'ont know why
        workspace_api = WorkspaceApi(tmpl_context.identity.get('user'))
        workspaces = workspace_api.get_all()
        serialized_workspaces = Context(CTX.API_WORKSPACE).toDict(workspaces)

        return {'value_list': serialized_workspaces}
Пример #12
0
    def edit(self, id):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)

        workspace = workspace_api_controller.get_one(id)

        dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace')
        return DictLikeClass(result = dictified_workspace)
Пример #13
0
    def test_mark_read__all(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]
        user_a = uapi.create_user(email='this.is@user',
                                  groups=groups,
                                  save_now=True)
        user_b = uapi.create_user(email='*****@*****.**',
                                  groups=groups,
                                  save_now=True)

        wapi = WorkspaceApi(user_a)
        workspace = wapi.create_workspace('test workspace', save_now=True)

        role_api = RoleApi(user_a)
        role_api.create_one(user_b, workspace, UserRoleInWorkspace.READER,
                            False)
        cont_api_a = ContentApi(user_a)
        cont_api_b = ContentApi(user_b)

        page_2 = cont_api_a.create(ContentType.Page,
                                   workspace,
                                   None,
                                   'this is page1',
                                   do_save=True)
        page_3 = cont_api_a.create(ContentType.Thread,
                                   workspace,
                                   None,
                                   'this is page2',
                                   do_save=True)
        page_4 = cont_api_a.create(ContentType.File,
                                   workspace,
                                   None,
                                   'this is page3',
                                   do_save=True)

        for rev in page_2.revisions:
            eq_(user_b not in rev.read_by.keys(), True)
        for rev in page_3.revisions:
            eq_(user_b not in rev.read_by.keys(), True)
        for rev in page_4.revisions:
            eq_(user_b not in rev.read_by.keys(), True)

        DBSession.refresh(page_2)
        DBSession.refresh(page_3)
        DBSession.refresh(page_4)

        cont_api_b.mark_read__all()

        for rev in page_2.revisions:
            eq_(user_b in rev.read_by.keys(), True)
        for rev in page_3.revisions:
            eq_(user_b in rev.read_by.keys(), True)
        for rev in page_4.revisions:
            eq_(user_b in rev.read_by.keys(), True)
Пример #14
0
    def _create_workspace_and_test(self, name, user) -> Workspace:
        """
        All extra parameters (*args, **kwargs) are for Workspace init
        :return: Created workspace instance
        """
        WorkspaceApi(user).create_workspace(name, save_now=True)

        eq_(1, DBSession.query(Workspace).filter(Workspace.label == name).count())
        return DBSession.query(Workspace).filter(Workspace.label == name).one()
Пример #15
0
    def __init__(self, path: str, environ: dict):
        super(Root, self).__init__(path, environ)

        self.user = UserApi(None).get_one_by_email(
            environ['http_authenticator.username'])
        # TODO BS 20170221: Web interface should list all workspace to. We
        # disable it here for moment. When web interface will be updated to
        # list all workspace, change this here to.
        self.workspace_api = WorkspaceApi(self.user, force_role=True)
Пример #16
0
    def get_workspace_readable_calendars_for_user(cls, user: User)\
            -> ['Workspace']:
        workspaces = []
        workspace_api = WorkspaceApi(user)

        for workspace in workspace_api.get_all():
            if workspace.calendar_enabled:
                workspaces.append(workspace)

        return workspaces
Пример #17
0
    def treeview_root(self, id='#',
                      current_id=None,
                      all_workspaces=True,
                      folder_allowed_content_types='',
                      ignore_id=None,
                      ignore_workspace_id=None):
        all_workspaces = bool(int(all_workspaces))

        # ignore_workspace_id is a string like 3,12,78,15
        ignored_ids = [int(id) for id in ignore_workspace_id.split(',')] if ignore_workspace_id else None

        if not current_id:
            # Default case is to return list of workspaces
            api = WorkspaceApi(tmpl_context.current_user)
            workspaces = api.get_all_for_user(tmpl_context.current_user,
                                              ignored_ids)
            dictified_workspaces = Context(CTX.MENU_API).toDict(workspaces, 'd')
            return dictified_workspaces

        allowed_content_types = ContentType.allowed_types_from_str(folder_allowed_content_types)
        ignored_item_ids = [int(ignore_id)] if ignore_id else []

        # Now complex case: we must return a structured tree
        # including the selected node, all parents (and their siblings)
        workspace, content = convert_id_into_instances(current_id)

        # The following step allow to select the parent folder when content itself is not visible in the treeview
        if content and content.type!=ContentType.Folder and CFG.CST.TREEVIEW_ALL!=CFG.get_instance().WEBSITE_TREEVIEW_CONTENT:
            content = content.parent if content.parent else None

        # This is the init of the recursive-like build of the tree
        content_parent = content
        tree_items = []

        # The first step allow to load child of selected item
        # (for example, when you select a folder in the windows explorer,
        # then the selected folder is expanded by default)
        content_api = ContentApi(tmpl_context.current_user)
        child_folders = content_api.get_child_folders(content_parent, workspace, allowed_content_types, ignored_item_ids)

        if len(child_folders)>0:
            first_child = child_folders[0]
            content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, first_child, tree_items, False, allowed_content_types, ignored_item_ids)

        content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items, True, allowed_content_types, ignored_item_ids)
        while content_parent:
            # Do the same for the parent level
            content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items)
        # Now, we have a tree_items list that is the root folders list,
        # so we now have to put it as a child of a list of workspaces
        should_select_workspace = not content

        full_tree = self._build_sibling_list_of_workspaces(workspace, tree_items, should_select_workspace, all_workspaces)

        return Context(CTX.MENU_API_BUILD_FROM_TREE_ITEM).toDict(full_tree, 'd')
Пример #18
0
    def get_workspace_readable_calendars_urls_for_user(cls, user: User)\
            -> [str]:
        calendar_urls = []
        workspace_api = WorkspaceApi(user)
        for workspace in workspace_api.get_all_for_user(user):
            if workspace.calendar_enabled:
                calendar_urls.append(
                    cls.get_workspace_calendar_url(
                        workspace_id=workspace.workspace_id, ))

        return calendar_urls
Пример #19
0
    def mark_read(self, workspace_id, **kwargs):

        user = tmpl_context.current_user
        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        content_api = ContentApi(user)
        content_api.mark_read__workspace(workspace)

        tg.redirect('/workspaces/{}'.format(workspace_id))
        return DictLikeClass(fake_api=fake_api)
Пример #20
0
    def disable_notifications(self, workspace_id, next_url=None):
        workspace_id = int(workspace_id)
        api = WorkspaceApi(tg.tmpl_context.current_user)

        workspace = api.get_one(workspace_id)
        api.disable_notifications(tg.tmpl_context.current_user, workspace)
        tg.flash(_('Notification disabled for workspace {}').format(workspace.label))

        if next_url:
            tg.redirect(tg.url(next_url))
        tg.redirect(self.parent_controller.url(None, 'me'))
Пример #21
0
    def restore(self, workspace_id):
        workspace_id = int(workspace_id)

        api = WorkspaceApi(tg.tmpl_context.current_user)
        workspace = api.restore_one(workspace_id, True)

        workspace_label = workspace.label
        undo_url = self.url(workspace_id, 'delete')

        tg.flash(_('{} workspace restored.').format(workspace_label), CST.STATUS_OK)
        tg.redirect(self.url())
Пример #22
0
    def get_all(self, *args, **kw):

        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)

        workspaces = workspace_api_controller.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict({'current_user': current_user_content})

        dictified_workspaces = Context(CTX.ADMIN_WORKSPACES).toDict(workspaces, 'workspaces', 'workspace_nb')
        return DictLikeClass(result = dictified_workspaces, fake_api=fake_api)
Пример #23
0
    def current_workspace(cls) -> Workspace:
        """
        To be used by other conrtollers in order to setup workspace instance in the context
        """
        workspace_api = WorkspaceApi(tg.tmpl_context.current_user)
        workspace_id = int(tg.request.controller_state.routing_args.get('workspace_id'))
        workspace = workspace_api.get_one(workspace_id)

        tg.tmpl_context.workspace_id = workspace_id
        tg.tmpl_context.workspace = workspace

        return workspace
Пример #24
0
    def get_one(self, workspace_id, **kwargs):
        """
        :param workspace_id: Displayed workspace id
        :param kwargs:
          * show_deleted: bool: Display deleted contents or hide them if False
          * show_archived: bool: Display archived contents or hide them
            if False
        """
        show_deleted = str_as_bool(kwargs.get('show_deleted', False))
        show_archived = str_as_bool(kwargs.get('show_archived', ''))
        user = tmpl_context.current_user

        workspace_api = WorkspaceApi(user)
        workspace = workspace_api.get_one(workspace_id)

        unread_contents = ContentApi(user).get_last_unread(None,
                                                           ContentType.Any,
                                                           workspace=workspace)
        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)



        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents,
                                                         'contents',
                                                         'nb'),
            current_user=dictified_current_user,
            current_workspace_folders=dictified_folders,
            current_user_workspace_role=workspace.get_user_role(user)
        )

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
            # TODO BS 20161209: Is the correct way to grab folders? No use API?
            workspace.get_valid_children(
                ContentApi.DISPLAYABLE_CONTENTS,
                show_deleted=show_deleted,
                show_archived=show_archived,
            )
        )

        dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')
        webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL

        return DictLikeClass(
            result=dictified_workspace,
            fake_api=fake_api,
            webdav_url=webdav_url,
            show_deleted=show_deleted,
            show_archived=show_archived,
        )
Пример #25
0
    def post_delete(self, workspace_id):
        workspace_id = int(workspace_id)

        api = WorkspaceApi(tg.tmpl_context.current_user)
        workspace = api.get_one(workspace_id)
        api.delete_one(workspace_id)

        workspace_label = workspace.label
        undo_url = self.url(workspace_id, self.restore.__name__)

        tg.flash(_('{} workspace deleted. In case of error, you can <a class="alert-link" href="{}">restore it</a>.').format(workspace_label, undo_url), CST.STATUS_OK, no_escape=True)
        tg.redirect(self.url())
Пример #26
0
 def test_get_notifiable_roles(self):
     admin = DBSession.query(User) \
         .filter(User.email == '*****@*****.**').one()
     wapi = WorkspaceApi(admin)
     w = wapi.create_workspace(label='workspace w', save_now=True)
     uapi = UserApi(admin)
     u = uapi.create_user(email='[email protected]', save_now=True)
     eq_([], wapi.get_notifiable_roles(workspace=w))
     rapi = RoleApi(u)
     r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif='on')
     eq_([r, ], wapi.get_notifiable_roles(workspace=w))
     u.is_active = False
     eq_([], wapi.get_notifiable_roles(workspace=w))
Пример #27
0
    def _before(self, *args, **kw):
        """
        Instantiate the current workspace in tg.tmpl_context
        :param args:
        :param kw:
        :return:
        """
        super(self.__class__, self)._before(args, kw)

        workspace_api = WorkspaceApi(tg.tmpl_context.current_user)
        workspace_id = tg.request.controller_state.routing_args.get('workspace_id')
        workspace = workspace_api.get_one(workspace_id)
        tg.tmpl_context.workspace_id = workspace_id
        tg.tmpl_context.workspace = workspace
Пример #28
0
    def test_get_all_with_filter(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)
        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        item = api.create(ContentType.Folder, workspace, None, 'thefolder',
                          True)
        item2 = api.create(ContentType.File, workspace, None, 'thefile', True)
        uid = user.user_id
        wid = workspace.workspace_id
        transaction.commit()

        # Refresh instances after commit
        user = uapi.get_one(uid)
        workspace = WorkspaceApi(user).get_one(wid)
        api = ContentApi(user)

        items = api.get_all(None, ContentType.Any, workspace)
        eq_(2, len(items))

        items2 = api.get_all(None, ContentType.File, workspace)
        eq_(1, len(items2))
        eq_('thefile', items2[0].label)

        items3 = api.get_all(None, ContentType.Folder, workspace)
        eq_(1, len(items3))
        eq_('thefolder', items3[0].label)
Пример #29
0
    def post(self, name, description, calendar_enabled: str = 'off'):
        # FIXME - Check user profile
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        calendar_enabled = on_off_to_boolean(calendar_enabled)

        workspace = workspace_api_controller.create_workspace(
            name, description)
        workspace.calendar_enabled = calendar_enabled
        DBSession.flush()

        tg.flash(
            _('{} workspace created.').format(workspace.label), CST.STATUS_OK)
        tg.redirect(self.url())
        return
Пример #30
0
    def put(self, id, name, description, calendar_enabled: str = 'off'):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        calendar_enabled = on_off_to_boolean(calendar_enabled)

        workspace = workspace_api_controller.get_one(id)
        workspace.label = name
        workspace.description = description
        workspace.calendar_enabled = calendar_enabled
        workspace_api_controller.save(workspace)

        tg.flash(
            _('{} workspace updated.').format(workspace.label), CST.STATUS_OK)
        tg.redirect(self.url(workspace.workspace_id))
        return