From 7f4dbfc007fdf2b69400d60d88d96800397ce2e1 Mon Sep 17 00:00:00 2001
From: Simon Leipold <s.leipold@adito.de>
Date: Fri, 10 Jan 2020 15:09:18 +0100
Subject: [PATCH] Permissions - bug fix updating roles and role name can not be
 updated anymore

---
 entity/Role_entity/Role_entity.aod                     |  1 +
 .../Role_entity/entityfields/rolename/stateProcess.js  |  9 +++++++++
 entity/Role_entity/recordcontainers/jdito/onUpdate.js  | 10 ++++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 entity/Role_entity/entityfields/rolename/stateProcess.js

diff --git a/entity/Role_entity/Role_entity.aod b/entity/Role_entity/Role_entity.aod
index 39f6b5e727..667568f4c0 100644
--- a/entity/Role_entity/Role_entity.aod
+++ b/entity/Role_entity/Role_entity.aod
@@ -33,6 +33,7 @@
       <name>ROLENAME</name>
       <title>Name</title>
       <mandatory v="true" />
+      <stateProcess>%aditoprj%/entity/Role_entity/entityfields/rolename/stateProcess.js</stateProcess>
     </entityField>
     <entityField>
       <name>USERCOUNT</name>
diff --git a/entity/Role_entity/entityfields/rolename/stateProcess.js b/entity/Role_entity/entityfields/rolename/stateProcess.js
new file mode 100644
index 0000000000..c659870cbd
--- /dev/null
+++ b/entity/Role_entity/entityfields/rolename/stateProcess.js
@@ -0,0 +1,9 @@
+import("system.result");
+import("system.vars");
+import("system.neon");
+
+if (vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT) {
+    result.string(neon.COMPONENTSTATE_READONLY);
+} else {
+    result.string(neon.COMPONENTSTATE_AUTO);
+}
\ No newline at end of file
diff --git a/entity/Role_entity/recordcontainers/jdito/onUpdate.js b/entity/Role_entity/recordcontainers/jdito/onUpdate.js
index d6e58304bb..c549fbcdef 100644
--- a/entity/Role_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/Role_entity/recordcontainers/jdito/onUpdate.js
@@ -1,5 +1,11 @@
 import("system.tools");
 import("system.vars");
 
-var name = vars.get("$field.ROLENAME");  // field got prefix "CUSTOM_" already
-tools.updateRole(name, vars.get("$field.ROLETITLE"), vars.get("$field.ROLEDESCRIPTION"), true, null);
\ No newline at end of file
+var selectedRole = vars.get("$field.ROLENAME"); // field got prefix "CUSTOM_" already
+
+tools.updateRole(selectedRole,
+    vars.get("$field.ROLETITLE"),
+    vars.get("$field.ROLEDESCRIPTION"),
+    vars.get("$field.IS_ASSIGNABLE") == "0" ? false : true,
+    null
+    );
\ No newline at end of file
-- 
GitLab