Skip to content
Snippets Groups Projects
Commit 939f0f84 authored by Simon Leipold's avatar Simon Leipold
Browse files

1036804 - Berechtigung - Entitätsübersicht

parent cdb9d297
No related branches found
No related tags found
No related merge requests found
Showing
with 60 additions and 38 deletions
import("system.logging");
import("system.result");
import("system.vars");
import("Keyword_lib");
import("KeywordRegistry_basic");
logging.log("condtype: " + vars.get("$field.CONDTYPE"));
logging.log("getViewValue: " + KeywordUtils.getViewValue($KeywordRegistry.permissionConditionType(), vars.get("$field.CONDTYPE")));
result.string(KeywordUtils.getViewValue($KeywordRegistry.permissionConditionType(), vars.get("$field.CONDTYPE")));
import("system.logging");
import("system.db");
import("system.vars");
import("Permission_lib");
......@@ -47,4 +46,4 @@ switch (accessType) {
if (PermissionUtil.permSetIsEmpty(parentPermSetId)) {
db.deleteData("AB_PERMISSIONSET", sqlCondDelPermSet); // delete empty permissionset
}
\ No newline at end of file
}
import("system.logging");
import("system.neon");
import("system.util");
import("system.db");
import("system.vars");
import("Permission_lib");
logging.log("---INSERT---");
var table, cols, vals;
var sqlExt = "";
var permissionid = util.getNewUUID();
......@@ -17,7 +20,9 @@ var action = vars.get("$field.ACTION").trim();
if (checkInput([role, entity, accesstype, condtype, action])) {
// calculate accesstype
if (field != undefined && field != null && field != "")
// TODO: calculation of accesstype not needed
// $field.ACCESSTYPE should only allow input according to inserted field (->F) or action (view,create) (->E) otherwise (->R)
if (checkInput([field]))
sqlExt += " and FIELD_ID = '" + field + "'";
else if (action.includes("view") || action.includes("create"))
sqlExt += " and ACCESSTYPE = 'E'";
......@@ -27,35 +32,40 @@ if (checkInput([role, entity, accesstype, condtype, action])) {
var sqlStr = "select AB_PERMISSIONSETID from AB_PERMISSIONSET where ENTITY_ID = '" + entity + "' and ROLE_ID = '" + role + "'" + sqlExt;
var permissionsetid = db.cell(sqlStr);
if (permissionsetid == undefined || permissionsetid == null || permissionsetid == "") {
if (permissionsetid == "") {
// no fitting permissionset found - insert new permissionset
var rootpermissionset;
if (accesstype == "E")
if (accesstype == "E") {
rootpermissionset = "";
else {
sqlStr = "select AB_PERMISSIONSETID from AB_PERMISSIONSET where ENTITY_ID = '" + entity + "' and ROLE_ID = '" + role + "' and ACCESSTYPE = 'E'";
rootpermissionset = db.cell(sqlStr);
} else {
rootpermissionset = PermissionUtil.getRootPermissionSet(role, entity);
}
permissionsetid = PermissionUtil.insertNewPermissionSet(rootpermissionset, entity, role, field, accesstype)
}
// check if insert or update
// check if a new permissions is needed or an existing one can be used
var existingPermId = permExists(role, entity, field, accesstype, condtype, condition);
if (existingPermId != null && existingPermId != undefined && existingPermId != "") {
logging.log(existingPermId);
if (existingPermId != "") {
// update
permissionid = existingPermId;
} else {
// permission doesnt exist, insert new permission
// permission doesnt exist -> insert new permission
// new permissionid is needed to link actions to the permission in the next step
permissionid = PermissionUtil.insertNewPermission(permissionsetid, condition, condtype)
}
// insert new permissionaction
// insert new permissionaction
// TODO: Actions come from GenericMultiple now, not from Generic anymore (actions input used to be a comma seperated string)
logging.log("action: " + action);
var actionNew = action.split(",");
logging.log("action new: " + actionNew.toSource());
for each (let permaction in actionNew) {
PermissionUtil.insertNewPermissionAction(permissionid, permaction);
}
}
// checks input array if each element is a valid input, returns true if valid, otherwise false
function checkInput(pInputArr) {
for each (var input in pInputArr) {
if (input == undefined || input == null || input == "")
......@@ -64,6 +74,7 @@ function checkInput(pInputArr) {
return true;
}
// returns the permission(id) with given parameters, otherwise returns empty string
function permExists(pRole, pEntity, pField, pAccesstype, pCondtype, pCondition) {
var sqlExt = "";
if (pCondition != null && pCondition != undefined && pCondition != "")
......@@ -75,8 +86,5 @@ function permExists(pRole, pEntity, pField, pAccesstype, pCondtype, pCondition)
+ " where ENTITY_ID = '" + pEntity + "' and ROLE_ID = '" + pRole + "'"
+ " and ACCESSTYPE = '" + pAccesstype + "' and CONDTYPE = '" + pCondtype + "'" + sqlExt;
var permId = db.cell(sqlStr);
if (permId == null && permId == undefined && permId == "")
return null;
else
return permId;
return permId;
}
\ No newline at end of file
import("system.logging");
import("system.util");
import("system.db");
import("system.vars");
import("Permission_lib");
logging.log("---UPDATE---");
var table, cols, vals, cond;
var permissionid = vars.get("$field.UID");
var actionNew = vars.get("$field.ACTION").split(",");
logging.log("permissionid: " + permissionid);
var actionNew = vars.get("$field.ACTION").trim().split(",");
var entityNew = vars.get("$field.ENTITY");
var permCond = vars.get("$field.CONDITION");
var permCondType = vars.get("$field.CONDTYPE").trim();
var diff = PermissionUtil.getActionDiff(permissionid, actionNew);
logging.log("actionNew: " + actionNew.toSource());
logging.log("diff: " + diff.toSource());
if (diff.length > 0) {
// delete all linked permission actions
table = "AB_PERMISSIONACTION";
cond = SqlCondition.begin().and("AB_PERMISSION_ID = '" + permissionid + "'").build();
var dbDeletes = db.deleteData(table, cond);
// insert
// insert the different actions
cols = db.getColumns(table);
var dbInserts = 0;
for each (var action in actionNew) {
vals = [util.getNewUUID(), permissionid, action];
dbInserts += db.insertData(table, cols, null, vals);
PermissionUtil.insertNewPermissionAction(permissionid, action);
}
}
PermissionUtil.updateIfDiff(permissionid, permCond, "COND", "AB_PERMISSION"); // updates COND if the new cond is different to COND in DB
PermissionUtil.updateIfDiff(permissionid, permCondType, "CONDTYPE", "AB_PERMISSION"); // updates CONDTYPE if the new condtype is different to CONDTYPE in DB
// needs entity of children also to be changed/deleted/ignored?
// entity of children has to be changed/deleted/ignored?
// PermissionUtil.updateIfDiff(PermissionUtil.getParentPermissionSet(permissionid), entityNew, "ENTITY_ID", "AB_PERMISSIONSET");
import("system.vars");
import("system.logging");
import("system.result");
import("system.project");
......
import("system.logging");
import("system.vars");
import("system.db");
import("system.result");
......
import("system.translate");
import("system.logging");
import("system.vars");
import("system.result");
import("system.tools");
......
......@@ -37,11 +37,18 @@
<name>c5629444-0aba-4880-a4d8-6352aa4d12e5</name>
<entityField>CONDITION</entityField>
</entityFieldLink>
<entityFieldLink>
<name>fafd3411-4566-450a-bf3b-06193fc6c852</name>
<entityField>ACTION</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
<genericMultipleViewTemplate>
<name>GenericMultiple</name>
<entityField>#ENTITY</entityField>
<title>Action</title>
<columns>
<neonTableColumn>
<name>ebf2d3a9-cf44-4e25-a5e7-753c5518497c</name>
<entityField>ACTION</entityField>
</neonTableColumn>
</columns>
</genericMultipleViewTemplate>
</children>
</neonView>
......@@ -12,7 +12,6 @@
<name>Card</name>
<iconField>#ICON</iconField>
<titleField>#TITLE</titleField>
<subtitleField>ACTION</subtitleField>
<entityField>#ENTITY</entityField>
</cardViewTemplate>
<genericViewTemplate>
......@@ -30,5 +29,16 @@
</entityFieldLink>
</fields>
</genericViewTemplate>
<genericMultipleViewTemplate>
<name>GenericMultiple</name>
<entityField>#ENTITY</entityField>
<title>Action</title>
<columns>
<neonTableColumn>
<name>a11c2bad-7481-4376-adeb-6728f42254ee</name>
<entityField>ACTION</entityField>
</neonTableColumn>
</columns>
</genericMultipleViewTemplate>
</children>
</neonView>
import("system.util");
import("system.logging");
import("system.db");
import("Sql_lib");
......@@ -146,11 +145,11 @@ PermissionUtil.indexOfPermId = function(pPermTable, pPermId) {
}
/**
* Checks if the given actions of a permission are different to the actions which are in the database.
* Checks a permission if the given actions are different to the actions in the database.
*
* @param {String} pPermId the id of the permission
* @param {String} pPermId permission id to which the actions are linked to
*
* @param {String} pActionNew actions which have to be checked if updated
* @param {String[]} pActionNew array of strings of new actions
*
* @result {String[]} returns the different elements
*/
......@@ -177,7 +176,6 @@ PermissionUtil.getActionDiff = function(pPermId, pActionNew) {
PermissionUtil.isDiff = function(pId, pString, pDbCol, pDbTable) {
var sqlStr = "select " + pDbCol + " from " + pDbTable + " where " + pDbTable + "ID = '" + pId + "'";
var stringDb = db.cell(sqlStr);
logging.log(stringDb + " == " + pString);
return stringDb != pString ? true : false;
}
......@@ -442,6 +440,7 @@ PermissionUtil.insertNewPermissionAction = function(pParentPerm, pAction) {
return permactionid;
}
// arrDiff calculates different elements of two arrays and returns them as array, otherwise empty array
function arrDiff (arr1, arr2) {
var helperArr = [], diff = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment