Loading...
Searching...
No Matches
mpe_row_level_security_postedit.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Post Edit Hook script for the MPE_ROW_LEVEL_SECURITY table
4 @details Post edit hooks provide additional backend validation for user
5 provided data. The incoming dataset is named `work.staging_ds` and is
6 provided in mpe_loader.sas.
7
8 Available macro variables:
9 @li DC_LIBREF - The DC control library
10 @li LIBREF - The library of the dataset being edited (is assigned)
11 @li DS - The dataset being edited
12
13 This validation checks the incoming row_level_security settings to ensure
14 each individual filter is
15
16 It also checks that EDIT scope security is not being applied to tables
17 with a REPLACE loadtype (these are incompatible - see issue #211).
18
19 <h4> SAS Macros </h4>
20 @li dc_assignlib.sas
21 @li mf_nobs.sas
22 @li mp_abort.sas
23 @li mp_filtercheck.sas
24
25 <h4> Related Macros </h4>
26 @li mpe_loader.sas
27
28**/
29
30
31/* REPLACE loadtype is incompatible with row level EDIT security (#211) */
32proc sql noprint;
33create table work.badloadtypes as
34 select distinct cats(upcase(a.rls_libref),'.',upcase(a.rls_table)) as libds
35 from work.staging_ds(where=(rls_active=1
36 and upcase(rls_scope) in ('EDIT','ALL')
37 and upcase(_____DELETE__THIS__RECORD_____) ne 'YES')) a
38 inner join &dc_libref..mpe_tables(where=(&dc_dttmtfmt. lt tx_to)) b
39 on upcase(a.rls_libref)=upcase(b.libref)
40 and upcase(a.rls_table)=upcase(b.dsn)
41 where upcase(b.loadtype)='REPLACE';
42
43%let badloadtypes=0;
44%let badloadtype=;
45data _null_;
46 set work.badloadtypes;
47 call symputx('badloadtypes',_n_);
48 call symputx('badloadtype',libds);
49run;
50
51%mp_abort(iftrue=(&badloadtypes ne 0)
52 ,mac=mpe_row_level_security_postedit
53 ,msg=%str(Row level EDIT security cannot be applied to table(s) with a%trim(
54 ) REPLACE loadtype, eg: &badloadtype. Remove the security rule(s) or%trim(
55 ) change the loadtype.)
56)
57
58/* group and subgroup are not used for validation */
59proc sql;
60create table work.batches as
61 select distinct upcase(rls_libref) as rls_libref,
62 upcase(rls_table) as rls_table,
63 rls_group_logic as group_logic,
64 rls_subgroup_logic as subgroup_logic,
65 rls_subgroup_id as subgroup_id,
66 rls_variable_nm as variable_nm,
67 rls_operator_nm as operator_nm,
68 rls_raw_value as raw_value
69 from work.staging_ds
70 where rls_active=1
71 and upcase(_____DELETE__THIS__RECORD_____) ne 'YES'
72 order by rls_libref, rls_table;
73
74%let cnt=0;
75data _null_;
76 set work.batches;
77 by rls_libref rls_table;
78 putlog (_all_)(=);
79 if last.rls_table then do;
80 x+1;
81 call symputx(cats('libds',x),cats(rls_libref,'.',rls_table));
82 call symputx('cnt',x);
83 end;
84run;
85
86/* derived variables exist only in the view the EDIT screen reads - a rule on
87 one cannot be validated against the physical table, so reject it here rather
88 than let mp_filtercheck fail with a variable-not-found error. Applies to
89 every scope: the VIEW scope could evaluate the column, but this hook checks
90 rules against the table they are submitted for. */
91proc sql;
92create table work.rls_derived as
93 select b.rls_libref, b.rls_table, b.variable_nm
94 from work.batches b
95 inner join &DC_LIBREF..mpe_derived d
96 on upcase(d.libref)=b.rls_libref
97 and upcase(d.dsn)=b.rls_table
98 and upcase(d.var_nm)=upcase(b.variable_nm)
99 where &dc_dttmtfmt lt d.tx_to
100 and d.active=1;
101quit;
102
103%let rls_msg=;
104data _null_;
105 set work.rls_derived(obs=1);
106 call symputx('rls_msg'
107 ,cats('MPE_ROW_LEVEL_SECURITY: ',variable_nm
108 ,' is a derived variable in ',rls_libref,'.',rls_table
109 ,' - derived variables cannot be used in a row level security rule'));
110run;
111
112%mp_abort(iftrue= (0 < %mf_nobs(work.rls_derived))
113 ,mac=mpe_row_level_security_postedit
114 ,msg=%superq(rls_msg)
115)
116
117%macro quickloop();
118%do i=1 %to &cnt;
119 data work.inds&i;
120 set work.batches;
121 if cats(rls_libref,'.',rls_table)="&&libds&i";
122 keep group_logic subgroup_logic subgroup_id variable_nm operator_nm
123 raw_value;
124 run;
125 %dc_assignlib(READ,%scan(&&libds&i,1,.))
126 %mp_filtercheck(work.inds&i
127 ,targetds=&&libds&i
128 ,outds=work.badrecords
129 ,abort=YES
130 )
131%end;
132%mend quickloop;
133
134%quickloop()