From 0a17d3d3825e9263a8905b6e5f21f2bf94e1e9c8 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Mon, 18 Nov 2019 10:10:48 +0100
Subject: [PATCH] fix support ticket behaviour if status whitelist is empty

---
 .../recordcontainers/db/conditionProcess.js   | 19 ++++++++++++-------
 process/Ticket_lib/process.js                 |  5 +++--
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
index ba9d5cc9a9..864f3ff831 100644
--- a/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/KeywordEntry_entity/recordcontainers/db/conditionProcess.js
@@ -10,13 +10,18 @@ if (vars.get("$param.OnlyActives_param") == "true")
     cond.and("AB_KEYWORD_ENTRY.ISACTIVE", "1");
 }
 
-if (vars.get("$param.ExcludedKeyIdsSubquery_param"))
-{
-    cond.and("AB_KEYWORD_ENTRY.KEYID not in ( " + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")");
-}
+if (vars.exists("$param.ExcludedKeyIdsSubquery_param") && vars.get("$param.ExcludedKeyIdsSubquery_param"))
+    cond.and("AB_KEYWORD_ENTRY.KEYID", "(" + vars.get("$param.ExcludedKeyIdsSubquery_param") + ")", "not in ?");
 
 if (vars.getString("$param.WhitelistIds_param"))
-    cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN());
+{
+    var whitelist = JSON.parse(vars.getString("$param.WhitelistIds_param"));
+   
+    if (whitelist.length > 0)
+        cond.and("AB_KEYWORD_ENTRY.KEYID", JSON.parse(vars.getString("$param.WhitelistIds_param")), SqlBuilder.IN());
+    else
+        cond.and("1=2"); // force empty result if whitelist is empty
+}
 
-//TODO: use a preparedCondition (.build instead of .toString) when available #1030812 #1034026
-result.string(cond.toString());
\ No newline at end of file
+//TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
+result.string(cond.translate("1 = 1"));
diff --git a/process/Ticket_lib/process.js b/process/Ticket_lib/process.js
index 185c069e60..4a8fa2388a 100644
--- a/process/Ticket_lib/process.js
+++ b/process/Ticket_lib/process.js
@@ -121,9 +121,10 @@ TicketUtils.prototype.getTypeAttributes = function()
  */
 TicketUtils.prototype.getAvailableStatus = function()
 {
-    states = JSON.parse(KeywordUtils.getAttributeRelation(this.type, $KeywordRegistry.ticketType(), "availableStatus", ""))
+    var states = JSON.parse(KeywordUtils.getAttributeRelation(this.type, $KeywordRegistry.ticketType(), "availableStatus", "[]"))
     if (states == null)
-        return "";
+        return [];
+   
     return states;
 }
 
-- 
GitLab