Skip to content
Snippets Groups Projects
Commit df671c04 authored by Sebastian Pongratz's avatar Sebastian Pongratz :ping_pong:
Browse files

Merge branch '1078807_ProjectRoleCustomRoleHierarchy' into '2021.0'

[Projekt: Entwicklung - Neon][TicketNr.: 1078807][[Rollen] PROJECT_Rolle kann...

See merge request xrm/basic!860
parents 6851f79b d13c6e2d
No related branches found
No related tags found
No related merge requests found
......@@ -3,10 +3,16 @@ import("system.tools");
import("system.vars");
import("system.result");
var newChildRoles = [];
var possibleChildRoles = [];
var alias = SqlUtils.getSystemAlias();
var parentRole = vars.get("$param.RoleId_param");
var allCustomAndProjectRoles = tools.getAllRoles(["CUSTOM", "PROJECT"], true);
var roleType = vars.get("$param.RoleType_param");
var allPossibleRoles;
if (roleType && roleType == "PROJECT")
allPossibleRoles = tools.getAllRoles(["PROJECT"], true);
else
allPossibleRoles = tools.getAllRoles(["CUSTOM", "PROJECT"], true);
var childRoles = newSelect("CHILD_ROLE", alias)
.from("ASYS_ROLES_CHILDREN")
......@@ -16,23 +22,15 @@ var childRoles = newSelect("CHILD_ROLE", alias)
var parentIsAlreadyChildOf = newSelect("PARENT_ROLE", alias)
.from("ASYS_ROLES_CHILDREN")
.where("ASYS_ROLES_CHILDREN.CHILD_ROLE", parentRole)
.table();
.arrayColumn();
for each (let role in allCustomAndProjectRoles) {
// dont show current role as possible child in dropdown
if (role[3] != parentRole) {
newChildRoles.push([role[3], role[3]]);
for each (let role in allPossibleRoles) {
// dont add current role as possible child in dropdown
// check for cycles in hierarchy - dont add role which could create a cycle
// e.g. role A can't be child of role B while it is already parent of B
if (role[3] != parentRole && parentIsAlreadyChildOf.indexOf(role[3]) == -1) {
possibleChildRoles.push([role[3], role[3]]);
}
}
// check for cyclces in hierarchy, A can't be child of B while it is already parent of B
for each (let role in parentIsAlreadyChildOf) {
newChildRoles = newChildRoles.filter(function(childRole) {
if (role == childRole[0]) {
return false;
}
return true;
});
}
result.object(newChildRoles.sort());
\ No newline at end of file
result.object(possibleChildRoles.sort());
\ No newline at end of file
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