Main Tables Views Materialized Views Indexes Constraints Triggers Procedures Functions Packages Sequences Java Sources Jobs Sanity Check Index DDL scrips
Package source Package body source

RHN_USER

DDL script

Package source

Legend: comment string keyword reserved word operator
     1: package rhn_user
     2: is
     3: 	version varchar2(100) := '';
     4: 
     5:     function check_role(user_id_in in number, role_in in varchar2) return number;
     6:     PRAGMA RESTRICT_REFERENCES(check_role, WNDS, RNPS, WNPS);
     7: 
     8:     function check_role_implied(user_id_in in number, role_in in varchar2) return number;
     9:     PRAGMA RESTRICT_REFERENCES(check_role_implied, WNDS, RNPS, WNPS);
    10: 
    11:     function get_org_id(user_id_in in number) return number;
    12:     PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
    13: 
    14: 	procedure add_servergroup_perm(
    15: 		user_id_in in number,
    16: 		server_group_id_in in number
    17: 	);
    18: 
    19: 	procedure remove_servergroup_perm(
    20: 		user_id_in in number,
    21: 		server_group_id_in in number
    22: 	);
    23: 
    24: 	procedure add_to_usergroup(
    25: 		user_id_in in number,
    26: 		user_group_id_in in number
    27: 	);
    28: 
    29: 	procedure remove_from_usergroup(
    30: 		user_id_in in number,
    31: 		user_group_id_in in number
    32: 	);
    33: 
    34: 	function role_names (user_id_in in number) return varchar2;
    35: 
    36: end rhn_user;

Package body source

Legend: comment string keyword reserved word operator
     1: package body rhn_user
     2: is
     3: 	body_version varchar2(100) := '';
     4: 
     5:     function check_role(user_id_in in number, role_in in varchar2)
     6:     return number
     7:     is
     8:     	throwaway number;
     9:     begin
    10:     	-- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
    11: 	select 1 into throwaway
    12: 	  from rhnUserGroupType UGT,
    13: 	       rhnUserGroup UG,
    14: 	       rhnUserGroupMembers UGM
    15: 	 where UGM.user_id = user_id_in
    16: 	   and UGM.user_group_id = UG.id
    17: 	   and UG.group_type = UGT.id
    18: 	   and UGT.label = role_in;
    19: 
    20: 	return 1;
    21:     exception
    22:     	when no_data_found
    23: 	    then
    24: 	    return 0;
    25:     end check_role;
    26: 
    27:     function check_role_implied(user_id_in in number, role_in in varchar2)
    28:     return number
    29:     is
    30:     	throwaway number;
    31:     begin
    32:     	-- if the user directly has the role, they win
    33:     	if rhn_user.check_role(user_id_in, role_in) = 1
    34: 	then
    35: 	    return 1;
    36:     	end if;
    37: 
    38: 	-- config_admin and channel_admin are automatically implied for org admins
    39: 	if role_in = 'config_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
    40: 	then
    41: 	    return 1;
    42: 	end if;
    43: 
    44: 	if role_in = 'channel_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
    45: 	then
    46: 	    return 1;
    47: 	end if;
    48: 
    49: 	return 0;
    50:     end check_role_implied;
    51: 
    52:     function get_org_id(user_id_in in number)
    53:     return number
    54:     is
    55:     	org_id_out number;
    56:     begin
    57:     	select org_id into org_id_out
    58: 	  from web_contact
    59: 	 where id = user_id_in;
    60: 
    61: 	return org_id_out;
    62:     end get_org_id;
    63: 
    64: 	procedure add_servergroup_perm(
    65: 		user_id_in in number,
    66: 		server_group_id_in in number
    67: 	) is
    68: 		cursor	orgs_match is
    69: 			select	1
    70: 			from	rhnServerGroup sg,
    71: 					web_contact u
    72: 			where	u.id = user_id_in
    73: 				and sg.id = server_group_id_in
    74: 				and sg.org_id = u.org_id;
    75: 	begin
    76: 		for okay in orgs_match loop
    77: 			insert into rhnUserServerGroupPerms(user_id, server_group_id)
    78: 				values (user_id_in, server_group_id_in);
    79: 			rhn_cache.update_perms_for_user(user_id_in);
    80: 			return;
    81: 		end loop;
    82: 		rhn_exception.raise_exception('usgp_different_orgs');
    83: 	exception when dup_val_on_index then
    84: 		rhn_exception.raise_exception('usgp_already_allowed');
    85: 	end add_servergroup_perm;
    86: 
    87: 	procedure remove_servergroup_perm(
    88: 		user_id_in in number,
    89: 		server_group_id_in in number
    90: 	) is
    91: 		cursor perms is
    92: 			select	1
    93: 			from	rhnUserServerGroupPerms
    94: 			where	user_id = user_id_in
    95: 				and server_group_id = server_group_id_in;
    96: 	begin
    97: 		for perm in perms loop
    98: 			delete from rhnUserServerGroupPerms
    99: 				where	user_id = user_id_in
   100: 					and server_group_id = server_group_id_in;
   101: 			rhn_cache.update_perms_for_user(user_id_in);
   102: 			return;
   103: 		end loop;
   104: 		rhn_exception.raise_exception('usgp_not_allowed');
   105: 	end remove_servergroup_perm;
   106: 
   107: 	procedure add_to_usergroup(
   108: 		user_id_in in number,
   109: 		user_group_id_in in number
   110: 	) is
   111: 		cursor perm_granting_usergroups is
   112: 			select	user_group_id_in
   113: 			from	rhnUserGroup		ug,
   114: 					rhnUserGroupType	ugt
   115: 			where	ugt.label in ('org_admin') -- and server_group_admin ?
   116: 				and ug.id = user_group_id_in
   117: 				and ug.group_type = ugt.id;
   118: 	begin
   119: 		insert into rhnUserGroupMembers(user_id, user_group_id)
   120: 			values (user_id_in, user_group_id_in);
   121: 
   122: 		for ug in perm_granting_usergroups loop
   123: 			rhn_cache.update_perms_for_user(user_id_in);
   124: 			return;
   125: 		end loop;
   126: 	end add_to_usergroup;
   127: 
   128: 	procedure remove_from_usergroup(
   129: 		user_id_in in number,
   130: 		user_group_id_in in number
   131: 	) is
   132: 		cursor perm_granting_usergroups is
   133: 			select	label
   134: 			from	rhnUserGroupType	ugt,
   135: 					rhnUserGroupMembers	ugm,
   136: 					rhnUserGroup		ug
   137: 			where	1=1
   138: 				and ug.id = user_group_id_in
   139: 				and ugm.user_group_id = user_group_id_in
   140: 				and ug.group_type = ugt.id
   141: 				and ugm.user_id = user_id_in;
   142: 	begin
   143: 		-- we only do anything if you're really in the group, because
   144: 		-- testing is significantly cheaper than rebuilding the user's
   145: 		-- cache for no reason.
   146: 		for ug in perm_granting_usergroups loop
   147: 			delete from rhnUserGroupMembers
   148: 				where	user_id = user_id_in
   149: 					and user_group_id = user_group_id_in;
   150: 			if ug.label in ('org_admin') then
   151: 				rhn_cache.update_perms_for_user(user_id_in);
   152: 			end if;
   153: 		end loop;
   154: 	end remove_from_usergroup;
   155: 
   156: 	function role_names (user_id_in in number)
   157: 	return varchar2
   158: 	is
   159: 		tmp varchar2(4000);
   160: 	begin
   161: 		for rec in (
   162: 			select type_name
   163: 			from rhnUserTypeBase
   164: 			where user_id = user_id_in
   165: 			order by type_id
   166: 			) loop
   167: 			if tmp is null then
   168: 				tmp := rec.type_name;
   169: 			else
   170: 				tmp := tmp || ', ' || rec.type_name;
   171: 			end if;
   172: 		end loop;
   173: 		return tmp;
   174: 	end;
   175: 
   176: end rhn_user;