Example #1
0
 def indexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         c.catalog_object(self, url)
Example #2
0
    def reindexObjectSecurity(self, skip_self=False):
        # Update security information in all registered catalogs.
        if isFactoryContained(self):
            return
        at = getToolByName(self, TOOL_NAME, None)
        if at is None:
            return

        catalogs = [c for c in at.getCatalogsByType(self.meta_type)
                               if ICatalogTool.providedBy(c)]
        path = self.__url()

        for catalog in catalogs:
            for brain in catalog.unrestrictedSearchResults(path=path):
                brain_path = brain.getPath()
                if brain_path == path and skip_self:
                    continue
                # Get the object
                if hasattr(aq_base(brain), '_unrestrictedGetObject'):
                    try:
                        ob = brain._unrestrictedGetObject()
                    except (KeyError, AttributeError):
                        ob = None
                if ob is None:
                    log("reindexObjectSecurity: Cannot get %s from catalog" %
                        brain_path, level=WARNING)
                    continue

                # Recatalog with the same catalog uid.
                catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
                                        update_metadata=0, uid=brain_path)
Example #3
0
    def manage_afterAdd(self, item, container):
        # Get a UID
        # (Called when the object is created or moved.)

        if isFactoryContained(self):
            return
        isCopy = getattr(item, '_v_is_cp', None)
        # Before copying we take a copy of the references that are to be copied
        # on the new copy
        rfields = self.Schema().filterFields(type="reference", keepReferencesOnCopy=1)
        rrefs = {}
        if isCopy:
            # If the object is a copy of a existing object we
            # want to renew the UID, and drop all existing references
            # on the newly-created copy.
            for r in rfields:
                rrefs[r.getName()] = r.get(self)
            setattr(self, config.UUID_ATTR, None)
            self._delReferenceAnnotations()

        ct = getToolByName(container, config.REFERENCE_CATALOG, None)
        self._register(reference_manager=ct)
        self._updateCatalog(container)
        self._referenceApply('manage_afterAdd', item, container)
        # copy the references
        if isCopy:
            for r in rfields:
                r.set(self, rrefs[r.getName()])
    def reindexObjectSecurity(self, skip_self=False):
        """update security information in all registered catalogs.
        """
        if isFactoryContained(self):
            return
        at = getToolByName(self, TOOL_NAME, None)
        if at is None:
            return

        catalogs = [c for c in at.getCatalogsByType(self.meta_type)
                    if ICatalogTool.providedBy(c)]
        path = self.__url()

        for catalog in catalogs:
            for brain in catalog.unrestrictedSearchResults(path=path):
                brain_path = brain.getPath()
                if brain_path == path and skip_self:
                    continue
                # Get the object
                if hasattr(aq_base(brain), '_unrestrictedGetObject'):
                    try:
                        ob = brain._unrestrictedGetObject()
                    except (KeyError, AttributeError):
                        ob = None
                if ob is None:
                    log("reindexObjectSecurity: Cannot get %s from catalog" %
                        brain_path, level=WARNING)
                    continue

                # Recatalog with the same catalog uid.
                catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
                                      update_metadata=0, uid=brain_path)
Example #5
0
 def indexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         c.catalog_object(self, url)
Example #6
0
def egov_reindexObjectSecurity(self, skip_self=False):
    if isFactoryContained(self):
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:
        return

    catalogs = [c for c in at.getCatalogsByType(self.meta_type) if ICatalogTool.providedBy(c)]
    path = "/".join(self.getPhysicalPath())

    for catalog in catalogs:
        for brain in catalog.unrestrictedSearchResults(path=path):
            brain_path = brain.getPath()
            if brain_path == path and skip_self:
                continue

            # Get the object
            if hasattr(aq_base(brain), "_unrestrictedGetObject"):
                ob = brain._unrestrictedGetObject()
            else:
                # BBB: Zope 2.7
                ob = self.unrestrictedTraverse(brain_path, None)
            if ob is None:
                # BBB: Ignore old references to deleted objects.
                # Can happen only in Zope 2.7, or when using
                # catalog-getObject-raises off in Zope 2.8
                log("reindexObjectSecurity: Cannot get %s from catalog" % brain_path, level=WARNING)
                continue
            # Also append our new index
            indexes = list(self._cmf_security_indexes)
            indexes.append("get_local_roles")
            indexes.append("isLocalRoleAcquired")
            # Recatalog with the same catalog uid.
            catalog.reindexObject(ob, idxs=tuple(indexes), update_metadata=1, uid=brain_path)
def permissionmanager_reindexObjectSecurity(self, skip_self=False):
    # Execute standard object reindexing.
    self._old_reindexObjectSecurity(skip_self=skip_self)

    # The standard indexing does not update catalog metadata.
    # We need to do that because we introduce security relevant
    # catalog metadata in this package.

    # In order to do that, we reindex the fast index "getId" of the
    # current context, so that we can use `update_metadata=True`.
    # We do not do that recursive because the metadata values
    # are non-recursive.
    if isFactoryContained(self):
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:
        return

    catalogs = [
        catalog for catalog in at.getCatalogsByType(self.meta_type)
        if ICatalogTool.providedBy(catalog)
    ]

    for catalog in catalogs:
        catalog.reindexObject(self, idxs=['getId'], update_metadata=True)
Example #8
0
 def unindexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         if c._catalog.uids.get(url, None) is not None:
             c.uncatalog_object(url)
Example #9
0
 def unindexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         if c._catalog.uids.get(url, None) is not None:
             c.uncatalog_object(url)
def at_reindexObjectSecurity(self):
    if isFactoryContained(self):  # pragma: no cover
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:  # pragma: no cover
        return
    catalogs = [c for c in at.getCatalogsByType(self.meta_type) if ICatalogTool.providedBy(c)]
    for catalog in catalogs:
        _reindex(self, catalog)
Example #11
0
def unindexObject(self):
    if isFactoryContained(self):
        return
    catalogs = self.getCatalogs()
    url = '/'.join(self.getPhysicalPath())
    for catalog in catalogs:
        # because we need the actual object for us to uncatalog...
        if type(aq_base(catalog)) in patched:
            catalog.uncatalog_object(url, self)
        elif catalog._catalog.uids.get(url, None) is not None:
            catalog.uncatalog_object(url)
Example #12
0
 def indexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         if c.id == 'portal_catalog':
             # use catalog tool queuing system
             c.indexObject(self)
             continue
         c.catalog_object(self, url)
Example #13
0
 def _uncatalogUID(self, aq, uc=None):
     if isFactoryContained(self):
         return
     if not uc:
         uc = getToolByName(self, config.UID_CATALOG)
     url = self._getURL()
     # XXX This is an ugly workaround. This method shouldn't be called
     # twice for an object in the first place, so we don't have to check
     # if it is still cataloged.
     rid = uc.getrid(url)
     if rid is not None:
         uc.uncatalog_object(url)
Example #14
0
 def unindexObject(self):
     if isFactoryContained(self):
         return
     catalogs = self.getCatalogs()
     url = self.__url()
     for c in catalogs:
         if c.id == 'portal_catalog':
             # use catalog tool queuing system
             c.unindexObject(self)
             continue
         if c._catalog.uids.get(url, None) is not None:
             c.uncatalog_object(url)
def at_reindexObjectSecurity(self):
    if isFactoryContained(self):  # pragma: no cover
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:  # pragma: no cover
        return
    catalogs = [
        c for c in at.getCatalogsByType(self.meta_type)
        if ICatalogTool.providedBy(c)
    ]
    for catalog in catalogs:
        _reindex(self, catalog)
Example #16
0
def ftw_solr_CatalogMultiplex_reindexObjectSecurity(self, skip_self=False):
    """update security information in all registered catalogs.
    """
    if isFactoryContained(self):
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:
        return

    catalogs = [c for c in at.getCatalogsByType(self.meta_type)
                if ICatalogTool.providedBy(c)]

    for catalog in catalogs:
        recursive_index_security(catalog, self)
Example #17
0
    def reindexObject(self, idxs=None):
        # Update indexes of this object in all registered catalogs.
        #
        # Catalogs are registered per 'meta_type' in archetypes tool.
        #
        # 'idxs' are a list of index names. If this list is given only the given
        # indexes are refreshed. If a index does not exist in catalog its
        # silently ignored.
        if idxs is None:
            idxs = []
        if isFactoryContained(self):
            return
        if idxs == [] and shasattr(self, 'notifyModified'):
            # Archetypes default setup has this defined in ExtensibleMetadata
            # mixin. note: this refreshes the 'etag ' too.
            self.notifyModified()

        self.http__refreshEtag()

        catalogs = self.getCatalogs()
        if not catalogs:
            return

        url = self.__url()

        for c in catalogs:
            if c is not None:
                if c.id == 'portal_catalog':
                    # use catalog tool queuing system
                    c.reindexObject(self, idxs=idxs)
                    continue
                # We want the intersection of the catalogs idxs
                # and the incoming list.
                lst = idxs
                indexes = c.indexes()
                if idxs:
                    lst = [i for i in idxs if i in indexes]
                c.catalog_object(self, url, idxs=lst)

        # We only make this call if idxs is not passed.
        #
        # manage_afterAdd/manage_beforeDelete from Referenceable take
        # care of most of the issues, but some places still expect to
        # call reindexObject and have the uid_catalog updated.
        # TODO: fix this so we can remove the following lines.
        if not idxs:
            if isinstance(self, Referenceable):
                isCopy = getattr(self, '_v_is_cp', None)
                if isCopy is None:
                    self._catalogUID(self)
Example #18
0
def ftw_solr_CatalogMultiplex_reindexObjectSecurity(self, skip_self=False):
    """update security information in all registered catalogs.
    """
    if isFactoryContained(self):
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:
        return

    catalogs = [c for c in at.getCatalogsByType(self.meta_type)
                if ICatalogTool.providedBy(c)]

    for catalog in catalogs:
        recursive_index_security(catalog, self)
    def reindexObject(self, idxs=None):
        """update indexes of this object in all registered catalogs.

        Catalogs are registered per 'meta_type' in archetypes tool.

        'idxs' are a list of index names. If this list is given only the given
        indexes are refreshed. If a index does not exist in catalog its
        silently ignored.
        """
        if idxs is None:
            idxs = []
        if isFactoryContained(self):
            return
        if idxs == [] and shasattr(self, 'notifyModified'):
            # Archetypes default setup has this defined in ExtensibleMetadata
            # mixin. note: this refreshes the 'etag ' too.
            self.notifyModified()

        self.http__refreshEtag()

        catalogs = self.getCatalogs()
        if not catalogs:
            return

        url = self.__url()

        for c in catalogs:
            if c is not None:
                # We want the intersection of the catalogs idxs
                # and the incoming list.
                lst = idxs
                indexes = c.indexes()
                if idxs:
                    lst = [i for i in idxs if i in indexes]
                c.catalog_object(self, url, idxs=lst)

        # We only make this call if idxs is not passed.
        #
        # manage_afterAdd/manage_beforeDelete from Referenceable take
        # care of most of the issues, but some places still expect to
        # call reindexObject and have the uid_catalog updated.
        # TODO: fix this so we can remove the following lines.
        if not idxs:
            if isinstance(self, Referenceable):
                isCopy = getattr(self, '_v_is_cp', None)
                if isCopy is None:
                    self._catalogUID(self)
Example #20
0
def egov_reindexObjectSecurity(self, skip_self=False):
    if isFactoryContained(self):
        return
    at = getToolByName(self, TOOL_NAME, None)
    if at is None:
        return

    catalogs = [
        c for c in at.getCatalogsByType(self.meta_type)
        if ICatalogTool.providedBy(c)
    ]
    path = '/'.join(self.getPhysicalPath())

    for catalog in catalogs:
        for brain in catalog.unrestrictedSearchResults(path=path):
            brain_path = brain.getPath()
            if brain_path == path and skip_self:
                continue

            # Get the object
            if hasattr(aq_base(brain), '_unrestrictedGetObject'):
                ob = brain._unrestrictedGetObject()
            else:
                # BBB: Zope 2.7
                ob = self.unrestrictedTraverse(brain_path, None)
            if ob is None:
                # BBB: Ignore old references to deleted objects.
                # Can happen only in Zope 2.7, or when using
                # catalog-getObject-raises off in Zope 2.8
                log("reindexObjectSecurity: Cannot get %s from catalog" %
                    brain_path,
                    level=WARNING)
                continue
            # Also append our new index
            indexes = list(self._cmf_security_indexes)
            indexes.append('get_local_roles')
            indexes.append('isLocalRoleAcquired')
            # Recatalog with the same catalog uid.
            catalog.reindexObject(ob,
                                  idxs=tuple(indexes),
                                  update_metadata=1,
                                  uid=brain_path)
Example #21
0
 def _uncatalogRefs(self, aq, uc=None, rc=None):
     if isFactoryContained(self):
         return
     annotations = self._getReferenceAnnotations()
     if annotations:
         if not uc:
             uc = getToolByName(self, config.UID_CATALOG)
         if not rc:
             rc = getToolByName(self, config.REFERENCE_CATALOG)
         for ref in annotations.objectValues():
             url = getRelURL(uc, ref.getPhysicalPath())
             # XXX This is an ugly workaround. This method shouldn't be
             # called twice for an object in the first place, so we don't
             # have to check if it is still cataloged.
             uc_rid = uc.getrid(url)
             if uc_rid is not None:
                 uc.uncatalog_object(url)
             rc_rid = rc.getrid(url)
             if rc_rid is not None:
                 rc.uncatalog_object(url)
    def reindexObjectSecurity(self, skip_self=False):
        """update security information in all registered catalogs.
        """
        if isFactoryContained(self):
            return
        at = getToolByName(self, TOOL_NAME, None)
        if at is None:
            return

        catalogs = [
            c for c in at.getCatalogsByType(self.meta_type)
            if ICatalogTool.providedBy(c)
        ]
        path = self.__url()

        for catalog in catalogs:
            for brain in catalog.unrestrictedSearchResults(path=path):
                brain_path = brain.getPath()
                if brain_path == path and skip_self:
                    continue

                # Get the object
                if hasattr(aq_base(brain), '_unrestrictedGetObject'):
                    ob = brain._unrestrictedGetObject()
                else:
                    # BBB: Zope 2.7
                    ob = self.unrestrictedTraverse(brain_path, None)
                if ob is None:
                    # BBB: Ignore old references to deleted objects.
                    # Can happen only in Zope 2.7, or when using
                    # catalog-getObject-raises off in Zope 2.8
                    log("reindexObjectSecurity: Cannot get %s from catalog" %
                        brain_path,
                        level=WARNING)
                    continue

                # Recatalog with the same catalog uid.
                catalog.reindexObject(ob,
                                      idxs=self._cmf_security_indexes,
                                      update_metadata=0,
                                      uid=brain_path)
    def reindexObjectSecurity(self, skip_self=False):
        """update security information in all registered catalogs.
        """
        if isFactoryContained(self):
            return
        at = getToolByName(self, TOOL_NAME, None)
        if at is None:
            return

        catalogs = [c for c in at.getCatalogsByType(self.meta_type)
                               if ICatalogTool.providedBy(c)]
        path = self.__url()

        for catalog in catalogs:
            for brain in catalog.unrestrictedSearchResults(path=path):
                brain_path = brain.getPath()
                if brain_path == path and skip_self:
                    continue

                # Get the object
                if hasattr(aq_base(brain), '_unrestrictedGetObject'):
                    ob = brain._unrestrictedGetObject()
                else:
                    # BBB: Zope 2.7
                    ob = self.unrestrictedTraverse(brain_path, None)
                if ob is None:
                    # BBB: Ignore old references to deleted objects.
                    # Can happen only in Zope 2.7, or when using
                    # catalog-getObject-raises off in Zope 2.8
                    log("reindexObjectSecurity: Cannot get %s from catalog" %
                        brain_path, level=WARNING)
                    continue

                # Recatalog with the same catalog uid.
                catalog.reindexObject(ob, idxs=self._cmf_security_indexes,
                                        update_metadata=0, uid=brain_path)