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

1036804 Berechtigung - Entitätsübersicht - Refactoring in PermissionDetail

parent 0e6870e0
No related branches found
No related tags found
No related merge requests found
......@@ -29,9 +29,6 @@ if (checkInput([role, entity, accesstype, condtype, action])) {
if (permissionsetid == undefined || permissionsetid == null || permissionsetid == "") {
// no fitting permissionset found - insert new permissionset
table = "AB_PERMISSIONSET";
cols = db.getColumns(table);
permissionsetid = util.getNewUUID();
var rootpermissionset;
if (accesstype == "E")
rootpermissionset = "";
......@@ -39,30 +36,23 @@ if (checkInput([role, entity, accesstype, condtype, action])) {
sqlStr = "select AB_PERMISSIONSETID from AB_PERMISSIONSET where ENTITY_ID = '" + entity + "' and ROLE_ID = '" + role + "' and ACCESSTYPE = 'E'";
rootpermissionset = db.cell(sqlStr);
}
vals = [permissionsetid, rootpermissionset, accesstype, entity, field, role];
db.insertData(table, cols, null, vals);
permissionsetid = PermissionUtil.insertNewPermissionSet(rootpermissionset, entity, role, field, accesstype)
}
// check if insert or update
table = "AB_PERMISSION";
var existingPermId = permExists(role, entity, field, accesstype, condtype, condition);
if (existingPermId != null && existingPermId != undefined && existingPermId != "") {
permissionid = existingPermId;
} else {
// permission doesnt exist, insert new permission
cols = db.getColumns(table);
vals = [permissionid, permissionsetid, condition, condtype];
db.insertData(table, cols, null, vals);
// new permissionid is needed to link actions to the permission in the next step
permissionid = PermissionUtil.insertNewPermission(permissionsetid, condition, condtype)
}
// insert new permissionaction
table = "AB_PERMISSIONACTION";
cols = db.getColumns(table);
var actionNew = action.split(",");
var dbInserts = 0;
for each (let permaction in actionNew) {
vals = [util.getNewUUID(), permissionid, permaction];
dbInserts += db.insertData(table, cols, null, vals);
PermissionUtil.insertNewPermissionAction(permissionid, permaction);
}
}
......
import("system.util");
import("system.logging");
import("system.db");
import("Sql_lib");
......@@ -379,6 +380,68 @@ PermissionUtil.containsDuplicateActions = function(pPermId, pActionNew) {
return res;
}
/**
* Inserts a new instance of a permission set into AB_PERMISSIONSET.
*
* @param {String} pParentPermSet The parent permission set, empty if root node
*
* @param {String} pEntity The entity to which the PermissionSet is linked
*
* @param {String} pRole The Role to which the PermissionSet is linked
*
* @param {String} pField The Field to which the PermissionSet is linked
*
* @param {String} pAccessType Entity, Record or Field (E, R, F)
*
* @result {Integer} returns the id of the inserted permission set
*/
PermissionUtil.insertNewPermissionSet = function(pParentPermSet, pEntity, pRole, pField, pAccessType) {
var table = "AB_PERMISSIONSET";
var cols = db.getColumns(table);
var permsetid = util.getNewUUID();
var vals = [permsetid, pParentPermSet, pAccessType, pEntity, pField, pRole];
db.insertData(table, cols, null, vals);
return permsetid;
}
/**
* Inserts a new instance of a permission into AB_PERMISSION.
*
* @param {String} pParentPermSet The parent permission set
*
* @param {String} pCond The entity to which the PermissionSet is linked
*
* @param {String} pCondType The Role to which the PermissionSet is linked
*
* @result {Integer} returns the id of the inserted permission
*/
PermissionUtil.insertNewPermission = function(pParentPermSet, pCond, pCondType) {
var table = "AB_PERMISSION";
var cols = db.getColumns(table);
var permid = util.getNewUUID();
var vals = [permid, pParentPermSet, pCond, pCondType];
db.insertData(table, cols, null, vals);
return permid;
}
/**
* Inserts a new instance of a permission action into AB_PERMISSIONACTION.
*
* @param {String} pParentPerm The parent permission
*
* @param {String} pAction Action (view, create,...)
*
* @result {Integer} returns the id of the inserted permission action
*/
PermissionUtil.insertNewPermissionAction = function(pParentPerm, pAction) {
var table = "AB_PERMISSIONACTION";
var cols = db.getColumns(table);
var permactionid = util.getNewUUID();
var vals = [permactionid, pParentPerm, pAction];
db.insertData(table, cols, null, vals);
return permactionid;
}
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