startupservice.sas
Go to the documentation of this file.
1 /**
2  @file startupservice.sas
3  @brief List the libraries and tables the mp-editor user can access
4  @details If user is in a control group (&mpeadmins, configured in mpeinit.sas)
5  then they have access to all libraries / tables. Otherwise a join is made
6  to the &mpelib..mp_editor_access table.
7 
8  This service is also callable from EUCs - just add EUCDLM= parameter.
9  EUCDLM values: TAB or CSV
10 
11  <h4> SAS Macros </h4>
12  @li mf_getuser.sas
13  @li mpe_getgroups.sas
14  @li mp_abort.sas
15  @li mpeinit.sas
16 
17  @version 9.2
18  @author 4GL Apps Ltd
19  @copyright 4GL Apps Ltd. This code may only be used within Data Controller
20  and may not be re-distributed or re-sold without the express permission of
21  4GL Apps Ltd.
22 **/
23 
24 %mpeinit()
25 %mp_abort(iftrue= (&syscc ne 0)
26  ,mac=&_program..sas
27  ,msg=%str(Issue on startup in startupService)
28 )
29 
30 %let userid=%mf_getuser();
31 %put userid is &userid;
32 %mpe_getgroups(user=&userid,outds=groups)
33 %mp_abort(iftrue= (&syscc ne 0)
34  ,mac=&_program..sas
35  ,msg=%str(Issue with Groups syscc=&syscc for user &userid)
36 )
37 
38 /* check if user is an admin */
39 %let admin_check=0;
40 proc sql noprint;
41 select count(*) into: admin_check
42  from groups
43  where groupname="&mpeadmins";
44 
45 /* check if user is registered or not */
46 %let isRegistered=0;
47 select count(*) into: isregistered
48  from &mpelib..mpe_users
49  where user_id="&userid";
50 
51 /* get number of registered users */
52 %let registerCount=0;
53 select count(*) into: registercount
54  from &mpelib..mpe_users
55  where last_seen_dt>%sysfunc(today())-365;
56 
57 %mp_abort(iftrue= (&syscc ne 0)
58  ,mac=&_program..sas
59  ,msg=%str(Problem accessing &mpelib..mpe_users table)
60 )
61 
62 %global dc_restrict_editrecord;
63 data work.globvars;
64  dclib="&mpelib";
65  sas9lineage_enabled=1;
66  isadmin=&admin_check;
67  isregistered=&isregistered;
68  registercount=&registerCount;
69  dc_admin_group="&mpeadmins";
70  /* fetched from mpe_config in dc_getsettings */
71  licence_key="&dc_licence_key";
72  activation_key="&dc_activation_key";
73  dc_restrict_editrecord="&dc_restrict_editrecord";
74 run;
75 
76 
77 %macro mstp_mpeditorstartup();
78  data _null_;
79  putlog "entering &sysmacroname";
80  run;
81  proc sql noprint;
82  /* update last seen, if seen */
83  %if &isregistered>0 %then %do;
84  update &mpelib..mpe_users
85  set last_seen_dt=%sysfunc(today())
86  where user_id="&userid";
87  %end;
88  %mp_abort(iftrue= (&syscc ne 0)
89  ,mac=&_program..sas
90  ,msg=%str(Problem updating &mpelib..mpe_users table)
91  )
92 
93  %local all_cnt;
94  select count(*) into: all_cnt
95  from &mpelib..mpe_security
96  where &dc_dttmtfmt. lt tx_to
97  and ACCESS_LEVEL in ('EDIT')
98  and libref='*ALL*'
99  and SAS_GROUP in (select groupname from groups);
100  %if &admin_check >0 or &all_cnt>0 %then %do;
101  create table sasDatasets as
102  select distinct libref, dsn
103  from &mpelib..mpe_tables
104  where &dc_dttmtfmt. lt tx_to
105  order by 1;
106  %end;
107  %else %do;
108  create table sasDatasets as
109  select distinct a.libref,a.dsn
110  from &mpelib..mpe_tables a
111  left join &mpelib..mpe_security b
112  on a.libref=b.libref
113  and a.dsn=b.dsn
114  where &dc_dttmtfmt. lt a.tx_to
115  and &dc_dttmtfmt. lt b.tx_to
116  and b.ACCESS_LEVEL in ('EDIT')
117  and b.SAS_GROUP in (select groupname from groups)
118  order by 1;
119  %end;
120 %mend mstp_mpeditorstartup;
121 %mstp_mpeditorstartup()
122 
123 create table saslibs as
124  select distinct libref
125  from &syslast;
126 
127 %mp_abort(iftrue= (&syscc ne 0)
128  ,mac=&_program..sas
129  ,msg=%str(issue with security validation)
130 )
131 
132 %webout(OPEN)
133 %webout(OBJ,sasDatasets)
134 %webout(OBJ,saslibs)
135 %webout(OBJ,globvars)
136 %webout(CLOSE)
137 
138 %mpeterm()