Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_adduser2group.sas
Go to the documentation of this file.
1/**
2 @file mm_adduser2group.sas
3 @brief Adds a user to a group
4 @details Adds a user to a metadata group. The macro first checks whether the
5 user is in that group, and if not, the user is added.
6
7 Note that the macro does not check inherited group memberships - it looks at
8 direct members only.
9
10 Usage:
11
12 %mm_adduser2group(user=sasdemo
13 ,group=someGroup)
14
15
16 @param [in] user= the user name (not displayname)
17 @param [in] group= the group to which to add the user
18 @param [in] mdebug= (0) set to 1 to show debug info in log
19
20 <h4> Related Files </h4>
21 @li ms_adduser2group.sas
22
23 @version 9.3
24 @author Allan Bowe
25
26 @sasjslint {"maxLineLength": 101}
27**/
28
29%macro mm_adduser2group(user=
30 ,group=
31 ,mdebug=0
32);
33/* first, check if user is in group already exists */
34%local check uuri guri;
35%let check=ok;
36
37data _null_;
38 length uri type msg $256;
39 call missing(of _all_);
40 rc=metadata_getnobj("omsobj:Person?@Name='&user'",1,uri);
41 if rc<=0 then do;
42 msg="%str(WARN)ING: rc="!!cats(rc)!!" &user not found "!!
43 ", or there was an err reading the repository.";
44 call symputx('check',msg);
45 putlog msg;
46 stop;
47 end;
48 call symputx('uuri',scan(uri,2,'\'));
49
50 rc=metadata_getnobj("omsobj:IdentityGroup?@Name='&group'",1,uri);
51 if rc<=0 then do;
52 msg="%str(WARN)ING: rc="!!cats(rc)!!" &group not found "!!
53 ", or there was an err reading the repository.";
54 call symputx('check',msg);
55 putlog msg;
56 stop;
57 end;
58 call symputx('guri',scan(uri,2,'\'));
59
60 rc=metadata_getnobj("omsobj:Person?Person[@Name='&user'][IdentityGroups/*[@Name='&group']]",1,uri);
61 if rc=0 then do;
62 msg="%str(WARN)ING: rc="!!cats(rc)!!" &user already in &group";
63 call symputx('check',msg);
64 stop;
65 end;
66
67 if &mdebug ne 0 then put (_all_)(=);
68run;
69
70/* stop if issues */
71%if %quote(&check) ne %quote(ok) %then %do;
72 %put &check;
73 %return;
74%end;
75
76%if &syscc ge 4 %then %do;
77 %put %str(WARN)ING: SYSCC=&syscc, exiting &sysmacroname;
78 %return;
79%end;
80
81
82filename __us2grp temp;
83
84proc metadata in= "<UpdateMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata>
85 <Person Id='%nrstr(&uuri)'>
86 <IdentityGroups><IdentityGroup ObjRef='%nrstr(&guri)' />
87 </IdentityGroups></Person></Metadata>
88 <NS>SAS</NS><Flags>268435456</Flags></UpdateMetadata>"
89 out=__us2grp verbose;
90run;
91
92%if &mdebug ne 0 %then %do;
93 /* write the response to the log for debugging */
94 data _null_;
95 infile __us2grp lrecl=32767;
96 input;
97 put _infile_;
98 run;
99%end;
100
101filename __us2grp clear;
102
103%mend mm_adduser2group;