@sasjs/core 4.27.14 → 4.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,10 @@
2
2
  @file mm_adduser2group.sas
3
3
  @brief Adds a user to a group
4
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.
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.
6
9
 
7
10
  Usage:
8
11
 
@@ -12,10 +15,10 @@
12
15
 
13
16
  @param user= the user name (not displayname)
14
17
  @param group= the group to which to add the user
15
- @param mdebug= set to 1 to show debug info in log
18
+ @param mdebug= (0) set to 1 to show debug info in log
16
19
 
17
- @warning the macro does not check inherited group memberships - it looks at
18
- direct members only
20
+ <h4> Related Files </h4>
21
+ @li ms_adduser2group.sas
19
22
 
20
23
  @version 9.3
21
24
  @author Allan Bowe
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.27.14"
38
+ "version": "4.28.0"
39
39
  }
@@ -0,0 +1,122 @@
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));
57
+ options nobomfile;
58
+
59
+ data _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_;
65
+ run;
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
+
76
+ proc 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;
81
+ run;
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
+
89
+ libname &libref JSON fileref=&fref1;
90
+
91
+ data &outds;
92
+ set &libref..users;
93
+ drop ordinal_root ordinal_users;
94
+ %if &mdebug=1 %then %do;
95
+ putlog _all_;
96
+ %end;
97
+ run;
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 */
107
+ options &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;
@@ -2,13 +2,19 @@
2
2
  @file
3
3
  @brief Fetches the list of groups from SASjs Server
4
4
  @details Fetches the list of groups from SASjs Server and writes them to an
5
- output dataset.
5
+ output dataset. Provide a username to filter for the groups for a particular
6
+ user.
6
7
 
7
8
  Example:
8
9
 
9
10
  %ms_getgroups(outds=userlist)
10
11
 
12
+ With filter:
13
+
14
+ %ms_getgroups(outds=userlist, user=James)
15
+
11
16
  @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
17
+ @param [in] user= (0) Provide the username on which to filter
12
18
  @param [out] outds= (work.ms_getgroups) This output dataset will contain the
13
19
  list of groups. Format:
14
20
  |NAME:$32.|DESCRIPTION:$64.|GROUPID:best.|
@@ -25,28 +31,32 @@
25
31
 
26
32
  <h4> Related Files </h4>
27
33
  @li ms_creategroup.sas
28
- @li ms_getusers.test.sas
34
+ @li ms_getgroups.test.sas
29
35
 
30
36
  **/
31
37
 
32
38
  %macro ms_getgroups(
33
- outds=work.ms_getgroups
34
- ,mdebug=0
35
- );
39
+ user=0,
40
+ outds=work.ms_getgroups,
41
+ mdebug=0
42
+ );
36
43
 
37
44
  %mp_abort(
38
45
  iftrue=(&syscc ne 0)
39
- ,mac=ms_getusers.sas
46
+ ,mac=ms_getgroups.sas
40
47
  ,msg=%str(syscc=&syscc on macro entry)
41
48
  )
42
49
 
43
- %local fref0 fref1 libref optval rc msg;
50
+ %local fref0 fref1 libref optval rc msg url;
44
51
 
45
52
  %if %sysget(MODE)=desktop %then %do;
46
53
  /* groups api does not exist in desktop mode */
47
54
  data &outds;
48
55
  length NAME $32 DESCRIPTION $64. GROUPID 8;
49
- call missing (of _all_);
56
+ name="&sysuserid";
57
+ description="&sysuserid (group - desktop mode)";
58
+ groupid=1;
59
+ output;
50
60
  stop;
51
61
  run;
52
62
  %return;
@@ -76,8 +86,11 @@ run;
76
86
  run;
77
87
  %end;
78
88
 
89
+ %if "&user"="0" %then %let url=/SASjsApi/group;
90
+ %else %let url=/SASjsApi/user/by/username/&user;
91
+
79
92
  proc http method='GET' headerin=&fref0 out=&fref1
80
- url="&_sasjs_apiserverurl/SASjsApi/group";
93
+ url="&_sasjs_apiserverurl.&url";
81
94
  %if &mdebug=1 %then %do;
82
95
  debug level=1;
83
96
  %end;
@@ -86,17 +99,27 @@ run;
86
99
  %mp_abort(
87
100
  iftrue=(&syscc ne 0)
88
101
  ,mac=ms_getgroups.sas
89
- ,msg=%str(Issue submitting GET query to SASjsApi/group)
102
+ ,msg=%str(Issue submitting GET query to SASjsApi)
90
103
  )
91
104
 
92
105
  libname &libref JSON fileref=&fref1;
93
106
 
94
- data &outds;
95
- length NAME $32 DESCRIPTION $64. GROUPID 8;
96
- if _n_=1 then call missing(of _all_);
97
- set &libref..root;
98
- drop ordinal_root;
99
- run;
107
+ %if "&user"="0" %then %do;
108
+ data &outds;
109
+ length NAME $32 DESCRIPTION $64. GROUPID 8;
110
+ if _n_=1 then call missing(of _all_);
111
+ set &libref..root;
112
+ drop ordinal_root;
113
+ run;
114
+ %end;
115
+ %else %do;
116
+ data &outds;
117
+ length NAME $32 DESCRIPTION $64. GROUPID 8;
118
+ if _n_=1 then call missing(of _all_);
119
+ set &libref..groups;
120
+ drop ordinal_:;
121
+ run;
122
+ %end;
100
123
 
101
124
  %mp_abort(
102
125
  iftrue=(&syscc ne 0)
@@ -2,16 +2,21 @@
2
2
  @file
3
3
  @brief Fetches the list of users from SASjs Server
4
4
  @details Fetches the list of users from SASjs Server and writes them to an
5
- output dataset.
5
+ output dataset. Can also be filtered, for a particular group.
6
6
 
7
7
  Example:
8
8
 
9
9
  %ms_getusers(outds=userlist)
10
10
 
11
+ Filtering for a group:
12
+
13
+ %ms_getusers(outds=work.groupmembers, group=GROUPNAME)
14
+
11
15
  @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
16
+ @param [in] group= (0) Set to a group name to filter members for that group
12
17
  @param [out] outds= (work.ms_getusers) This output dataset will contain the
13
18
  list of user accounts. Format:
14
- |DISPLAYNAME:$18.|USERNAME:$10.|ID:best.|
19
+ |DISPLAYNAME:$60.|USERNAME:$30.|ID:best.|
15
20
  |---|---|---|
16
21
  |`Super Admin `|`secretuser `|`1`|
17
22
  |`Sabir Hassan`|`sabir`|`2`|
@@ -28,14 +33,16 @@
28
33
 
29
34
  <h4> Related Files </h4>
30
35
  @li ms_createuser.sas
36
+ @li ms_getgroups.sas
31
37
  @li ms_getusers.test.sas
32
38
 
33
39
  **/
34
40
 
35
41
  %macro ms_getusers(
36
- outds=work.ms_getusers
37
- ,mdebug=0
38
- );
42
+ outds=work.ms_getusers,
43
+ group=0,
44
+ mdebug=0
45
+ );
39
46
 
40
47
  %mp_abort(
41
48
  iftrue=(&syscc ne 0)
@@ -43,7 +50,7 @@
43
50
  ,msg=%str(syscc=&syscc on macro entry)
44
51
  )
45
52
 
46
- %local fref0 fref1 libref optval rc msg;
53
+ %local fref0 fref1 libref optval rc msg url;
47
54
  %let fref0=%mf_getuniquefileref();
48
55
  %let fref1=%mf_getuniquefileref();
49
56
  %let libref=%mf_getuniquelibref();
@@ -68,26 +75,40 @@ run;
68
75
  run;
69
76
  %end;
70
77
 
78
+ %if "&group"="0" %then %let url=/SASjsApi/user;
79
+ %else %let url=/SASjsApi/group/by/groupname/&group;
80
+
81
+
71
82
  proc http method='GET' headerin=&fref0 out=&fref1
72
- url="&_sasjs_apiserverurl/SASjsApi/user";
83
+ url="&_sasjs_apiserverurl.&url";
73
84
  %if &mdebug=1 %then %do;
74
85
  debug level=1;
75
86
  %end;
76
87
  run;
77
88
 
89
+
78
90
  %mp_abort(
79
91
  iftrue=(&syscc ne 0)
80
92
  ,mac=ms_getusers.sas
81
- ,msg=%str(Issue submitting GET query to SASjsApi/user)
93
+ ,msg=%str(Issue submitting API query)
82
94
  )
83
95
 
84
96
  libname &libref JSON fileref=&fref1;
85
97
 
86
- data &outds;
87
- set &libref..root;
88
- drop ordinal_root;
89
- run;
90
-
98
+ %if "&group"="0" %then %do;
99
+ data &outds;
100
+ length DISPLAYNAME $60 USERNAME:$30 ID 8;
101
+ set &libref..root;
102
+ drop ordinal_root;
103
+ run;
104
+ %end;
105
+ %else %do;
106
+ data &outds;
107
+ length DISPLAYNAME $60 USERNAME:$30 ID 8;
108
+ set &libref..users;
109
+ drop ordinal_root ordinal_users;
110
+ run;
111
+ %end;
91
112
 
92
113
  %mp_abort(
93
114
  iftrue=(&syscc ne 0)