Live Security
Last modified by Aurelie Bertrand on 2024/08/27 15:45
Define Live Security function
Open the data model you wish to set a Live Security function
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)
/* START CONFIG */
//version: 2019R2
var securedDims = {};
securedDims["Région"] = getUserAttribute("region");
/* Ajouter ici les autres dimensions sur lequel du live security doit s’appliquer */
/*
securedDims["DIMENSION_NAME_2"] = getUserAttribute("USER_PARAM_2");
*/
/* END CONFIG */
/* MODIFY THE SCRIPT BELOW WITH CAUTION */
var sLogPrefix = "[LIVE_SECURITY] [live-sec-thread-" + Math.floor(Math.random()*16777215).toString(16) + "]"; /* 16777215 is FFFFFF in decimal */
for (var dimId in securedDims)
{
var dim = selection.dm.objName[dimId];
var persoVal = securedDims[dimId];
//Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + "Applying user filters on: " + dimId + ", persoVal:" + persoVal);
if (dim)
{
if (persoVal == null || persoVal.length == 0)
{
// user must no see any value
var persoValuesTab = ["-noval-"];
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
selection.setFilter(filt);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Filters (members) on " + dimId + ": [" + persoValuesTab + "]");
}
else if (persoVal && persoVal != ".*")
{
//user is limited to some value(s)
var persoValuesTab = persoVal.split("|");
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Applying user filters on " + dimId + ": [" + persoValuesTab + "]");
var exFilter = selection.filterByDimName[dimId];
if (!exFilter)
{
//there is no exisitng filter on that dimension => create a new one
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
selection.setFilter(filt);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (members) on " + dimId + ": [" + persoValuesTab + "]");
}
else
{
//there is already a filter on that dimension => merge (intersect) into a new one
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
filt.recalcIds();
exFilter.recalcIds();
exFilter = mergeFilters(exFilter, filt);
origIdsTab = exFilter.origIds;
selection.setFilter(exFilter);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (origIds) on " + dimId + ": [" + exFilter.origIds + "]");
}
}
else // perso value is .*
{
// do nothing, user can see everything
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters on " + dimId + ": All (.*)");
}
}
else
{
Packages.com.digdash.utils.MessageStack.getInstance().addError(sLogPrefix + " Dimension " + dimId + "not found");
}
}
//version: 2019R2
var securedDims = {};
securedDims["Région"] = getUserAttribute("region");
/* Ajouter ici les autres dimensions sur lequel du live security doit s’appliquer */
/*
securedDims["DIMENSION_NAME_2"] = getUserAttribute("USER_PARAM_2");
*/
/* END CONFIG */
/* MODIFY THE SCRIPT BELOW WITH CAUTION */
var sLogPrefix = "[LIVE_SECURITY] [live-sec-thread-" + Math.floor(Math.random()*16777215).toString(16) + "]"; /* 16777215 is FFFFFF in decimal */
for (var dimId in securedDims)
{
var dim = selection.dm.objName[dimId];
var persoVal = securedDims[dimId];
//Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + "Applying user filters on: " + dimId + ", persoVal:" + persoVal);
if (dim)
{
if (persoVal == null || persoVal.length == 0)
{
// user must no see any value
var persoValuesTab = ["-noval-"];
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
selection.setFilter(filt);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Filters (members) on " + dimId + ": [" + persoValuesTab + "]");
}
else if (persoVal && persoVal != ".*")
{
//user is limited to some value(s)
var persoValuesTab = persoVal.split("|");
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Applying user filters on " + dimId + ": [" + persoValuesTab + "]");
var exFilter = selection.filterByDimName[dimId];
if (!exFilter)
{
//there is no exisitng filter on that dimension => create a new one
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
selection.setFilter(filt);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (members) on " + dimId + ": [" + persoValuesTab + "]");
}
else
{
//there is already a filter on that dimension => merge (intersect) into a new one
var filt = new FilterSelection(dim, -1, -1, [], persoValuesTab);
filt.recalcIds();
exFilter.recalcIds();
exFilter = mergeFilters(exFilter, filt);
origIdsTab = exFilter.origIds;
selection.setFilter(exFilter);
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters (origIds) on " + dimId + ": [" + exFilter.origIds + "]");
}
}
else // perso value is .*
{
// do nothing, user can see everything
Packages.com.digdash.utils.MessageStack.getInstance().addDebug(sLogPrefix + " Resolved filters on " + dimId + ": All (.*)");
}
}
else
{
Packages.com.digdash.utils.MessageStack.getInstance().addError(sLogPrefix + " Dimension " + dimId + "not found");
}
}
User Attribute
Make sure to add a user parameter (USER_PARAM_1 for example) and fill it for the concerned users (Set .* for other users).
In the following example, admin will be granted to see the DIMENSION_NAME_1 where value A, B or C are present.
Live Security to forbid measure display
var show_measure = getUserAttribute('show_measure');
var measureId = 'CA'; // id of the measure to hide
if (show_measure == 'non')
{
var measIndex = selection.indexOfMeasure(measureId);
if (measIndex != -1)
selection.removeMeasure(measIndex);
}
var measureId = 'CA'; // id of the measure to hide
if (show_measure == 'non')
{
var measIndex = selection.indexOfMeasure(measureId);
if (measIndex != -1)
selection.removeMeasure(measIndex);
}