From e4e1e42c4b9e999f3a01be05ac7b4c17e3a4a44b Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Fri, 7 Feb 2020 12:08:50 +0100
Subject: [PATCH] Employee_entity: grantDelete

---
 entity/Employee_entity/grantDeleteProcess.js      | 15 +++++++++++++--
 .../recordcontainers/jdito/onDelete.js            |  2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/entity/Employee_entity/grantDeleteProcess.js b/entity/Employee_entity/grantDeleteProcess.js
index e1d6c3c3c6..d817b2a09e 100644
--- a/entity/Employee_entity/grantDeleteProcess.js
+++ b/entity/Employee_entity/grantDeleteProcess.js
@@ -2,5 +2,16 @@ import("Employee_lib");
 import("Document_lib");
 import("system.vars");
 import("system.result");
-// TODO: Commented because of performance problems: in Filter view this Process is called for every row. Waiting for bugfix
-//result.string(!DocumentUtil.hasDocuments("EMPLOYEE", null, EmployeeUtils.sliceUserId(vars.get("$field.UID"))));
\ No newline at end of file
+
+var res = false;
+
+//the current user should not delete himself
+if (EmployeeUtils.getCurrentUserName() != vars.get("$field.TITLE") 
+    && !EmployeeUtils.hasRelations(vars.get("$field.CONTACT_ID")) 
+    && !DocumentUtil.hasDocuments("EMPLOYEE", null, EmployeeUtils.sliceUserId(vars.get("$field.UID")))
+   )
+{
+    res = true;
+}
+
+result.string(res);
\ No newline at end of file
diff --git a/entity/Employee_entity/recordcontainers/jdito/onDelete.js b/entity/Employee_entity/recordcontainers/jdito/onDelete.js
index 212b6d2313..ab759edc01 100644
--- a/entity/Employee_entity/recordcontainers/jdito/onDelete.js
+++ b/entity/Employee_entity/recordcontainers/jdito/onDelete.js
@@ -3,6 +3,6 @@ import("system.vars");
 import("system.tools");
 import("Employee_lib");
 
-//TODO: the current user should not delete himself, put this condition in grantDelete when available
+//the current user should not delete himself
 if (EmployeeUtils.getCurrentUserName() != vars.get("$field.TITLE") && !EmployeeUtils.hasRelations(vars.get("$field.CONTACT_ID")))
     tools.deleteUser(vars.get("$field.TITLE"));
\ No newline at end of file
-- 
GitLab