def test_blacklisting_intermediate_wildcards_does_not_affect_parents(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        config.appendPathToBlacklist('/demo/one*two')
        blacklist = IPathBlacklist(self.portal)

        self.assertFalse(blacklist.is_blacklisted('/demo/one'))
        self.assertFalse(blacklist.is_blacklisted('/demo/oneXtwo'))
        self.assertFalse(blacklist.is_blacklisted('/demo/one/two'))
    def test_blacklist_does_not_affect_parents(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        config.appendPathToBlacklist('/foo/bar/one/two/three')
        blacklist = IPathBlacklist(self.portal)

        self.assertFalse(blacklist.is_blacklisted('/foo/bar'))
        self.assertFalse(blacklist.is_blacklisted('/foo/bar/one/two'))
        self.assertTrue(blacklist.is_blacklisted('/foo/bar/one/two/three'))
    def test_blacklisting_intermediate_wildcards_does_not_affect_parents(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        config.appendPathToBlacklist('/demo/one*two')
        blacklist = IPathBlacklist(self.portal)

        self.assertFalse(blacklist.is_blacklisted('/demo/one'))
        self.assertFalse(blacklist.is_blacklisted('/demo/oneXtwo'))
        self.assertFalse(blacklist.is_blacklisted('/demo/one/two'))
    def test_blacklist_does_not_affect_parents(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        config.appendPathToBlacklist('/foo/bar/one/two/three')
        blacklist = IPathBlacklist(self.portal)

        self.assertFalse(blacklist.is_blacklisted('/foo/bar'))
        self.assertFalse(blacklist.is_blacklisted('/foo/bar/one/two'))
        self.assertTrue(blacklist.is_blacklisted('/foo/bar/one/two/three'))
    def test_portal_can_be_blacklisted(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        blacklist = IPathBlacklist(self.portal)

        # The portal is not blacklisted by default.
        self.assertFalse(blacklist.is_blacklisted(self.portal))

        # Blacklist the portal.
        config.appendPathToBlacklist('/'.join(self.portal.getPhysicalPath()))
        self.assertTrue(blacklist.is_blacklisted(self.portal))
    def test_portal_can_be_blacklisted(self):
        config = IConfig(self.portal)
        config.setPathBlacklist(PersistentList())
        blacklist = IPathBlacklist(self.portal)

        # The portal is not blacklisted by default.
        self.assertFalse(blacklist.is_blacklisted(self.portal))

        # Blacklist the portal.
        config.appendPathToBlacklist('/'.join(self.portal.getPhysicalPath()))
        self.assertTrue(blacklist.is_blacklisted(self.portal))
Пример #7
0
 def get_elements_for_cache(self, controller):
     bl = IPathBlacklist(self.context)
     for brain in self.context.portal_catalog(self.local_query()):
         if bl.is_blacklisted(brain):
             continue
         if controller.get_remote_item(brain=brain):
             yield {
                 'Title': brain.pretty_title_or_id(),
                 'path': brain.getPath(),
                 'review_state': self.context.translate(brain.review_state),
                 'workflow_name': brain.workflow_name,
                 'portal_type': brain.portal_type,
             }
Пример #8
0
    def __call__(self, event, no_response=False, msg=None):
        if IPreventPublishing.providedBy(self.context):
            return 'prevented'

        if publisher_jobs_are_disabled():
            return 'disabled'

        self.logger = getLogger()
        # is the object blacklisted?
        if IPathBlacklist(self.context).is_blacklisted():
            self.logger.warning(
                'Could not create move job for blacklisted object (%s at %s)' %
                (self.context.Title(), '/'.join(
                    self.context.getPhysicalPath())))
            if not no_response:
                return self.request.RESPONSE.redirect('./view')
            return False

        # This View should not be executed at the PloneSiteRoot
        if IPloneSiteRoot.providedBy(self.context):
            raise Exception('Not allowed on PloneSiteRoot')

        # get username
        user = self.context.portal_membership.getAuthenticatedMember()
        username = user.getUserName()

        # create Job
        portal = self.context.portal_url.getPortalObject()
        queue = IQueue(portal)

        additional_data = {
            'move_data': {
                'newName': event.newName,
                'newParent': get_site_relative_path(event.newParent),
                'newTitle': event.object.Title().decode('utf-8'),
                'oldName': event.oldName,
                'oldParent': get_site_relative_path(event.oldParent),
            }
        }

        queue.createJob('move',
                        self.context,
                        username,
                        additional_data=additional_data)
        self.logger.debug('Created "%s" Job for "%s" at %s' % (
            'move',
            self.context.Title(),
            '/'.join(self.context.getPhysicalPath()),
        ))

        # status message
        if msg is None:
            msg = _(u'Object move/rename action has been added to the queue.')

        IStatusMessage(self.request).addStatusMessage(msg, type='info')
        if not no_response:
            return self.request.RESPONSE.redirect('./view')
Пример #9
0
    def __call__(self, no_response=False, msg=None, recursive=True):
        if IPreventPublishing.providedBy(self.context):
            return 'prevented'

        if publisher_jobs_are_disabled():
            return 'disabled'

        self.logger = getLogger()
        # is the object blacklisted?
        if IPathBlacklist(self.context).is_blacklisted():
            self.logger.warning(
                'Could not create push job for blacklisted object (%s at %s)' %
                (self.context.Title(), '/'.join(
                    self.context.getPhysicalPath())))
            if not no_response:
                return self.request.RESPONSE.redirect('./view')
            return False

        event.notify(BeforePublishEvent(self.context))

        # mle: now its possible to execite this view on plonesiteroot
        # This View should not be executed at the PloneSiteRoot
        # if IPloneSiteRoot.providedBy(self.context):
        #    raise Exception('Not allowed on PloneSiteRoot')
        # get username
        user = self.context.portal_membership.getAuthenticatedMember()
        username = user.getUserName()

        # create Job
        portal = self.context.portal_url.getPortalObject()
        queue = IQueue(portal)
        queue.createJob('push', self.context, username)
        self.logger.debug('Created "%s" Job for "%s" at %s' % (
            'push',
            self.context.Title(),
            '/'.join(self.context.getPhysicalPath()),
        ))

        if recursive and base_hasattr(self.context, 'contentValues'):
            # Use contentValues for implicit ftw.trash compatibility.
            for obj in filter(belongs_to_parent, self.context.contentValues()):
                obj.restrictedTraverse('@@publisher.publish')(no_response=True,
                                                              msg=msg)

        # status message
        if msg is None:
            msg = _(u'This object has been added to the queue.')
        IStatusMessage(self.request).addStatusMessage(msg, type='info')
        if not no_response:
            return self.request.RESPONSE.redirect('./view')
Пример #10
0
    def __call__(self, no_response=False, msg=None):
        if IPreventPublishing.providedBy(self.context):
            return 'prevented'

        if publisher_jobs_are_disabled():
            return 'disabled'

        self.logger = getLogger()
        # is the object blacklisted?
        if IPathBlacklist(self.context).is_blacklisted():
            self.logger.warning('Could not create delete job for blacklisted '
                                'object (%s at %s)' %
                                (self.context.Title(), '/'.join(
                                    self.context.getPhysicalPath())))
            if not no_response:
                return self.request.RESPONSE.redirect('./view')
            return False

        # This view should not be executed at the PloneSiteRoot
        if IPloneSiteRoot.providedBy(self.context):
            raise Exception('Not allowed on PloneSiteRoot')

        # get username
        user = self.context.portal_membership.getAuthenticatedMember()
        username = user.getUserName()

        # create Job
        portal = self.context.portal_url.getPortalObject()
        queue = IQueue(portal)
        queue.createJob('delete', self.context, username)
        self.logger.debug('Created "%s" Job for "%s" at %s' % (
            'delete',
            self.context.Title(),
            '/'.join(self.context.getPhysicalPath()),
        ))

        # status message
        if msg is None:
            msg = _(u'This object will be deleted at the remote sites.')
        add_transaction_aware_status_message(self.request, msg, type='info')

        if not no_response:
            return self.request.RESPONSE.redirect('./view')
Пример #11
0
    def executeJob(self, job):
        """
        Executes a Job: sends the job to all available realms.
        @param job:     Job object to execute
        @type job:      Job
        """
        objTitle = job.objectTitle
        if isinstance(objTitle, unicode):
            objTitle = objTitle.encode('utf8')
        # is the object blacklisted?
        if IPathBlacklist(self.context).is_blacklisted(job.objectPath):
            self.logger.error('blacklisted: "%s" on "%s" (at %s | UID %s)' % (
                job.action,
                objTitle,
                job.objectPath,
                job.objectUID,
            ))
            self.error_logger.error(
                'blacklisted: "%s" on "%s" (at %s | UID %s)' % (
                    job.action,
                    objTitle,
                    job.objectPath,
                    job.objectUID,
                ))
            return False

        # get data from chache file
        state = None
        json = job.getData()
        self.logger.info('-' * 100)
        self.logger.info('executing "%s" on "%s" (at %s | UID %s)' % (
            job.action,
            objTitle,
            job.objectPath,
            job.objectUID,
        ))
        self.logger.info('... request data length: %i' % len(json))
        state_entries = {'date': datetime.now()}
        for realm in self.getActiveRealms():
            self.logger.info('... to realm %s' % (realm.url, ))
            # send data to each realm
            state = sendJsonToRealm(json, realm, 'publisher.receive')
            if isinstance(state, states.ErrorState):
                self.logger.error('... got result: %s' % state.toString())
                self.error_logger.error(
                    'executing "%s" on "%s" (at %s | UID %s)' % (
                        job.action,
                        objTitle,
                        job.objectPath,
                        job.objectUID,
                    ))
                self.error_logger.error('... got result: %s' %
                                        state.toString())
            else:
                self.logger.info('... got result: %s' % state.toString())
            state_entries[realm] = state
        job.executed_with_states(state_entries)

        # fire AfterPushEvent
        obj = uuidToObject(job.objectUID)
        if state is not None:
            event.notify(AfterPushEvent(obj, state, job))