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

[Projekt: Entwicklung - Neon][TicketNr.: 1049945][Rollen - Fehler bei Zuweisung von Kindrollen]

parent 15187ddc
No related branches found
No related tags found
No related merge requests found
......@@ -126,6 +126,7 @@
</entityField>
<entityConsumer>
<name>RoleChildrens</name>
<onValidation>%aditoprj%/entity/Role_entity/entityfields/rolechildrens/onValidation.js</onValidation>
<dependency>
<name>dependency</name>
<entityName>RoleChildren_entity</entityName>
......
import("system.result");
import("Sql_lib");
import("system.logging");
import("system.vars");
var changedRows = vars.get("$field.RoleChildrens.changedRows");
var insertedRows = vars.get("$field.RoleChildrens.insertedRows");
// check for duplicates
for each (let row in insertedRows) {
if (isRoleAlreadyChildren(row)) {
result.string("No duplicates allowed!");
}
}
for each (let row in changedRows) {
if (isRoleAlreadyChildren(row)) {
result.string("No duplicates allowed!");
}
}
function isRoleAlreadyChildren(pRole) {
var alias = SqlUtils.getSystemAlias();
var parentRoleName = vars.get("$field.ROLENAME")
var childRoles = newSelect("CHILD_ROLE", alias)
.from("ASYS_ROLES_CHILDREN")
.where("ASYS_ROLES_CHILDREN.PARENT_ROLE", parentRoleName)
.table();
// check for duplicates in database
for each (let child in childRoles) {
if (child == pRole.CHILD_ROLE) {
return true;
}
}
// check for duplicate in changed or inserted rows
if (checkDuplicateInObject("CHILD_ROLE", changedRows) || checkDuplicateInObject("CHILD_ROLE", insertedRows))
return true;
// crosscheck for duplicates in inserted and changed rows
for each (let insRow in insertedRows) {
for each (let chaRow in changedRows) {
if (insRow.CHILD_ROLE == chaRow.CHILD_ROLE) {
return true;
}
}
}
return false;
}
function checkDuplicateInObject(propertyName, inputArray) {
var seenDuplicate = false,
testObject = {};
inputArray.map(function(item) {
var itemPropertyName = item[propertyName];
if (itemPropertyName in testObject) {
testObject[itemPropertyName].duplicate = true;
item.duplicate = true;
seenDuplicate = true;
}
else {
testObject[itemPropertyName] = item;
delete item.duplicate;
}
});
return seenDuplicate;
}
\ 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