From 898d7393bd5f53e3a7acfcc2e04e51d4d1387a29 Mon Sep 17 00:00:00 2001
From: Simon Leipold <s.leipold@adito.de>
Date: Wed, 4 Mar 2020 10:49:32 +0100
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.:
 1053501][Berechtigungshierarchie - Anzeige von parent role]

---
 .../recordcontainers/jdito/contentProcess.js     | 16 ++++++++--------
 process/Permission_lib/process.js                | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js b/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
index f21fb44def8..9732fa101c6 100644
--- a/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
@@ -5,18 +5,18 @@ import("system.result");
 import("system.util");
 
 var alias = SqlUtils.getSystemAlias();
-var parentRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param");
+var selectedRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param");
 var children = [];
 
-if (parentRoleName && parentRoleName.indexOf("CUSTOM_") != -1) {
-    // roles can only be assigned to CUSTOM roles -> parent role has to be a viable CUSTOM role
-    childRoles = newSelect("ID, CHILD_ROLE", alias)
-        .from("ASYS_ROLES_CHILDREN")
-        .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", parentRoleName)
-        .table();
+// roles can only be assigned to CUSTOM roles -> selected role has to be a viable CUSTOM role
+if (selectedRoleName && selectedRoleName.indexOf("CUSTOM_") != -1) {
+    var childRoles = newSelect("ID, CHILD_ROLE", alias)
+    .from("ASYS_ROLES_CHILDREN")
+    .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", selectedRoleName)
+    .table();
 
     for each (let childRole in childRoles) {
-        children.push([childRole[0], childRole[1], parentRoleName]);
+        children.push([childRole[0], childRole[1], selectedRoleName]);
     }
 
     var ids = vars.get("$local.idvalues");
diff --git a/process/Permission_lib/process.js b/process/Permission_lib/process.js
index ac78dd31487..5a054df59de 100644
--- a/process/Permission_lib/process.js
+++ b/process/Permission_lib/process.js
@@ -836,6 +836,20 @@ function PermissionUtil () {}
         return true;
     }
     
+    /**
+     * Gets all parent roles of the given role.
+     * 
+     * @param {String} pRoleName name of the role, mandatory
+     * 
+     * @result {String[]} returns role names of the parent roles, if there are none then returns empty array
+     */
+    PermissionUtil.getHierarchyParents = function(pRoleName) {
+        return newSelect("PARENT_ROLE", alias)
+        .from("ASYS_ROLES_CHILDREN")
+        .where("ASYS_ROLES_CHILDREN.CHILD_ROLE", pRoleName)
+        .arrayColumn(true);
+    }
+    
 } //end of block
 
 
-- 
GitLab