Exemplo n.º 1
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

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

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            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)
        )

        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,
        )
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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'))
Exemplo n.º 6
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)
Exemplo n.º 7
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'))
Exemplo n.º 8
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())
Exemplo n.º 9
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
Exemplo n.º 10
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,
        )
Exemplo n.º 11
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
Exemplo n.º 12
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())
Exemplo n.º 13
0
    def put(self, id, name, description):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)

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

        tg.flash(_('{} workspace updated.').format(workspace.label), CST.STATUS_OK)
        tg.redirect(self.url(workspace.workspace_id))
        return
Exemplo n.º 14
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
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        role_api = RoleApi(tg.tmpl_context.current_user)
        user_api = UserApi(tg.tmpl_context.current_user)

        workspace = workspace_api_controller.get_one(workspace_id)
        role_list = role_api.get_roles_for_select_field()
        user_list = user_api.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)

        dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace')
        fake_api_content = DictLikeClass(role_types=role_list, users=user_list, current_user=current_user_content)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(fake_api_content)

        return dict(result = dictified_workspace, fake_api = fake_api)
Exemplo n.º 19
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        role_api = RoleApi(tg.tmpl_context.current_user)
        user_api = UserApi(tg.tmpl_context.current_user)

        workspace = workspace_api_controller.get_one(workspace_id)
        role_list = role_api.get_roles_for_select_field()
        user_list = user_api.get_all()

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)

        dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace')
        fake_api_content = DictLikeClass(role_types=role_list, users=user_list, current_user=current_user_content)
        fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(fake_api_content)

        return dict(result = dictified_workspace, fake_api = fake_api)
Exemplo n.º 20
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

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

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(current_user=dictified_current_user,
                                 current_workspace_folders=dictified_folders)\
        # ,
        #                      sub_items=Context(CTX.FOLDER_CONTENT_LIST).toDict(dictified_folders))

        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(workspace.get_valid_children())

        dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace')

        return DictLikeClass(result = dictified_workspace, fake_api=fake_api)
Exemplo n.º 21
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)

        tg.flash(_('{} workspace updated.').format(workspace.label), CST.STATUS_OK)
        tg.redirect(self.url(workspace.workspace_id))
        return
Exemplo n.º 22
0
    def get_one(self, workspace_id):
        user = tmpl_context.current_user

        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
        current_user_content.roles.sort(key=lambda role: role.workspace.name)

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

        dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
        dictified_folders = self.folders.get_all_fake(workspace).result
        fake_api = DictLikeClass(
            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(
            workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS))

        dictified_workspace = Context(CTX.WORKSPACE).toDict(
            workspace, 'workspace')

        return DictLikeClass(result=dictified_workspace, fake_api=fake_api)