Esempio n. 1
0
def onObjectMoved(ob, event):
    """
    Reindex paths only, don't update metadata.
    """
    if not (IObjectAddedEvent.providedBy(event) or
            IObjectRemovedEvent.providedBy(event)):
        notify(IndexingEvent(ob, 'path', False))
Esempio n. 2
0
def onObjectMoved(ob, event):
    """
    Reindex paths only, don't update metadata.
    """
    if not (IObjectAddedEvent.providedBy(event)
            or IObjectRemovedEvent.providedBy(event)):
        notify(IndexingEvent(ob, 'path', False))
def movedCustomUser(ob, event):
    """A CustomUser was moved.
    """
    if not IObjectRemovedEvent.providedBy(event):
        return
    if not IObjectAddedEvent.providedBy(event):
        removedCustomUser(ob, event)
def movedCustomUser(ob, event):
    """A CustomUser was moved.
    """
    if not IObjectRemovedEvent.providedBy(event):
        return
    if not IObjectAddedEvent.providedBy(event):
        removedCustomUser(ob, event)
Esempio n. 5
0
def onObjectMoved(ob, event):
    """
    Reindex paths only
    """
    if not (IObjectAddedEvent.providedBy(event) or
            IObjectRemovedEvent.providedBy(event)):
        notify(IndexingEvent(ob, idxs='path', triggered_by_zope_event=True))
Esempio n. 6
0
def onObjectMoved(ob, event):
    """
    Reindex paths only
    """
    if not (IObjectAddedEvent.providedBy(event)
            or IObjectRemovedEvent.providedBy(event)):
        notify(IndexingEvent(ob, idxs='path', triggered_by_zope_event=True))
def log_move(content, event):
    if content is event.object:
        if not (IObjectAddedEvent.providedBy(event) or
                IObjectRemovedEvent.providedBy(event)):
            detail = 'from %s/%s to %s/%s' % (
                get_path(event.oldParent), event.oldName,
                get_path(event.newParent), event.newName)
            LoggingEvent('move', content, detail).log()
def movedFile(ob, event):
    """A File was moved in the storage.

    """
    if not IObjectRemovedEvent.providedBy(event):
        #raise NotImplementedError # we don't support moving
        return
    if not IObjectAddedEvent.providedBy(event):
        removedFile(ob, event)
Esempio n. 9
0
def refireEventOnObjectAddOrMove(object, event):
    if not IObjectRemovedEvent.providedBy(event):
        oldguid = IGlobalIdentifier(object).getGUID()
        if oldguid is None:
            IGlobalIdentifier(object).create()
        else:
            # Refire in the case where an object already has a guid
            # but that guid has been removed from the guid table
            notify(GUIDEvent(object, oldguid, oldguid, False))
def movedFile(ob, event):
    """A File was moved in the storage.

    """
    if not IObjectRemovedEvent.providedBy(event):
        #raise NotImplementedError # we don't support moving
        return
    if not IObjectAddedEvent.providedBy(event):
        removedFile(ob, event)
Esempio n. 11
0
def refireEventOnObjectAddOrMove(object, event):
    if not IObjectRemovedEvent.providedBy(event):
        oldguid = IGlobalIdentifier(object).getGUID()
        if oldguid is None:
            IGlobalIdentifier(object).create()
        else:
            # Refire in the case where an object already has a guid
            # but that guid has been removed from the guid table
            notify(GUIDEvent(object, oldguid, oldguid, False))
def reconfigureChildRegistry(context, event):
    """ Upon moving or renaming an object, the registry must be reconfigured.

    Under the hood, this will re-register compoents with the correct paths
    to prevent errors.
    """
    # Ignore removal, and we already catch added events above
    if not IObjectRemovedEvent.providedBy(event) \
            and not IObjectAddedEvent.providedBy(event):
        enableChildRegistry(context, event)
Esempio n. 13
0
def reconfigureChildRegistry(context, event):
    """ Upon moving or renaming an object, the registry must be reconfigured.

    Under the hood, this will re-register compoents with the correct paths
    to prevent errors.
    """
    # Ignore removal, and we already catch added events above
    if not IObjectRemovedEvent.providedBy(event) \
            and not IObjectAddedEvent.providedBy(event):
        enableChildRegistry(context, event)
def patched___call__(self, context, rule, event):
    """ Workaround: don't add the rule in the list of executed ones,
    because together with plone.app.linkintegrity it causes to don't execute
    the rule"""
    exec_context = getattr(event, 'object', context)
    uid = _get_uid(exec_context)

    if (uid, rule.__name__, ) in self.executed:
        return False
    else:
        # workaround for ObjectRemovedEvent
        if not IObjectRemovedEvent.providedBy(event):
        #end of workaround
            self.executed.add((uid, rule.__name__, ))
        return True
def adaptPloneGroupDefinition(organization, event):
    """
        Manage an organization change
    """
    # zope.lifecycleevent.ObjectRemovedEvent : delete
    # zope.lifecycleevent.ObjectModifiedEvent : edit, rename
    # is the container who's modified at creation ?
    # bypass if we are removing the Plone Site
    if IContainerModifiedEvent.providedBy(event) or \
       event.object.portal_type == 'Plone Site':
        return
    # is the current organization a part of own organization
    organization_path = '/'.join(organization.getPhysicalPath())
    if not organization_path.startswith(
            get_own_organization_path(
                not_found_value='unfound')):  # can be unfound too
        return
    portal = getSite()
    # when an organization is removed (and its content), we check if it is used in plonegroup configuration
    registry_orgs = get_registry_organizations()
    if IObjectRemovedEvent.providedBy(
            event) and organization.UID() in registry_orgs:
        smi = IStatusMessage(organization.REQUEST)
        smi.addStatusMessage(_('You cannot delete this item !'), type='error')
        smi.addStatusMessage(_(
            "This organization or a contained organization is used in plonegroup "
            "configuration ! Remove it first from the configuration !"),
                             type='error')
        view_url = getMultiAdapter((organization, organization.REQUEST),
                                   name=u'plone_context_state').view_url()
        organization.REQUEST['RESPONSE'].redirect(view_url)
        raise Redirect(view_url)
        return
    pcat = portal.portal_catalog
    brains = pcat(portal_type='organization', path=organization_path)
    changes = False
    for brain in brains:
        orga = brain.getObject()
        orga_uid = orga.UID()
        if orga_uid in registry_orgs:
            if addOrModifyOrganizationGroups(orga, orga_uid):
                changes = True
    if changes:
        invalidate_sopgv_cache()
        invalidate_sov_cache()
        invalidate_soev_cache()
        invalidate_ssoev_cache()
Esempio n. 16
0
def at_handle_target_moved(obj, event):
    """
    when a target of a link is moved, or renamed we need to notify any
    objects that may be caching pointers
    """
    #@@ add more tests
    if IObjectRemovedEvent.providedBy(event):
        return

    refs = obj.getRefs(relationship=config.BACKLINK_RELATIONSHIP)
    path = '/'.join(obj.getPhysicalPath())
    for target in refs:
        for field in ISchema(target).fields():
            if IAmWickedField.providedBy(field):
                wicked = utils.getWicked(field, target)
                uid = IUID(obj)
                data = dict(path=path, icon=obj.getIcon(), uid=uid)
                wicked.cache.reset(uid, [data])
Esempio n. 17
0
def at_handle_target_moved(obj, event):
    """
    when a target of a link is moved, or renamed we need to notify any
    objects that may be caching pointers
    """
    #@@ add more tests
    if IObjectRemovedEvent.providedBy(event):
        return

    refs=obj.getRefs(relationship=config.BACKLINK_RELATIONSHIP)
    path = '/'.join(obj.getPhysicalPath())
    for target in refs:
        for field in ISchema(target).fields():
            if IAmWickedField.providedBy(field):
                wicked = utils.getWicked(field, target)
                uid = IUID(obj)
                data = dict(path=path,
                        icon=obj.getIcon(),
                        uid=uid)
                wicked.cache.reset(uid, [data])
Esempio n. 18
0
def content_moved(content, event):
    # We only do if the object is the target of the event.
    if event.object is not content:
        return
    # Don't create a link if it's an add or remove event.
    if IObjectRemovedEvent.providedBy(event) or \
            IObjectAddedEvent.providedBy(event):
        return
    # The content might not want redirect link.
    if INoPermanentRedirectLink.providedBy(content):
        return
    # The extension is not activated.
    if not content.service_extensions.is_installed("silva.app.redirectlink"):
        return
    container = event.oldParent
    factory = container.manage_addProduct['silva.app.redirectlink']
    factory.manage_addPermanentRedirectLink(event.oldName, content.get_title())
    link = getattr(container, event.oldName)
    link.set_target(content)
    binding = getUtility(IMetadataService).getMetadata(link)
    binding.setValues('silva-settings', {'hide_from_tocs': 'hide'})
Esempio n. 19
0
def onTreeSpanningComponentAfterAddOrMove(ob, event):
    if not IObjectRemovedEvent.providedBy(event):
        component = ob
        try:
            catalog = ob.getPhysicalRoot().zport.global_catalog
        except (KeyError, AttributeError):
            # Migrate script hasn't run yet; ignore indexing
            return
        device = component.device()
        if not device:
            # OS relation has been broken or doesn't exist yet; get by path
            path = component.getPrimaryPath()
            try:
                devpath = path[:path.index('devices') + 2]
                device = component.unrestrictedTraverse(devpath)
            except ValueError:
                # We've done our best. Give up.
                return
        if device:
            newpaths = devicePathsFromComponent(component)
            catalog.index_object_under_paths(device, newpaths)
Esempio n. 20
0
def patched___call__(self, context, rule, event):
    """ Workaround: don't add the rule in the list of executed ones,
    because together with plone.app.linkintegrity it causes to don't execute
    the rule"""
    exec_context = getattr(event, 'object', context)
    uid = _get_uid(exec_context)

    if (
            uid,
            rule.__name__,
    ) in self.executed:
        return False
    else:
        # workaround for ObjectRemovedEvent
        if not IObjectRemovedEvent.providedBy(event):
            #end of workaround
            self.executed.add((
                uid,
                rule.__name__,
            ))
        return True
Esempio n. 21
0
def onTreeSpanningComponentAfterAddOrMove(ob, event):
    if not IObjectRemovedEvent.providedBy(event):
        component = ob
        try:
            catalog = ob.getPhysicalRoot().zport.global_catalog
        except (KeyError, AttributeError):
            # Migrate script hasn't run yet; ignore indexing
            return
        device = component.device()
        if not device:
            # OS relation has been broken or doesn't exist yet; get by path
            path = component.getPrimaryPath()
            try:
                devpath = path[:path.index('devices')+2]
                device = component.unrestrictedTraverse(devpath)
            except ValueError:
                # We've done our best. Give up.
                return
        if device:
            newpaths = devicePathsFromComponent(component)
            catalog.index_object_under_paths(device, newpaths)
def onOpenStackHostAdded(obj, event):
    if not IObjectRemovedEvent.providedBy(event):
        # If a host is added to the system, we need to reindex the openstack
        # ports, since a portion of their integration key is based on the hosts'
        # manageIps.
        endpoint = obj.endpoint()

        log.info("A new host (%s) has been added to openstack endpoint %s - reindexing port components",
                 obj.titleOrId(), endpoint.titleOrId())

        results = ICatalogTool(endpoint).search(('ZenPacks.zenoss.OpenStackInfrastructure.Port.Port',))
        for brain in results:
            try:
                port = brain.getObject()
            except Exception, e:
                log.error("Error loading port %s: %s", brain, e)
                continue

            try:
                port.index_object()
                notify(IndexingEvent(port))
            except Exception, e:
                log.error("Error reindexing port %s: %s", port, e)
Esempio n. 23
0
def onTreeSpanningComponentAfterAddOrMove(ob, event):
    """ When tree spanning component is added or moved """
    if not IObjectRemovedEvent.providedBy(event):
        affected_objects = ObjectsAffectedBySpanningComponent(ob)
        affected_objects.index_affected_objects()
Esempio n. 24
0
def onTreeSpanningComponentAfterAddOrMove(ob, event):
    """ When tree spanning component is added or moved """
    if not IObjectRemovedEvent.providedBy(event):
        affected_objects = ObjectsAffectedBySpanningComponent(ob)
        affected_objects.index_affected_objects()
Esempio n. 25
0
def indexAfterAddOrMove(ob, event):
    """
    Multisubscriber for IIndexed + IObjectMovedEvent.
    """
    if not IObjectRemovedEvent.providedBy(event):
        ob.index_object()
Esempio n. 26
0
def onAfterObjectAddedOrMoved(ob, event):
    """ Subscriber for IObjectEventsSubscriber + IObjectMovedEvent """
    if not IObjectRemovedEvent.providedBy(event):
        if hasattr(ob, "after_object_added_or_moved_handler"):
            ob.after_object_added_or_moved_handler()
Esempio n. 27
0
def indexAfterAddOrMove(ob, event):
    """
    Multisubscriber for IIndexed + IObjectMovedEvent.
    """
    if not IObjectRemovedEvent.providedBy(event):
        ob.index_object()