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 mp_abort.sas
22 @li mp_filtercheck.sas
23
24 <h4> Related Macros </h4>
25 @li mpe_loader.sas
26
27**/
28
29
30/* REPLACE loadtype is incompatible with row level EDIT security (#211) */
31proc sql noprint;
32create table work.badloadtypes as
33 select distinct cats(upcase(a.rls_libref),'.',upcase(a.rls_table)) as libds
34 from work.staging_ds(where=(rls_active=1
35 and upcase(rls_scope) in ('EDIT','ALL')
36 and upcase(_____DELETE__THIS__RECORD_____) ne 'YES')) a
37 inner join &dc_libref..mpe_tables(where=(&dc_dttmtfmt. lt tx_to)) b
38 on upcase(a.rls_libref)=upcase(b.libref)
39 and upcase(a.rls_table)=upcase(b.dsn)
40 where upcase(b.loadtype)='REPLACE';
41
42%let badloadtypes=0;
43%let badloadtype=;
44data _null_;
45 set work.badloadtypes;
46 call symputx('badloadtypes',_n_);
47 call symputx('badloadtype',libds);
48run;
49
50%mp_abort(iftrue=(&badloadtypes ne 0)
51 ,mac=mpe_row_level_security_postedit
52 ,msg=%str(Row level EDIT security cannot be applied to table(s) with a%trim(
53 ) REPLACE loadtype, eg: &badloadtype. Remove the security rule(s) or%trim(
54 ) change the loadtype.)
55)
56
57/* ignore scope and group for validation */
58proc sql;
59create table work.batches as
60 select distinct upcase(rls_libref) as rls_libref,
61 upcase(rls_table) as rls_table,
62 rls_group_logic as group_logic,
63 rls_subgroup_logic as subgroup_logic,
64 rls_subgroup_id as subgroup_id,
65 rls_variable_nm as variable_nm,
66 rls_operator_nm as operator_nm,
67 rls_raw_value as raw_value
68 from work.staging_ds
69 where rls_active=1
70 order by rls_libref, rls_table;
71
72%let cnt=0;
73data _null_;
74 set work.batches;
75 by rls_libref rls_table;
76 putlog (_all_)(=);
77 if last.rls_table then do;
78 x+1;
79 call symputx(cats('libds',x),cats(rls_libref,'.',rls_table));
80 call symputx('cnt',x);
81 end;
82run;
83
84%macro quickloop();
85%do i=1 %to &cnt;
86 data work.inds&i;
87 set work.batches;
88 if cats(rls_libref,'.',rls_table)="&&libds&i";
89 keep group_logic subgroup_logic subgroup_id variable_nm operator_nm
90 raw_value;
91 run;
92 %dc_assignlib(READ,%scan(&&libds&i,1,.))
93 %mp_filtercheck(work.inds&i
94 ,targetds=&&libds&i
95 ,outds=work.badrecords
96 ,abort=YES
97 )
98%end;
99%mend quickloop;
100
101%quickloop()