Loading...
Searching...
No Matches
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 %local libds;
43 proc sql noprint;
44 select upcase(cats(base_lib,'.',base_ds)) into: libds
45 from &dc_libref..mpe_submit
46 where TABLE_ID="&load_ref";
47
48 %local base_lib base_ds;
49 %let base_lib=%scan(&libds,1,.);
50 %let base_ds=%scan(&libds,2,.);
51
52 /**
53 * check if there is actually a version to restore
54 */
55 %local audtab;
56 proc sql noprint;
57 select coalescec(audit_libds,"&dc_libref..MPE_AUDIT") into: audtab
58 from &dc_libref..MPE_TABLES
59 where &dc_dttmtfmt. lt tx_to
60 and libref="%scan(&libds,1,.)" and dsn="%scan(&libds,2,.)";
61 %if "&audtab"="0" %then %do;
62 %let &outresult=NO;
63 %let &outreason= &libds has no audit table configured;
64 %return;
65 %end;
66
67 %local chk;
68 %let chk=0;
69 proc sql noprint;
70 select count(*) into: chk from &audtab
71 where load_ref="&load_ref";
72 %if &chk=0 %then %do;
73 %let &outresult=NO;
74 %let &outreason=No entry for &load_ref in &audtab;
75 %return;
76 %end;
77
78 /* grab user groups */
79 %local user;
80 %let user=%mf_getuser();
81 %mpe_getgroups(user=&user,outds=work.groups)
82
83 /* check if user is admin */
84 %local is_admin;
85 %let is_admin=0;
86 proc sql;
87 select count(*) into: is_admin from work.groups
88 where groupname="&dc_admin_group";
89
90 %if &is_admin>0 %then %do;
91 %let &outresult=YES;
92 %let &outreason=IS ADMIN;
93 %return;
94 %end;
95
96 /* check if user has basic access */
97 %mpe_accesscheck(&libds,outds=work.access_check
98 ,user=&user
99 ,access_level=EDIT
100 )
101 %if %mf_nobs(access_check)=0 %then %do;
102 %let &outresult=NO;
103 %let &outreason=No access in MPE_TABLES;
104 %return;
105 %end;
106
107 /* check if user has column level security rules */
108 proc sql;
109 create table work.cls_rules as
110 select *
111 from &mpelib..mpe_column_level_security
112 where &dc_dttmtfmt. lt tx_to
113 and CLS_SCOPE in ("EDIT",'ALL')
114 and CLS_ACTIVE=1
115 and upcase(CLS_GROUP) in (select upcase(groupname) from work.groups)
116 and CLS_LIBREF="%upcase(&base_lib)"
117 and CLS_TABLE="%upcase(&base_ds)";
118 %if %mf_nobs(work.cls_rules)>0 %then %do;
119 %let &outresult=NO;
120 %let &outreason=User has restrictions in MPE_COLUMN_LEVEL_SECURITY;
121 data _null_;
122 set work.cls_rules;
123 putlog (_all_)(=);
124 if _n_>5 then stop;
125 run;
126 %return;
127 %end;
128
129 /* check if user has row level security rules */
130 proc sql;
131 create table work.rls_rules as
132 select *
133 from &mpelib..mpe_row_level_security
134 where &dc_dttmtfmt. lt tx_to
135 and rls_scope in ("EDIT",'ALL')
136 and upcase(rls_group) in (select upcase(groupname) from work.groups)
137 and rls_libref="&base_lib"
138 and rls_table="&base_ds"
139 and rls_active=1;
140 %if %mf_nobs(work.rls_rules)>0 %then %do;
141 %let &outresult=NO;
142 %let &outreason=User has restrictions in MPE_ROW_LEVEL_SECURITY;
143 data _null_;
144 set work.rls_rules;
145 putlog (_all_)(=);
146 if _n_>5 then stop;
147 run;
148 %return;
149 %end;
150 %else %do;
151 %let &outresult=YES;
152 %let &outreason=CHECKS PASSED;
153 %end;
154%mend mpe_checkrestore;