コード例 #1
0
    def __call__(self):
        """ Create a new revision based on an existing item IRevisionFile """
        revisionfile_info = IRevisionFileInfo(self.context)
        revision_folder = revisionfile_info.revision_folder()
        revision_info = IRevisionInfo(revision_folder)
        next_code = revision_info.next_code()

        try:
            _copy(revision_folder, self.context, revision_folder, self.context.getId(), next_code)

            cloned_revision = getattr(revision_folder, next_code)
            member = getMultiAdapter((self.context, self.request), name=u'plone_portal_state').member()
            creator = member.getId()
            cloned_revision.setCreators([creator])
            plone_utils = getToolByName(self.context, 'plone_utils')
            plone_utils.changeOwnershipOf(cloned_revision, member.getId())
            cloned_revision.setRelatedItems(self.context.getRelatedItems())
            cloned_revision.setEffectiveDate(None)
            cloned_revision.reindexObject()
            cloned_revision.reindexObjectSecurity()
        except ConflictError:
            raise
        except Exception:
            IStatusMessage(self.request).addStatusMessage(_(u'cloned_revision_error', default=u'Error'), type='error')
        else:
            IStatusMessage(self.request).addStatusMessage(_(u'cloned_revision_ok', default=u'Revision cloned correctly'), type='info')

        self.request.response.redirect("/".join(revision_folder.getPhysicalPath()))
コード例 #2
0
    def test_revision_info_adapter(self):
        """ """
        from redomino.revision.interfaces import IRevisionInfo
        revision1_info = self._revision1_info()
        self.assertTrue(IRevisionInfo.providedBy(revision1_info))
        from redomino.revision.content.revision import RevisionInfo
        self.assertIsInstance(revision1_info, RevisionInfo)

        self.assertTrue(IRevisionInfo.implementedBy(RevisionInfo))
コード例 #3
0
    def __call__(self):
        """ Create a new revision folder based on an existing item """
        context_id = self.context.getId()
        parent = getMultiAdapter((self.context, self.request), name=u'plone_context_state').parent()
        try:
            uniqueid = parent.generateUniqueId('Folder')
            uniqueid = parent.invokeFactory('Folder', uniqueid)
            folderish_obj = getattr(parent, uniqueid)

            folderish_obj.setTitle(self.context.Title())

            alsoProvides(folderish_obj, IRevision)

            revision_info = IRevisionInfo(folderish_obj)
            next_code = revision_info.next_code()

            transaction.savepoint(optimistic=True)

            _move(parent, self.context, folderish_obj, context_id, next_code)

            revisionfile = getattr(folderish_obj, next_code)
            alsoProvides(revisionfile, IRevisionFile)

            _move(parent, folderish_obj, parent, uniqueid, context_id)

            newcontext = getattr(parent, context_id)
            ppw = getToolByName(newcontext, 'portal_placeful_workflow', None)
            if ppw:
                portal_type = self.context.portal_type
                priority_utility = queryUtility(IRevisionWorkflowUtility, name=portal_type)
                priority_utility = not priority_utility and queryUtility(IRevisionWorkflowUtility)
                policy_id = priority_utility and priority_utility.policy_id()
                if policy_id and ppw.isValidPolicyName(policy_id):

                    old_sm = SecurityManagement.getSecurityManager()
                    try:
                        SecurityManagement.newSecurityManager(None, SpecialUsers.system)
                        newcontext.manage_addProduct['CMFPlacefulWorkflow'].manage_addWorkflowPolicyConfig()
                        config = ppw.getWorkflowPolicyConfig(newcontext)
                        config.setPolicyIn(policy=policy_id)
                        config.setPolicyBelow(policy=policy_id, update_security=True)
                    finally:
                        SecurityManagement.setSecurityManager(old_sm)
            newcontext.reindexObject()
            newcontext.reindexObjectSecurity()
                
        except ConflictError:
            raise
        except Exception:
            view_url = getMultiAdapter((self.context, self.request), name=u'plone_context_state').view_url()
            self.request.response.redirect(view_url)
            IStatusMessage(self.request).addStatusMessage(_(u'enabled_revision_error', default=u'Error'), type='error')
        else:
            view_url = getMultiAdapter((folderish_obj, self.request), name=u'plone_context_state').view_url()
            self.request.response.redirect(view_url)
            IStatusMessage(self.request).addStatusMessage(_(u'enabled_revision_ok', default=u'Revision created correctly'), type='info')
コード例 #4
0
def revisionfile_deleted(obj, event):
    """ Reindex the revision folder item """

    if obj is not event.object:
        return
    revisionfile_info = IRevisionFileInfo(obj)
    revision_folder = revisionfile_info.revision_folder()

    revision_info = IRevisionInfo(revision_folder)
    for revisionfile in revision_info.revisionfiles():
        revisionfile.reindexObject()
    revision_folder.reindexObject()
コード例 #5
0
    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'])
コード例 #6
0
class RevisionListViewlet(ViewletBase):
    index = ViewPageTemplateFile('templates/revisionlist_viewlet.pt')

    def update(self):
        super(RevisionListViewlet, self).update()

        self.revisionfile_info = IRevisionFileInfo(self.context)
        self.revision_info = IRevisionInfo(self.revisionfile_info.revision_folder())
        self.revisions = sorted(self.revision_info.revisionfiles_info(), key = lambda o: o['obj_info'].code(), reverse = True)
コード例 #7
0
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()
コード例 #8
0
def _latest(revision):
    revision_info = IRevisionInfo(revision)
    latest = revision_info.latest()
    return latest
コード例 #9
0
    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'])
コード例 #10
0
    def update(self):
        super(RevisionListViewlet, self).update()

        self.revisionfile_info = IRevisionFileInfo(self.context)
        self.revision_info = IRevisionInfo(self.revisionfile_info.revision_folder())
        self.revisions = sorted(self.revision_info.revisionfiles_info(), key = lambda o: o['obj_info'].code(), reverse = True)
コード例 #11
0
 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()