Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
ms_adduser2group.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Adds a user to a group on SASjs Server
4 @details Adds a user to a group based on userid and groupid. Both user and
5 group must already exist.
6
7 Examples:
8
9 %ms_adduser2group(uid=1,gid=1)
10
11
12 @param [in] uid= (0) The User ID to be added
13 @param [in] gid= (0) The Group ID to contain the new user
14 @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
15 @param [out] outds= (work.ms_adduser2group) This output dataset will contain
16 the new list of group members, eg:
17|DISPLAYNAME:$18.|USERNAME:$10.|ID:best.|
18|---|---|---|
19|`Super Admin `|`secretuser `|`1`|
20|`Sabir Hassan`|`sabir`|`2`|
21|`Mihajlo Medjedovic `|`mihajlo `|`3`|
22|`Ivor Townsend `|`ivor `|`4`|
23|`New User `|`newuser `|`5`|
24
25
26
27 <h4> SAS Macros </h4>
28 @li mf_getuniquefileref.sas
29 @li mf_getuniquelibref.sas
30 @li mp_abort.sas
31
32 <h4> Related Files </h4>
33 @li ms_creategroup.sas
34 @li ms_createuser.sas
35
36**/
37
38%macro ms_adduser2group(uid=0
39 ,gid=0
40 ,outds=work.ms_adduser2group
41 ,mdebug=0
42 );
43
44%mp_abort(
45 iftrue=(&syscc ne 0)
46 ,mac=ms_adduser2group.sas
47 ,msg=%str(syscc=&syscc on macro entry)
48)
49
50%local fref0 fref1 fref2 libref optval rc msg;
51%let fref0=%mf_getuniquefileref();
52%let fref1=%mf_getuniquefileref();
53%let libref=%mf_getuniquelibref();
54
55/* avoid sending bom marker to API */
56%let optval=%sysfunc(getoption(bomfile));
57options nobomfile;
58
59data _null_;
60 file &fref0 lrecl=1000;
61 infile "&_sasjs_tokenfile" lrecl=1000;
62 input;
63 if _n_=1 then put "accept: application/json";
64 put _infile_;
65run;
66
67%if &mdebug=1 %then %do;
68 %put _local_;
69 data _null_;
70 infile &fref0;
71 input;
72 put _infile_;
73 run;
74%end;
75
76proc http method='POST' headerin=&fref0 out=&fref1
77 url="&_sasjs_apiserverurl/SASjsApi/group/&gid/&uid";
78%if &mdebug=1 %then %do;
79 debug level=1;
80%end;
81run;
82
83%mp_abort(
84 iftrue=(&syscc ne 0)
85 ,mac=ms_adduser2group.sas
86 ,msg=%str(Issue submitting query to SASjsApi/group)
87)
88
89libname &libref JSON fileref=&fref1;
90
91data &outds;
92 set &libref..users;
93 drop ordinal_root ordinal_users;
94%if &mdebug=1 %then %do;
95 putlog _all_;
96%end;
97run;
98
99
100%mp_abort(
101 iftrue=(&syscc ne 0)
102 ,mac=ms_creategroup.sas
103 ,msg=%str(Issue reading response JSON)
104)
105
106/* reset options */
107options &optval;
108
109%if &mdebug=0 %then %do;
110 filename &fref0 clear;
111 filename &fref1 clear;
112 libname &libref clear;
113%end;
114%else %do;
115 data _null_;
116 infile &fref1;
117 input;
118 putlog _infile_;
119 run;
120%end;
121
122%mend ms_adduser2group;