Ejemplo n.º 1
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"])
Ejemplo n.º 2
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"])
Ejemplo n.º 3
0
def get_entity_spreads(db, entity_id):
    """ Lookup any entity spreads on an entity.

    entity_id -> [<spread_code_str>, ...]
    """
    # TODO: Include spreads in change_params, so that we don't have to look
    #       them up?
    constants = Factory.get("Constants")(db)
    entity = EntitySpread(db)
    try:
        entity.find(int(entity_id))
        return [six.text_type(constants.Spread(s['spread']))
                for s in entity.get_spread()]
    except (NotFoundError, ValueError):
        pass
    return list()
Ejemplo n.º 4
0
def get_entity_spreads(db, entity_id):
    """ Lookup any entity spreads on an entity.

    entity_id -> [<spread_code_str>, ...]
    """
    # TODO: Include spreads in change_params, so that we don't have to look
    #       them up?
    constants = Factory.get("Constants")(db)
    entity = EntitySpread(db)
    try:
        entity.find(int(entity_id))
        return [six.text_type(constants.Spread(s['spread']))
                for s in entity.get_spread()]
    except (NotFoundError, ValueError):
        pass
    return list()