From 123ed0122e052a15ac626cfcd466e9cde0b7133c Mon Sep 17 00:00:00 2001
From: Simon Leipold <s.leipold@adito.de>
Date: Wed, 4 Mar 2020 15:15:27 +0100
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201048120][L=C3=B6schen=20einer=20Rolle=20entfernt=20nicht=20d?=
 =?UTF-8?q?ie=20zugeh=C3=B6rigen=20Permissions]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 entity/Role_entity/Role_entity.aod            |  1 +
 .../stateProcess.js                           | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 entity/Role_entity/entityfields/deleteeverythinglinkedtorole/stateProcess.js

diff --git a/entity/Role_entity/Role_entity.aod b/entity/Role_entity/Role_entity.aod
index 023fd014cc..8e6196406f 100644
--- a/entity/Role_entity/Role_entity.aod
+++ b/entity/Role_entity/Role_entity.aod
@@ -150,6 +150,7 @@
       <title>delete linked permissions and hierarchies</title>
       <onActionProcess>%aditoprj%/entity/Role_entity/entityfields/deleteeverythinglinkedtorole/onActionProcess.js</onActionProcess>
       <iconId>VAADIN:CLOSE</iconId>
+      <stateProcess>%aditoprj%/entity/Role_entity/entityfields/deleteeverythinglinkedtorole/stateProcess.js</stateProcess>
     </entityActionField>
     <entityConsumer>
       <name>RoleParents</name>
diff --git a/entity/Role_entity/entityfields/deleteeverythinglinkedtorole/stateProcess.js b/entity/Role_entity/entityfields/deleteeverythinglinkedtorole/stateProcess.js
new file mode 100644
index 0000000000..0b7b5d057e
--- /dev/null
+++ b/entity/Role_entity/entityfields/deleteeverythinglinkedtorole/stateProcess.js
@@ -0,0 +1,20 @@
+import("system.logging");
+import("system.neon");
+import("system.result");
+import("system.vars");
+import("Permission_lib");
+
+// action enabled if role has permissions or is part of hierarchy
+// if role is deletable -> disable action
+var roleName = vars.get("$field.ROLENAME");
+var roleType = vars.get("$field.ROLETYPE");
+
+if (roleType == "CUSTOM") {
+    if (PermissionUtil.roleIsDeletable(roleName)) {
+        result.string(neon.COMPONENTSTATE_DISABLED);
+    } else {
+        result.string(neon.COMPONENTSTATE_EDITABLE);
+    }
+} else {
+    result.string(neon.COMPONENTSTATE_INVISIBLE);
+}
-- 
GitLab