Esempio n. 1
0
    def _post_process_tags(self):
        """Process possible after-effects of tags. This may include removing
        spreads, roles and such.

        Currently only spreads are supported."""
        # Do nothing if the config doesn't have TAG_REWRITE or it's empty.
        # In the latter case you get very serious side-effects that will wipe
        # all spreads on all entities due to entity.list_all_with_spread()'s
        # way of handling an empty argument.
        if not hasattr(abcconf, "TAG_REWRITE") or not abcconf.TAG_REWRITE:
            return
        # Access Entity objects directly.
        from Cerebrum.Entity import EntitySpread
        es = EntitySpread(self.db)
        for row in es.list_all_with_spread(
                [int(s) for s in abcconf.TAG_REWRITE.values()]):
            if int(row['entity_id']) in self._spreads:
                # Entity found, check spreads in database
                if (not int(row['spread']) in
                        self._spreads[int(row['entity_id'])]):
                    es.clear()
                    es.find(int(row['entity_id']))
                    es.delete_spread(int(row['spread']))
                    self.logger.info("Entity: '%d', removed spread '%s'" %
                                     (es.entity_id, int(row['spread'])))
            else:
                # Entity missing from file, remove all spreads
                es.clear()
                es.find(int(row['entity_id']))
                es.delete_spread(int(row['spread']))
                self.logger.info("Entity: '%d', removed spread '%s'" %
                                 (es.entity_id, int(row['spread'])))
Esempio n. 2
0
    def _post_process_tags(self):
        """Process possible after-effects of tags. This may include removing
        spreads, roles and such.

        Currently only spreads are supported."""
        # Do nothing if the config doesn't have TAG_REWRITE or it's empty.
        # In the latter case you get very serious side-effects that will wipe all
        # spreads on all entities due to entity.list_all_with_spread()'s way of
        # handling an empty argument.
        if not hasattr(abcconf, "TAG_REWRITE") or not abcconf.TAG_REWRITE:
            return
        # Access Entity objects directly.
        from Cerebrum.Entity import EntitySpread

        es = EntitySpread(self.db)
        for row in es.list_all_with_spread([int(s) for s in abcconf.TAG_REWRITE.values()]):
            if self._spreads.has_key(int(row["entity_id"])):
                # Entity found, check spreads in database
                if not int(row["spread"]) in self._spreads[int(row["entity_id"])]:
                    es.clear()
                    es.find(int(row["entity_id"]))
                    es.delete_spread(int(row["spread"]))
                    self.logger.info("Entity: '%d', removed spread '%s'" % (es.entity_id, int(row["spread"])))
            else:
                # Entity missing from file, remove all spreads
                es.clear()
                es.find(int(row["entity_id"]))
                es.delete_spread(int(row["spread"]))
                self.logger.info("Entity: '%d', removed spread '%s'" % (es.entity_id, int(row["spread"])))
Esempio n. 3
0
def delete_common(entity_id, db):
    """Remove information from the database common to whichever entity we are
    deleting.
    """
    # Remove spreads
    # Remove traits
    # Remove all permissions
    # Remove from all groups
    # Remove change_log entries
    const = Factory.get("Constants")()
    logger.debug("Deleting common parts for entity %s (id=%s)",
                 fetch_name(entity_id, db), entity_id)

    es = EntitySpread(db)
    es.find(entity_id)
    logger.debug("Deleting spreads: %s",
                 ", ".join(str(const.Spread(x["spread"]))
                           for x in es.get_spread()))
    for row in es.get_spread():
        es.delete_spread(row["spread"])

    et = EntityTrait(db)
    et.find(entity_id)
    logger.debug("Deleting traits: %s",
                 ", ".join(str(x) for x in et.get_traits()))
    # copy(), since delete_trait and get_traits work on the same dict. This is
    # so silly.
    for trait_code in et.get_traits().copy():
        et.delete_trait(trait_code)

    remove_target_permissions(entity_id, db)

    remove_permissions_on_target(entity_id, db)

    # Kill memberships
    group = Factory.get("Group")(db)
    for row in group.search(member_id=entity_id,
                            filter_expired=False):
        group.clear()
        group.find(row["group_id"])
        logger.debug("Removing %s as member of %s (id=%s)",
                     entity_id, group.group_name, group.entity_id)
        group.remove_member(entity_id)

    # Kill change_log entries
    logger.debug("Cleaning change_log of references to %s", entity_id)
    # Kill change_log entries (this includes requests linked to this entity)
    for row in db.get_log_events(subject_entity=entity_id):
        db.remove_log_event(row["change_id"])
Esempio n. 4
0
def delete_common(entity_id, db):
    """Remove information from the database common to whichever entity we are
    deleting.
    """
    # Remove spreads
    # Remove traits
    # Remove all permissions
    # Remove from all groups
    # Remove change_log entries
    const = Factory.get("Constants")()
    logger.debug("Deleting common parts for entity %s (id=%s)",
                 fetch_name(entity_id, db), entity_id)

    es = EntitySpread(db)
    es.find(entity_id)
    logger.debug(
        "Deleting spreads: %s",
        ", ".join(str(const.Spread(x["spread"])) for x in es.get_spread()))
    for row in es.get_spread():
        es.delete_spread(row["spread"])

    et = EntityTrait(db)
    et.find(entity_id)
    logger.debug("Deleting traits: %s",
                 ", ".join(str(x) for x in et.get_traits()))
    # copy(), since delete_trait and get_traits work on the same dict. This is
    # so silly.
    for trait_code in et.get_traits().copy():
        et.delete_trait(trait_code)

    remove_target_permissions(entity_id, db)

    remove_permissions_on_target(entity_id, db)

    # Kill memberships
    group = Factory.get("Group")(db)
    for row in group.search(member_id=entity_id, filter_expired=False):
        group.clear()
        group.find(row["group_id"])
        logger.debug("Removing %s as member of %s (id=%s)", entity_id,
                     group.group_name, group.entity_id)
        group.remove_member(entity_id)

    # Kill change_log entries
    logger.debug("Cleaning change_log of references to %s", entity_id)
    # Kill change_log entries (this includes requests linked to this entity)
    for row in db.get_log_events(subject_entity=entity_id):
        db.remove_log_event(row["change_id"])