acs_user::demote_user (public)

 acs_user::demote_user [ -user_id user_id ] [ -delete_portrait ]

Defined in packages/acs-tcl/tcl/community-core-procs.tcl

Demotes an ACS user to a person/party. This will fail if other tables have content referencing the users table. It is probably best for tables created in other packages to reference persons, parties, or acs_objects instead. This proc could be extended with an option to find all referenced tables and remove rows referencing this user.

Switches:
-user_id (optional)
the user_id in the acs system that should be demoted.
-delete_portrait (optional, boolean)
Delete the portrait of the user
Error:
An error is thrown if user_id is not in the users table.

Partial Call Graph (max 5 caller/called nodes):
%3 test_demote_promote_a_user demote_promote_a_user (test acs-tcl) acs_user::demote_user acs_user::demote_user test_demote_promote_a_user->acs_user::demote_user acs_user::erase_portrait acs_user::erase_portrait (public) acs_user::demote_user->acs_user::erase_portrait acs_user::flush_cache acs_user::flush_cache (public) acs_user::demote_user->acs_user::flush_cache acs_user::get acs_user::get (public) acs_user::demote_user->acs_user::get db_dml db_dml (public) acs_user::demote_user->db_dml db_multirow db_multirow (public) acs_user::demote_user->db_multirow

Testcases:
demote_promote_a_user
Source code:
    #
    # Make sure this user exists
    #
    set user_info [acs_user::get -user_id $user_id]
    if { [llength $user_info] == 0 } {
        return -error "This user does not exist."
    }

    # revoke permissions
    db_dml noxql {
       DELETE FROM acs_permissions
       WHERE grantee_id = :user_id
    }

    db_multirow -local rels noxql {
        SELECT rel_id
        FROM acs_rels
        WHERE rel_type = 'membership_rel'
          AND object_id_two = :user_id
    }
    template::multirow -local foreach rels {
        if { ![relation_remove $rel_id] } {
            # didn't delete anything - error?
        }
    }

    db_dml noxql {
        DELETE FROM user_preferences
        WHERE user_id = :user_id
    }
    db_dml noxql {
        DELETE FROM users
        WHERE user_id = :user_id
    }

    #
    # Update object type.
    #
    db_dml update_object_type {
        UPDATE acs_objects
        SET    object_type = 'person'
        WHERE  object_id = :user_id
    }


    #
    # Remove the portrait on request.
    #
    if {$delete_portrait_p} {
        acs_user::erase_portrait -user_id $user_id
    }

    #
    # Always flush the cache. It should not be necessary to flush the
    # person_info cache, since the "person" is still around.
    #
    acs_user::flush_cache -user_id $user_id

    #
    # All user's direct permissions have been revoked, flush the
    # permissions cache as well.
    #
    permission::cache_flush -party_id $user_id

    return
Generic XQL file:
packages/acs-tcl/tcl/community-core-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/community-core-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/community-core-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: