Code source wiki de Live Security

Version 1.1 par mrochelle le 2020/08/05 16:10

Afficher les derniers auteurs
1 = Define Live Security function =
2 Open the data model you wish to set a Live Security function
3 Add the function in the SELTRANS section of the dictionary of functions (You have to duplicate it and update it between /* START CONFIG*/ and /* END CONFIG */ see below)
4
5 {{code language="js"}}
6 /* START CONFIG */
7 //version: 2019R2
8 var securedDims = {};
9 securedDims["Région"] = getUserAttribute("region");
10
11 /* Ajouter ici les autres dimensions sur lequel du live security doit s’appliquer */
12 /*
13 securedDims["DIMENSION_NAME_2"] = getUserAttribute("USER_PARAM_2");
14 */
15
16 /* END CONFIG */
17
18 /* MODIFY THE SCRIPT BELOW WITH CAUTION */
19 var sLogPrefix = "[LIVE_SECURITY] [live-sec-thread-" + Math.floor(Math.random()*16777215).toString(16) + "]"; /* 16777215 is FFFFFF in decimal */
20
21 for (var dimId in securedDims)
22 {
23 var dim = selection.dm.objName[dimId];
24 var persoVal = securedDims[dimId];
25
26 //Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + "Applying user filters on: " + dimId + ", persoVal:" + persoVal);
27 if (dim)
28 {
29 if (persoVal == null || persoVal.length == 0)
30 {
31 // user must no see any value
32 var persoValuesTab = ["-noval-"];
33 var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
34 selection.setFilter(filt);
35 Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Filters (members) on " + dimId + ": [" + persoValuesTab + "]");
36 }
37 else if (persoVal && persoVal != ".*")
38 {
39 //user is limited to some value(s)
40 var persoValuesTab = persoVal.split("|");
41 Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Applying user filters on " + dimId + ": [" + persoValuesTab + "]");
42
43 var exFilter = selection.filterByDimName[dimId];
44 if (!exFilter)
45 {
46 //there is no exisitng filter on that dimension => create a new one
47 var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
48 selection.setFilter(filt);
49 Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (members) on " + dimId + ": [" + persoValuesTab + "]");
50 }
51 else
52 {
53 //there is already a filter on that dimension => merge (intersect) into a new one
54 var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
55 filt.recalcIds();
56 exFilter.recalcIds();
57 exFilter = mergeFilters(exFilter, filt);
58 origIdsTab = exFilter.origIds;
59 selection.setFilter(exFilter);
60 Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (origIds) on " + dimId + ": [" + exFilter.origIds + "]");
61 }
62 }
63 else // perso value is .*
64 {
65 // do nothing, user can see everything
66 Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters on " + dimId + ": All (.*)");
67 }
68 }
69 else
70 {
71 Packages.com.digdash.utils.MessageStack.getInstance().addError(sLogPrefix + " Dimension " + dimId + "not found");
72 }
73 }
74 {{/code}}
75
76 = User Attribute =
77
78 Make sure to add a user parameter (USER_PARAM_1 for example) and fill it for the concerned users (Set .* for other users).
79 In the following example, admin will be granted to see the DIMENSION_NAME_1 where value A, B or C are present.
80
81 = Live Security to forbid measure display =
82 {{code language="js"}}
83 var show_measure = getUserAttribute('show_measure');
84 var measureId = 'CA'; // id of the measure to hide
85
86 if (show_measure == 'non')
87 {
88 var measIndex = selection.indexOfMeasure(measureId);
89 if (measIndex > 0)
90 selection.removeMeasure(measIndex);
91 }
92 {{/code}}