ad_get_group_id

one of the documented procedures in this installation of the ACS
Usage:
ad_get_group_id
What it does:
Returns the group_id cookie value. Returns 0 if the group_id cookie is missing, if the user is not logged in, or if the user is not a member of the group.
Defined in: /web/philip/packages/acs-core/user-groups-procs.tcl

Source code:


    # 1 verifies the user_id cookie 
    # 2 gets the group_id cookie
    # 3 verifies that the user_id is mapped to group_id 

    ns_share ad_group_map_cache

    set user_id [ad_verify_and_get_user_id]
    if { $user_id == 0 } {
	return 0
    }
    set headers [ns_conn headers]
    set cookie [ns_set get $headers Cookie]
    if { [regexp {ad_group_id=([^;]+)} $cookie {} group_id] } {
	if { [info exists ad_group_map_cache($user_id)] } {
	    # there exists a cached $user_id to $group_id mapping
	    if { [string compare $group_id $ad_group_map_cache($user_id)] == 0 } {
		return $group_id
	    } 
	}
	# we continue and hit db even if there was a cached group_id (but 
	# it didn't match) because the user might have just logged into 
	# a different group

	set db [ns_db gethandle subquery]

	if {
	    [database_to_tcl_string $db "select ad_group_member_p($user_id, $group_id) from dual"] == "t"
	} {
	    set ad_group_map_cache($user_id) $group_id
	    ns_db releasehandle $db
	    return $group_id
	} else {
	    ns_db releasehandle $db
	    # user is not in the group
	    return 0
	}
    } else {
	return 0
    }


philg@mit.edu