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)
def put_status(self, item_id, status): item_id = int(item_id) content_api = ContentApi(tmpl_context.current_user) item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace) try: content_api.set_status(item, status) content_api.save(item, ActionDescription.STATUS_UPDATE) msg = _('{} status updated').format(self._item_type_label) tg.flash(msg, CST.STATUS_OK) tg.redirect(self._std_url.format(item.workspace_id, item.parent_id, item.content_id)) except ValueError as e: msg = _('{} status not updated: {}').format(self._item_type_label, str(e)) tg.flash(msg, CST.STATUS_ERROR) tg.redirect(self._err_url.format(item.workspace_id, item.parent_id, item.content_id))
def test_set_status_unknown_status(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) api.set_status(c, 'unknown-status')
def put_status(self, item_id, status): item_id = int(item_id) content_api = ContentApi(tmpl_context.current_user) item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace) try: with new_revision(item): content_api.set_status(item, status) content_api.save(item, ActionDescription.STATUS_UPDATE) msg = _('{} status updated').format(self._item_type_label) tg.flash(msg, CST.STATUS_OK) tg.redirect(self._std_url.format(item.workspace_id, item.parent_id, item.content_id)) except ValueError as e: msg = _('{} status not updated: {}').format(self._item_type_label, str(e)) tg.flash(msg, CST.STATUS_ERROR) tg.redirect(self._err_url.format(item.workspace_id, item.parent_id, item.content_id))
def test_set_status_unknown_status(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): api.set_status(c, 'unknown-status')
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) 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)
def put_status(self, item_id, status): item_id = int(item_id) content_api = ContentApi(tmpl_context.current_user) try: item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace) with new_revision(item): content_api.set_status(item, status) content_api.save(item, ActionDescription.STATUS_UPDATE) msg = _('{} status updated').format(self._item_type_label) tg.flash(msg, CST.STATUS_OK) tg.redirect(self._std_url.format(item.workspace_id, item.parent_id, item.content_id)) except ValueError as e: msg = _('{} status not updated: {}').format(self._item_type_label, str(e)) tg.flash(msg, CST.STATUS_ERROR) tg.redirect(self._err_url.format(item.workspace_id, item.parent_id, item.content_id)) except NoResultFound as e: # probably the content is deleted or archived => forbidden to update status content_api = ContentApi( tmpl_context.current_user, show_archived=True, show_deleted=True ) item = content_api.get_one( item_id, self._item_type, tmpl_context.workspace ) next_url = self._std_url.format( item.workspace_id, item.parent_id, item.content_id ) msg = _('{} status not updated: the operation ' 'is not allowed on deleted/archived content').format( self._item_type_label ) tg.flash(msg, CST.STATUS_ERROR) tg.redirect(next_url)