diff --git a/entity/PermissionDetail_entity/entityfields/condtype/displayValueProcess.js b/entity/PermissionDetail_entity/entityfields/condtype/displayValueProcess.js index 93a1839d5d01fc552ff45d5721d7ad67621bdcb1..d6026ea916df2bc6aa670a580d33d7c1dcae74e1 100644 --- a/entity/PermissionDetail_entity/entityfields/condtype/displayValueProcess.js +++ b/entity/PermissionDetail_entity/entityfields/condtype/displayValueProcess.js @@ -1,9 +1,6 @@ -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"))); diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js index 2e3bed6355b91ca9b1a25e877ee560395681da02..59f34513d50ae94649a05009129dc06d4ba77fe6 100644 --- a/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js +++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onDelete.js @@ -1,4 +1,3 @@ -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 +} diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onInsert.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onInsert.js index 8d5d66d42b69300a26af12efe2719ca581563628..58b69e34bd2dcd974d6a80514e8680b9b028fe95 100644 --- a/entity/PermissionDetail_entity/recordcontainers/jdito/onInsert.js +++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onInsert.js @@ -1,9 +1,12 @@ +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 diff --git a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js index f860ec72b3ec0e01a828f633a50adb79d5dcc2a4..b4fcca3c9b95bfaf1c426f355b2f9586dd6874a3 100644 --- a/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/PermissionDetail_entity/recordcontainers/jdito/onUpdate.js @@ -1,33 +1,38 @@ +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"); diff --git a/entity/PermissionMetaData_entity/recordcontainers/jdito/contentProcess.js b/entity/PermissionMetaData_entity/recordcontainers/jdito/contentProcess.js index ebb62899dff8fdba531afd179f10ba878968f9a0..3e7bd18d57ed6e83408d3197fbeda39780fc352c 100644 --- a/entity/PermissionMetaData_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/PermissionMetaData_entity/recordcontainers/jdito/contentProcess.js @@ -1,5 +1,4 @@ import("system.vars"); -import("system.logging"); import("system.result"); import("system.project"); diff --git a/entity/Permission_entity/recordcontainers/db/conditionProcess.js b/entity/Permission_entity/recordcontainers/db/conditionProcess.js index 2adcb0cdfb2e5a66f455cfe126dbc04b3bcef7bb..e3b2aadeab4e4fb4d304c110430f8e8393fb808a 100644 --- a/entity/Permission_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Permission_entity/recordcontainers/db/conditionProcess.js @@ -1,4 +1,3 @@ -import("system.logging"); import("system.vars"); import("system.db"); import("system.result"); diff --git a/entity/Role_entity/recordcontainers/jdito/contentProcess.js b/entity/Role_entity/recordcontainers/jdito/contentProcess.js index 81f43e812a800d7cf1ee42469e64e1b2844d04ea..d0d7a7bd99d501767243942d7ab9e90ad536c93e 100644 --- a/entity/Role_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/Role_entity/recordcontainers/jdito/contentProcess.js @@ -1,5 +1,4 @@ import("system.translate"); -import("system.logging"); import("system.vars"); import("system.result"); import("system.tools"); diff --git a/neonView/PermissionDetailEdit_view/PermissionDetailEdit_view.aod b/neonView/PermissionDetailEdit_view/PermissionDetailEdit_view.aod index e56c8aa78d81ff155a3ef14ebb32c38201d1646a..e6dd0a67e06b736d8765f540d06a555e599e2d5f 100644 --- a/neonView/PermissionDetailEdit_view/PermissionDetailEdit_view.aod +++ b/neonView/PermissionDetailEdit_view/PermissionDetailEdit_view.aod @@ -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> diff --git a/neonView/PermissionDetailPreview_view/PermissionDetailPreview_view.aod b/neonView/PermissionDetailPreview_view/PermissionDetailPreview_view.aod index 34b0eed3b08c16ec5d2794d94c3324d519a18704..ad1d2a05224a1dc23c8339b9d22eeb57c6c2205d 100644 --- a/neonView/PermissionDetailPreview_view/PermissionDetailPreview_view.aod +++ b/neonView/PermissionDetailPreview_view/PermissionDetailPreview_view.aod @@ -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> diff --git a/process/Permission_lib/process.js b/process/Permission_lib/process.js index 9da0159459d1c8137e22348663d6f680c8247f05..f449d69f2013aeb385a55fcf8f98afc8a85de834 100644 --- a/process/Permission_lib/process.js +++ b/process/Permission_lib/process.js @@ -1,5 +1,4 @@ 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 = [];