Пример #1
0
    def test__two_folders(self):
        from Products.ATContentTypes.interfaces.folder import IATFolder
        base = IAdapter(self.portal)

        folder1 = self.portal[self.portal.invokeFactory('Folder', 'folder1')]
        folder1.reindexObject()
        folder2 = folder1[folder1.invokeFactory('Folder', 'folder2')]
        folder2.reindexObject()

        query = {}

        self.assertEqual(len(base.get_brains(**query)), 2)
        self.assertEqual(len(base.get_objects(**query)), 2)
        self.assertEqual(len(base.get_content_listing(**query)), 2)

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 2)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 2)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 2)

        query['sort_limit'] = 1
        self.assertEqual(len(base.get_brains(**query)), 1)
        self.assertEqual(len(base.get_objects(**query)), 1)
        self.assertEqual(len(base.get_content_listing(**query)), 1)

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 1)
Пример #2
0
    def test__get_brains__empty(self):
        from Products.ATContentTypes.interfaces.folder import IATFolder
        base = IAdapter(self.portal)

        query = {}

        self.assertEqual(len(base.get_brains(**query)), 0)
        self.assertEqual(len(base.get_objects(**query)), 0)
        self.assertEqual(len(base.get_content_listing(**query)), 0)
        self.assertIsNone(base.get_brain(**query))
        self.assertIsNone(base.get_object(**query))

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 0)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 0)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 0)
        self.assertIsNone(base.get_brain(interfaces=IATFolder, **query))
        self.assertIsNone(base.get_object(interfaces=IATFolder, **query))
def make_subarticles_private(context, logger=None):
    """Make subarticles private if article with use_subarticle is private"""
    if logger is None:
        logger = logging.getLogger(__name__)
    from Products.CMFCore.WorkflowCore import WorkflowException
    from collective.base.interfaces import IAdapter
    from collective.cart.shopping.interfaces import IArticle
    from collective.cart.shopping.interfaces import IArticleAdapter
    from zope.lifecycleevent import modified

    wftool = getToolByName(context, 'portal_workflow')
    portal = IAdapter(context).portal()
    adapter = IAdapter(portal)
    particles = adapter.get_objects(IArticle, use_subarticle=True, review_state="published")
    action = 'hide'

    if particles:
        obj = particles[0]
        for trans in wftool.getTransitionsFor(obj):
            tid = trans['id']
            if tid == 'retract' or tid == 'reject':
                action = tid

    articles = adapter.get_objects(IArticle, use_subarticle=True, review_state="private")
    count = 0

    for article in articles:
        aadapter = IArticleAdapter(article)
        subarticles = aadapter.get_objects(IArticle, review_state="published")
        for subarticle in subarticles:
            subarticle_path = '/'.join(subarticle.getPhysicalPath())
            try:
                wftool.doActionFor(subarticle, action)
                modified(subarticle)
                message = 'Successfully hid subarticle: {}'.format(subarticle_path)
                logger.info(message)
                count += 1
            except WorkflowException:
                message = 'Already hidden subarticle? {}'.format(subarticle_path)
                logger.info(message)

    if count:
        message = 'There are total of {} subarticles hidden.'.format(count)
        logger.info(message)
Пример #4
0
    def clear_interfaces(self):
        context = aq_inner(self.context)
        adapter = IAdapter(context)
        items = {}
        omits = [
            IVersioned, IATImage, IImageContent, IATFile, IFileContent,
            IATBlobImage, IATBlobFile
        ]
        for obj in adapter.get_objects():
            if obj.id == 'carousel':
                parent = aq_parent(aq_inner(obj))
                parent.manage_delObjects(['carousel'])
                message = 'Remove carousel folder from {}.'.format('/'.join(
                    parent.getPhysicalPath()))
                logger.info(message)
                IStatusMessage(self.request).addStatusMessage(message,
                                                              type='info')
            else:
                ifaces = [
                    iface for iface in directlyProvidedBy(obj)
                    if iface not in omits
                ]
                if ifaces:
                    for iface in ifaces:
                        annotations = IAnnotations(obj)
                        if annotations.get('collective.pfg.payment'):
                            del annotations['collective.pfg.payment']
                            message = 'Remove annotations collective.pfg.payment from {}.'.format(
                                '/'.join(obj.getPhysicalPath()))
                            logger.info(message)
                            IStatusMessage(self.request).addStatusMessage(
                                message, type='info')
                        noLongerProvides(obj, iface)
                        identifier = iface.__identifier__
                        if identifier not in items:
                            items[identifier] = 1
                        else:
                            items[identifier] += 1
                    obj.reindexObject(idxs=['object_provides'])

        for key in items:
            message = '{} objects providing {} are cleared.'.format(
                items[key], key)
            logger.info(message)
            IStatusMessage(self.request).addStatusMessage(message, type='info')
        if not items:
            message = 'No objects need to be cleared.'
            logger.info(message)
            IStatusMessage(self.request).addStatusMessage(message, type='info')
        url = self.context.absolute_url()
        return self.request.response.redirect(url)
Пример #5
0
    def test__folder_and_document(self):
        from Products.ATContentTypes.interfaces.document import IATDocument
        from Products.ATContentTypes.interfaces.folder import IATFolder
        base = IAdapter(self.portal)

        folder1 = self.portal[self.portal.invokeFactory('Folder', 'folder1')]
        folder1.reindexObject()
        doc1 = self.portal[self.portal.invokeFactory('Document', 'doc1')]
        doc1.reindexObject()

        self.assertEqual(len(base.get_brains(IATDocument)), 1)
        self.assertEqual(len(base.get_objects(IATDocument)), 1)
        self.assertEqual(len(base.get_content_listing(IATDocument)), 1)
        self.assertEqual(base.get_brain(IATDocument).id, 'doc1')
        self.assertEqual(base.get_object(IATDocument).id, 'doc1')

        self.assertEqual(len(base.get_brains([IATDocument, IATFolder])), 2)
        self.assertEqual(len(base.get_objects([IATDocument, IATFolder])), 2)
        self.assertEqual(len(base.get_content_listing([IATDocument, IATFolder])), 2)

        self.assertEqual(len(base.get_brains([IATDocument], object_provides=IATFolder.__identifier__)), 2)
        self.assertEqual(len(base.get_objects([IATDocument], object_provides=IATFolder.__identifier__)), 2)
        self.assertEqual(len(base.get_content_listing([IATDocument], object_provides=IATFolder.__identifier__)), 2)
Пример #6
0
    def clear_interfaces(self):
        context = aq_inner(self.context)
        adapter = IAdapter(context)
        items = {}
        omits = [IVersioned, IATImage, IImageContent, IATFile, IFileContent, IATBlobImage, IATBlobFile]
        for obj in adapter.get_objects():
            if obj.id == 'carousel':
                parent = aq_parent(aq_inner(obj))
                parent.manage_delObjects(['carousel'])
                message = 'Remove carousel folder from {}.'.format('/'.join(parent.getPhysicalPath()))
                logger.info(message)
                IStatusMessage(self.request).addStatusMessage(message, type='info')
            else:
                ifaces = [iface for iface in directlyProvidedBy(obj) if iface not in omits]
                if ifaces:
                    for iface in ifaces:
                        annotations = IAnnotations(obj)
                        if annotations.get('collective.pfg.payment'):
                            del annotations['collective.pfg.payment']
                            message = 'Remove annotations collective.pfg.payment from {}.'.format('/'.join(obj.getPhysicalPath()))
                            logger.info(message)
                            IStatusMessage(self.request).addStatusMessage(message, type='info')
                        noLongerProvides(obj, iface)
                        identifier = iface.__identifier__
                        if identifier not in items:
                            items[identifier] = 1
                        else:
                            items[identifier] += 1
                    obj.reindexObject(idxs=['object_provides'])

        for key in items:
            message = '{} objects providing {} are cleared.'.format(items[key], key)
            logger.info(message)
            IStatusMessage(self.request).addStatusMessage(message, type='info')
        if not items:
            message = 'No objects need to be cleared.'
            logger.info(message)
            IStatusMessage(self.request).addStatusMessage(message, type='info')
        url = self.context.absolute_url()
        return self.request.response.redirect(url)
Пример #7
0
    def test__one_folder(self):
        """Add folder under portal."""
        from Products.ATContentTypes.interfaces.folder import IATFolder
        base = IAdapter(self.portal)

        folder1 = self.portal[self.portal.invokeFactory('Folder', 'folder1')]
        folder1.reindexObject()

        query = {}

        self.assertEqual(len(base.get_brains(**query)), 1)
        self.assertEqual(len(base.get_objects(**query)), 1)
        self.assertEqual(len(base.get_content_listing(**query)), 1)
        self.assertEqual(base.get_brain(**query).id, 'folder1')
        self.assertEqual(base.get_object(**query).id, 'folder1')

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 1)
        self.assertEqual(base.get_brain(interfaces=IATFolder, **query).id, 'folder1')
        self.assertEqual(base.get_object(interfaces=IATFolder, **query).id, 'folder1')

        query = {'path': '/'.join(folder1.getPhysicalPath())}

        self.assertEqual(len(base.get_brains(**query)), 1)
        self.assertEqual(len(base.get_objects(**query)), 1)
        self.assertEqual(len(base.get_content_listing(**query)), 1)
        self.assertEqual(base.get_brain(**query).id, 'folder1')
        self.assertEqual(base.get_object(**query).id, 'folder1')

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 1)
        self.assertEqual(base.get_brain(interfaces=IATFolder, **query).id, 'folder1')
        self.assertEqual(base.get_object(interfaces=IATFolder, **query).id, 'folder1')

        query['depth'] = 0
        self.assertEqual(len(base.get_brains(**query)), 1)
        self.assertEqual(len(base.get_objects(**query)), 1)
        self.assertEqual(len(base.get_content_listing(**query)), 1)
        self.assertEqual(base.get_brain(**query).id, 'folder1')
        self.assertEqual(base.get_object(**query).id, 'folder1')

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 1)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 1)
        self.assertEqual(base.get_brain(interfaces=IATFolder, **query).id, 'folder1')
        self.assertEqual(base.get_object(interfaces=IATFolder, **query).id, 'folder1')

        query['depth'] = 1
        self.assertEqual(len(base.get_brains(**query)), 0)
        self.assertEqual(len(base.get_objects(**query)), 0)
        self.assertEqual(len(base.get_content_listing(**query)), 0)
        self.assertIsNone(base.get_brain(**query))
        self.assertIsNone(base.get_object(**query))

        self.assertEqual(len(base.get_brains(interfaces=IATFolder, **query)), 0)
        self.assertEqual(len(base.get_objects(interfaces=IATFolder, **query)), 0)
        self.assertEqual(len(base.get_content_listing(interfaces=IATFolder, **query)), 0)
        self.assertIsNone(base.get_brain(interfaces=IATFolder, **query))
        self.assertIsNone(base.get_object(interfaces=IATFolder, **query))

        query['depth'] = 0
        self.assertEqual(len(base.get_brains(**query)), 1)
        self.assertEqual(len(base.get_objects(**query)), 1)
        self.assertEqual(len(base.get_content_listing(**query)), 1)
        self.assertEqual(base.get_brain(**query).id, 'folder1')
        self.assertEqual(base.get_object(**query).id, 'folder1')

        setRoles(self.portal, TEST_USER_ID, ['Member'])

        from plone.app.testing.helpers import logout
        logout()

        base = IAdapter(self.portal)
        self.assertEqual(len(base.get_brains(**query)), 0)

        query['unrestricted'] = True
        self.assertEqual(len(base.get_brains(**query)), 1)