def test_enable_revision(self): """ """ from DateTime import DateTime portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('File', 'test.pdf') obj = portal['test.pdf'] obj.setTitle('title') obj.setDescription('description') obj.setSubject(['keyword1']) obj.setRelatedItems([self._revision1()]) obj.setEffectiveDate(DateTime()) obj_title = obj.Title() obj_description = obj.Description() obj_subject = obj.Subject() obj_relateditems = obj.getRelatedItems() obj_effective = obj.effective() self.assertEquals('test.pdf', obj.getId()) self.assertEquals('File', obj.portal_type) from zope.component import getMultiAdapter view = getMultiAdapter((obj, obj.REQUEST), name='enable_revision') view() obj = portal['test.pdf'] self.assertEquals('test.pdf', obj.getId()) self.assertEquals('Folder', obj.portal_type) self.assertTrue('1' in obj.objectIds()) from redomino.revision.interfaces import IRevision self.assertTrue(IRevision.providedBy(obj)) from redomino.revision.interfaces import IRevisionInfo revision_info = IRevisionInfo(obj) latest = revision_info.latest() # metadata ok? self.assertEquals(obj_title, latest.Title()) self.assertEquals(obj_description, latest.Description()) self.assertEquals(obj_subject, latest.Subject()) self.assertEquals(obj_relateditems, latest.getRelatedItems()) self.assertEquals(obj_effective, latest.effective()) setRoles(portal, TEST_USER_ID, ['Member'])
def revisionfile_workflow(obj, event): """ Workflow state changed """ priority_utility = queryUtility(IRevisionWorkflowUtility, name=obj.portal_type) priority_utility = not priority_utility and queryUtility(IRevisionWorkflowUtility) priority_map = priority_utility and priority_utility.priority_map() if priority_map: revisionfile_info = IRevisionFileInfo(obj) revision = revisionfile_info.revision_folder() revision_info = IRevisionInfo(revision) latest = revision_info.latest() obj_status = revisionfile_info.status() latestfile_info = IRevisionFileInfo(latest) latest_status = latestfile_info.status() if priority_map.get(obj_status, {}).get('priority', -1) >= priority_map.get(latest_status, {}).get('priority', -1): # set status workflow = event.workflow workflow.setStatusOf(workflow.getId(), revision, {'action': event.action, 'review_state': obj_status, 'comments': '', 'actor': '', 'time': DateTime()}) workflow.updateRoleMappingsFor(revision) revision.reindexObject() revision.reindexObjectSecurity()
def _latest(revision): revision_info = IRevisionInfo(revision) latest = revision_info.latest() return latest
def test_enable_revision2(self): """ """ from DateTime import DateTime portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('File', 'test.pdf') obj = portal['test.pdf'] obj.setTitle('title') obj.setDescription('description') obj.setSubject(['keyword1']) obj.setEffectiveDate(DateTime()) obj_title = obj.Title() obj_description = obj.Description() obj_subject = obj.Subject() obj_effective = obj.effective() self.assertEquals('test.pdf', obj.getId()) self.assertEquals('File', obj.portal_type) from zope.component import getMultiAdapter view = getMultiAdapter((obj, obj.REQUEST), name='enable_revision') view() self.assertTrue(portal.hasObject('test.pdf')) obj = portal['test.pdf'] self.assertEquals('test.pdf', obj.getId()) self.assertEquals('Folder', obj.portal_type) self.assertTrue('1' in obj.objectIds()) from redomino.revision.interfaces import IRevision self.assertTrue(IRevision.providedBy(obj)) from redomino.revision.interfaces import IRevisionInfo revision_info = IRevisionInfo(obj) latest = revision_info.latest() # metadata ok? self.assertEquals(obj_title, latest.Title()) self.assertEquals(obj_description, latest.Description()) self.assertEquals(obj_subject, latest.Subject()) self.assertEquals(obj_effective, latest.effective()) revision1 = portal['test.pdf'] revision1_info = IRevisionInfo(revision1) revision11 = revision1['1'] portal_workflow = portal.portal_workflow self.assertEquals(portal_workflow.getInfoFor(revision1, 'review_state'), 'internal') revision11.content_status_modify('submit') revision11.content_status_modify('publish_internally') self.assertFalse('2' in revision1.objectIds()) # clone revision view = getMultiAdapter((revision11, revision11.REQUEST), name='clone_revision') view() self.assertEquals('3', revision1_info.next_code()) self.assertTrue('2' in revision1.objectIds()) ppw = getToolByName(revision1, 'portal_placeful_workflow') from redomino.revision.interfaces import IRevisionWorkflowUtility portal_type = revision11.portal_type from zope.component import queryUtility priority_utility = queryUtility(IRevisionWorkflowUtility, name=portal_type) priority_utility = not priority_utility and queryUtility(IRevisionWorkflowUtility) policy_id = priority_utility.policy_id() config = ppw.getWorkflowPolicyConfig(revision1) self.assertEquals(config.getPolicyIn().getId(), policy_id) self.assertEquals(config.getPolicyBelow().getId(), policy_id) revision12 = revision1['2'] revision12.content_status_modify('submit') revision12.reindexObject() self.assertEquals(revision11, revision1_info.latest()) self.assertEquals(portal_workflow.getInfoFor(revision1, 'review_state'), 'internally_published') # new revision12 become pending, new current revision revision12.content_status_modify('publish_internally') revision1_info.latest() IRevisionInfo(revision1).latest() self.assertEquals(revision12, revision1_info.latest()) self.assertEquals(portal_workflow.getInfoFor(revision1, 'review_state'), 'internally_published') setRoles(portal, TEST_USER_ID, ['Member'])
def is_latest(self): """ Is the latest revision? """ revision_folder = self.revision_folder() revision_folder_info = IRevisionInfo(revision_folder) return aq_inner(self.context) == revision_folder_info.latest()