Exemplo n.º 1
0
    def test_unit__folder_label_reserved_with_case__ok__folder_at_root(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='W1F1',
                workspace=w1,
                parent=None,
            ),
            msg='label W1F1 should be reserved',
        )
Exemplo n.º 2
0
    def test_unit__folder_label_reserved_with_case__ok__folder_at_root(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='W1F1',
                workspace=w1,
                parent=None,
            ),
            msg='label W1F1 should be reserved',
        )
Exemplo n.º 3
0
    def test_unit__folder_label_available__ok__folder_at_root(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()

        ok_(
            integrity_manager.content_label_is_free(
                content_label_as_file='f42',
                workspace=w1,
                parent=None,
            ),
            msg='label f42 should not be used',
        )
Exemplo n.º 4
0
    def test_unit__folder_label_available__ok__folder_at_root(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()

        ok_(
            integrity_manager.content_label_is_free(
                content_label_as_file='f42',
                workspace=w1,
                parent=None,
            ),
            msg='label f42 should not be used',
        )
Exemplo n.º 5
0
    def test_unit__folder_label_reserved__ok__folder_in_folder(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1f1',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1f1 should be reserved',
        )
Exemplo n.º 6
0
    def test_unit__folder_label_reserved__ok__folder_in_folder(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1f1',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1f1 should be reserved',
        )
Exemplo n.º 7
0
    def test_unit__content_label_available__ok__without_extension(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            integrity_manager.content_label_is_free(
                content_label_as_file='w1f1p42',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1p42 should be available',
        )
Exemplo n.º 8
0
    def test_unit__content_label_available__ok__without_extension(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            integrity_manager.content_label_is_free(
                content_label_as_file='w1f1p42',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1p42 should be available',
        )
Exemplo n.º 9
0
    def test_unit__content_label_reserved__ok__because_thread_extension(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1t1.html',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1t1 should be reserved because '
            'w1f1t1 rendered with .html',
        )
Exemplo n.º 10
0
    def test_unit__content_label_reserved__ok__because_page_name(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1p1.html',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1p1.html should be reserved '
                'because page w1f1p1.html',
        )
Exemplo n.º 11
0
    def test_unit__content_label_reserved__ok__because_page_name(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1p1.html',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1p1.html should be reserved '
            'because page w1f1p1.html',
        )
Exemplo n.º 12
0
    def test_unit__content_label_reserved__ok__because_thread_extension(self):
        integrity_manager = PathValidationManager()
        w1 = DBSession.query(Workspace).filter(Workspace.label == 'w1').one()
        w1f1 = self._get_content_by_label('w1f1')

        ok_(
            not integrity_manager.content_label_is_free(
                content_label_as_file='w1f1t1.html',
                workspace=w1,
                parent=w1f1,
            ),
            msg='label w1f1t1 should be reserved because '
                'w1f1t1 rendered with .html',
        )
Exemplo n.º 13
0
 def test_unit__workspace_label_available__ok(self):
     integrity_manager = PathValidationManager()
     ok_(
         integrity_manager.workspace_label_is_free('w42'),
         msg='label w42 should not be used',
     )
Exemplo n.º 14
0
 def test_unit__workspace_label_reserved_with_case__ok(self):
     integrity_manager = PathValidationManager()
     ok_(
         not integrity_manager.workspace_label_is_free('W1'),
         msg='label W1 should be reserved',
     )
Exemplo n.º 15
0
class WorkspaceRestController(TIMRestController, BaseController):
    """
     CRUD Controller allowing to manage Workspaces

     Reminder: a workspace is a group of users with associated rights
     responsible / advanced contributor. / contributor / reader
    """
    def __init__(self):
        super().__init__()
        self._path_validation = PathValidationManager(
            is_case_sensitive=False, )

    @property
    def _base_url(self):
        return '/admin/workspaces'

    @classmethod
    def current_item_id_key_in_context(cls):
        return 'workspace_id'

    @tg.expose('tracim.templates.admin.workspace_getall')
    def get_all(self, *args, **kw):
        user = tmpl_context.current_user
        workspace_api_controller = WorkspaceApi(user)
        workspaces = workspace_api_controller.get_all_manageable()
        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)

    @tg.expose('tracim.templates.admin.workspace_getone')
    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)

    @tg.expose()
    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)

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

        workspace = workspace_api_controller.create_workspace(
            name,
            description,
            calendar_enabled=calendar_enabled,
            save_now=True,
        )

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

    @tg.expose('tracim.templates.workspace.edit')
    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)

    @tg.expose('tracim.templates.workspace.edit')
    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

    @tg.expose()
    def get_delete(self, workspace_id):
        """
        Shortcut to post_delete for convenience only.
        This allow to put a link that allow to delete a user
        (instead of generating a POST or DELETE http query
        """
        return self.post_delete(workspace_id)

    @tg.expose()
    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())

    @tg.expose()
    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())

    roles = RoleInWorkspaceRestController()
Exemplo n.º 16
0
 def test_unit__workspace_label_reserved_with_case__ok(self):
     integrity_manager = PathValidationManager()
     ok_(
         not integrity_manager.workspace_label_is_free('W1'),
         msg='label W1 should be reserved',
     )
Exemplo n.º 17
0
 def test_unit__workspace_label_available__ok(self):
     integrity_manager = PathValidationManager()
     ok_(
         integrity_manager.workspace_label_is_free('w42'),
         msg='label w42 should not be used',
     )
Exemplo n.º 18
0
 def __init__(self):
     super().__init__()
     self._path_validation = PathValidationManager(
         is_case_sensitive=False,
     )
Exemplo n.º 19
0
 def __init__(self):
     super().__init__()
     self._path_validation = PathValidationManager(
         is_case_sensitive=False, )
Exemplo n.º 20
0
class WorkspaceRestController(TIMRestController, BaseController):
    """
     CRUD Controller allowing to manage Workspaces

     Reminder: a workspace is a group of users with associated rights
     responsible / advanced contributor. / contributor / reader
    """

    def __init__(self):
        super().__init__()
        self._path_validation = PathValidationManager(
            is_case_sensitive=False,
        )

    @property
    def _base_url(self):
        return '/admin/workspaces'

    @classmethod
    def current_item_id_key_in_context(cls):
        return 'workspace_id'

    @tg.expose('tracim.templates.admin.workspace_getall')
    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)

    @tg.expose('tracim.templates.admin.workspace_getone')
    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)

    @tg.expose()
    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)

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

        workspace = workspace_api_controller.create_workspace(
            name,
            description,
            calendar_enabled=calendar_enabled,
            save_now=True,
        )

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

    @tg.expose('tracim.templates.workspace.edit')
    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)

    @tg.expose('tracim.templates.workspace.edit')
    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


    @tg.expose()
    def get_delete(self, workspace_id):
        """
        Shortcut to post_delete for convenience only.
        This allow to put a link that allow to delete a user
        (instead of generating a POST or DELETE http query
        """
        return self.post_delete(workspace_id)

    @tg.expose()
    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())

    @tg.expose()
    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())

    roles = RoleInWorkspaceRestController()