Loading...
Searching...
No Matches
getdiffs.sas
Go to the documentation of this file.
1/**
2 @file getdiffs.sas
3 @brief Retrieves the diff file for viewing
4 @details
5
6 <h4> SAS Macros </h4>
7 @li mpe_getvars.sas
8 @li mpe_accesscheck.sas
9 @li mf_getattrn.sas
10 @li mf_getuser.sas
11 @li mp_abort.sas
12 @li mp_streamfile.sas
13 @li mp_validatecol.sas
14
15 @version 9.2
16 @author 4GL Apps Ltd
17 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
18 and may not be re-distributed or re-sold without the express permission of
19 4GL Apps Ltd.
20
21**/
22
23%mpeinit()
24%mpe_getvars(BrowserParams, BrowserParams);
25
26/**
27 * Validate inputs before they reach executable code. libds is passed to
28 * the access check (which interpolates it into SQL) and table is used in
29 * the staging file path, so both must be well formed before use. Values
30 * are re-read with symget (never re-resolved) and validated in a data
31 * step so no macro content in the request can execute.
32 */
33%let is_libds=0;
34%let is_table=0;
35%let is_csv=0;
36data _null_;
37 length _libds $64 _table $64 _csv $128;
38 _libds=symget('libds');
39 _table=symget('table');
40 _csv=coalescec(symget('stp_diffs_csv'),'tempDiffs.csv');
41 %mp_validatecol(_libds,LIBDS,is_libds)
42 %mp_validatecol(_table,ISNAME,is_table)
43 /* the diffs csv filename must stay inside the staging directory */
44 if findc(_csv,'/\')>0 or index(_csv,'..')>0 then do;
45 is_csv=0;
46 putlog 'ERR' 'OR: Invalid stp_diffs_csv:' _csv;
47 end;
48 else is_csv=1;
49 if is_libds=0 then putlog 'ERR' 'OR: Invalid libds:' _libds;
50 if is_table=0 then putlog 'ERR' 'OR: Invalid table:' _table;
51 call symputx('is_libds',is_libds,'l');
52 call symputx('is_table',is_table,'l');
53 call symputx('is_csv',is_csv,'l');
54 if is_libds=1 then call symputx('libds',_libds,'g');
55 if is_table=1 then call symputx('table',_table,'g');
56 if is_csv=1 then call symputx('stp_diffs_csv',_csv,'g');
57run;
58
59%mp_abort(iftrue= (&is_libds ne 1)
60 ,mac=&_program..sas
61 ,msg=%str(Invalid libds)
62)
63%mp_abort(iftrue= (&is_table ne 1)
64 ,mac=&_program..sas
65 ,msg=%str(Invalid table)
66)
67%mp_abort(iftrue= (&is_csv ne 1)
68 ,mac=&_program..sas
69 ,msg=%str(Invalid stp_diffs_csv)
70)
71
72/* security checks */
73%let user=%mf_getuser();
74%mpe_accesscheck(&libds,outds=authEDIT,user=&user,access_level=EDIT)
75%mpe_accesscheck(&libds,outds=authAPP,user=&user,access_level=APPROVE)
76
77%macro mpestp_diffs();
78 %if %mf_getattrn(work.authEDIT,NLOBS)=0 & %mf_getattrn(work.authAPP,NLOBS)=0
79 %then %do;
80 %mp_abort(msg=%str(
81 &user not authorised to download diffs data for &stp_table)
82 ,mac=mpestp_diffs.sas);
83 %return;
84 %end;
85
86 %mp_abort(iftrue= (&syscc ne 0)
87 ,mac=&_program..sas
88 ,msg=%str(syscc=&syscc)
89 )
90
91 /* stream diffs csv to client */
92 %mp_streamfile(contenttype=EXCEL
93 ,inloc=%str(&mpelocapprovals/&TABLE/&STP_DIFFS_CSV)
94 ,outname=&STP_DIFFS_CSV
95 )
96
97%mend mpestp_diffs;
98%mpestp_diffs()
99
100
101%mpeterm()