From d94655ac0b489f4de4c8ae2a376ab4e0b1bf0f79 Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Mon, 5 Jun 2023 14:34:43 +0200
Subject: [PATCH] ENH: Add function that hides an HTML element for certain
 roles

---
 src/core/js/webcaosdb.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/core/js/webcaosdb.js b/src/core/js/webcaosdb.js
index 1d6d5c83..f2e5e8ec 100644
--- a/src/core/js/webcaosdb.js
+++ b/src/core/js/webcaosdb.js
@@ -41,10 +41,10 @@ var globalError = function (error) {
     // ignore this particular error. It is caused by bootstrap-select which is
     // probably misusing the bootstrap 5 API.
     if (error.toString().startsWith("TypeError: this._element is undefined")) {
-      if (error && error.stack)
-        stack = "" + error.stack;
+        if (error && error.stack)
+            stack = "" + error.stack;
         if (stack.indexOf("dataApiKeydownHandler") > 0) {
-          return;
+            return;
         }
     }
 
@@ -306,6 +306,19 @@ this.navbar = new function () {
         }
     }
 
+    this.hideElementForRoles = function (name, roles) {
+        var elt = name;
+        if (typeof (name) === "string") {
+            elt = $(elt);
+        }
+        const userRoles = getUserRoles();
+        if (userRoles.some(role => roles.includes(role))) {
+            elt.addClass("d-none");
+        } else {
+            elt.removeClass("d-none");
+        }
+    }
+
 }
 
 
-- 
GitLab