Loading...
Searching...
No Matches
mm_getgroups.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Creates dataset with all groups or just those for a particular user
4 @details Provide a metadata user to get groups for just that user, or leave
5 blank to return all groups.
6 Usage:
7
8 - all groups: `%mm_getGroups()`
9
10 - all groups for a particular user: `%mm_getgroups(user=&sysuserid)`
11
12 @param [in] user= the metadata user to return groups for. Leave blank for all
13 groups.
14 @param [in] repo= (foundation) the metadata repository that contains the
15 user/group information
16 @param [in] mDebug= (0) set to 1 to show debug messages in the log
17 @param [out] outds= (work.mm_getgroups) The dataset to create that contains
18 the list of groups
19
20 @returns outds contains GROUPURI, GROUPNAME and GROUPDESC as character
21 columns of length 256 bytes. An unknown user or a user with no groups
22 returns zero rows.
23
24 <h4> SAS Macros </h4>
25 @li mddl_getgroups.sas
26 @li mf_getuniquename.sas
27
28 @version 9.2
29 @author Allan Bowe
30
31**/
32
33%macro mm_getgroups(
34 user=
35 ,outds=work.mm_getGroups
36 ,repo=foundation
37 ,mDebug=0
38)/*/STORE SOURCE*/;
39
40%local mD oldrepo schema;
41%let oldrepo=%sysfunc(getoption(metarepository));
42%if &mDebug=1 %then %let mD=;
43%else %let mD=%str(*);
44%&mD.put Executing mm_getGroups.sas;
45%&mD.put _local_;
46
47/* on some sites, user / group info is in a different metadata repo to the
48 default */
49%if &oldrepo ne &repo %then %do;
50 options metarepository=&repo;
51%end;
52%let schema=work.%mf_getuniquename(prefix=mm_groups_);
53%mddl_getgroups(&schema)
54
55%if %length(&user)=0 %then %do;
56 data &outds;
57 if 0 then set &schema;
58 length group_or_role $256;
59 keep groupuri groupname groupdesc;
60 call missing(of _all_);
61 i+1;
62 do while
63 (metadata_getnobj("omsobj:IdentityGroup?@Id contains '.'",i,groupuri)>0);
64 rc=metadata_getattr(groupuri, "Name", groupname);
65 rc=metadata_getattr(groupuri, "Desc", groupdesc);
66 rc=metadata_getattr(groupuri,"PublicType",group_or_role);
67 if Group_or_Role = 'UserGroup' then output;
68 i+1;
69 end;
70 stop;
71 run;
72%end;
73%else %do;
74 data &outds;
75 if 0 then set &schema;
76 length uri group_or_role $256;
77 keep groupuri groupname groupdesc;
78 call missing(of _all_);
79 rc=metadata_getnobj("omsobj:Person?@Name='&user'",1,uri);
80 if rc<=0 then do;
81 putlog "%str(WARN)ING: rc=" rc "&user not found "
82 ", or there was an issue reading the repository.";
83 stop;
84 end;
85 a=1;
86 grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
87 if grpassn in (-3,-4) then do;
88 putlog "%str(WARN)ING: No metadata groups found for &user";
89 end;
90 else do while (grpassn > 0);
91 rc=metadata_getattr(groupuri, "Name", groupname);
92 rc=metadata_getattr(groupuri, "Desc", groupdesc);
93 a+1;
94 rc=metadata_getattr(groupuri,"PublicType",group_or_role);
95 if Group_or_Role = 'UserGroup' then output;
96 grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
97 end;
98 stop;
99 run;
100%end;
101
102%if &oldrepo ne &repo %then %do;
103 options metarepository=&oldrepo;
104%end;
105
106%mend mm_getgroups;