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