mpe_checkrestore.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Checks if a user is able to restore a LOAD_REF
4  @details Not all LOAD_REFs can be restored - maybe the user does not have
5  permission, maybe the load was never loaded, or maybe the load was not
6  tracked.
7 
8  The macro creates two output (global) macro variables.
9 
10  @param [in] LOAD_REF The Load Reference to check
11  @param [out] outresult= (ALLOW_RESTORE) Output macro variable NAME. Will be
12  given the value of YES or NO depending on whether the user is allowed to
13  restore the load ref.
14  @param [out] outreason= (REASON) Output macro variable NAME.
15  Will be populated with the reason for which the restore decision was made.
16 
17  <h4> SAS Macros </h4>
18  @li mf_nobs.sas
19  @li mf_getuser.sas
20  @li mpe_accesscheck.sas
21  @li mpe_getgroups.sas
22 
23  <h4> Related Macros </h4>
24  @li mpe_checkrestore.test.sas
25 
26  @version 9.2
27  @author 4GL Apps Ltd
28  @copyright 4GL Apps Ltd. This code may only be used within Data Controller
29  and may not be re-distributed or re-sold without the express permission of
30  4GL Apps Ltd.
31 **/
32 
33 %macro mpe_checkrestore(load_ref,
34  outresult=ALLOW_RESTORE,
35  outreason=REASON
36 );
37 
38  %global &outresult &outreason;
39  %let &outresult=NO;
40  %let &outreason=NOTFOUND;
41 
42  /* check if there is actually a version to restore */
43  %local chk;
44  %let chk=0;
45  proc sql noprint;
46  select count(*) into: chk from &dc_libref..mpe_audit
47  where load_ref="&load_ref";
48  %if &chk=0 %then %do;
49  %let allow_restore=NO;
50  %let reason=No entry for &load_ref in MPE_AUDIT;
51  %return;
52  %end;
53 
54  /* grab user groups */
55  %local user;
56  %let user=%mf_getuser();
57  %mpe_getgroups(user=&user,outds=work.groups)
58 
59  /* check if user is admin */
60  %local is_admin;
61  %let is_admin=0;
62  proc sql;
63  select count(*) into: is_admin from work.groups
64  where groupname="&dc_admin_group";
65 
66  %if &is_admin>0 %then %do;
67  %let allow_restore=YES;
68  %let reason=IS ADMIN;
69  %return;
70  %end;
71 
72  /* check if user has basic access */
73  %local libds;
74  proc sql noprint;
75  select cats(base_lib,'.',base_ds) into: libds
76  from &mpelib..mpe_submit
77  where TABLE_ID="&load_ref";
78  %mpe_accesscheck(&libds,outds=work.access_check
79  ,user=&user
80  ,access_level=EDIT
81  )
82  %if %mf_nobs(access_check)=0 %then %do;
83  %let allow_restore=NO;
84  %let reason=No access in MPE_TABLES;
85  %return;
86  %end;
87 
88  /* check if user has column level security rules */
89  proc sql;
90  create table work.cls_rules as
91  select *
92  from &mpelib..mpe_column_level_security
93  where &dc_dttmtfmt. lt tx_to
94  and CLS_SCOPE in ("EDIT",'ALL')
95  and CLS_ACTIVE=1
96  and upcase(CLS_GROUP) in (select upcase(groupname) from work.groups)
97  and CLS_LIBREF="%upcase(&base_lib)"
98  and CLS_TABLE="%upcase(&base_ds)";
99  %if %mf_nobs(work.cls_rules)>0 %then %do;
100  %let allow_restore=NO;
101  %let reason=User has restrictions in MPE_COLUMN_LEVEL_SECURITY;
102  data _null_;
103  set work.cls_rules;
104  putlog (_all_)(=);
105  if _n_>5 then stop;
106  run;
107  %return;
108  %end;
109 
110  /* check if user has row level security rules */
111  proc sql;
112  create table work.rls_rules as
113  select *
114  from &mpelib..mpe_row_level_security
115  where &dc_dttmtfmt. lt tx_to
116  and rls_scope in ("EDIT",'ALL')
117  and upcase(rls_group) in (select upcase(groupname) from work.groups)
118  and rls_libref="&base_lib"
119  and rls_table="&base_ds"
120  and rls_active=1;
121  %if %mf_nobs(work.rls_rules)>0 %then %do;
122  %let allow_restore=NO;
123  %let reason=User has restrictions in MPE_ROW_LEVEL_SECURITY;
124  data _null_;
125  set work.rls_rules;
126  putlog (_all_)(=);
127  if _n_>5 then stop;
128  run;
129  %return;
130  %end;
131  %else %do;
132  %let allow_restore=YES;
133  %let reason=CHECKS PASSED;
134  %end;
135 %mend mpe_checkrestore;