From 00e570ca2a1e4f146fde2be42020e97d6ed24b12 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Tue, 1 Nov 2022 23:17:18 +1100
Subject: [PATCH] Updates for 'admin' buttons:

- Make them work like proper links
- Hidden if 'hide_admin_link' customization option is set
- Check for user staff status
---
 .../InvenTree/static/script/inventree/inventree.js |  7 -------
 InvenTree/templates/admin_button.html              | 14 +++++++++++---
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js
index f0d65b9131..0f06ea98ac 100644
--- a/InvenTree/InvenTree/static/script/inventree/inventree.js
+++ b/InvenTree/InvenTree/static/script/inventree/inventree.js
@@ -127,13 +127,6 @@ function inventreeDocReady() {
         loadBrandIcon($(this), $(this).attr('brand_name'));
     });
 
-    // Callback for "admin view" button
-    $('#admin-button, .admin-button').click(function() {
-        var url = $(this).attr('url');
-
-        location.href = url;
-    });
-
     // Display any cached alert messages
     showCachedAlerts();
 
diff --git a/InvenTree/templates/admin_button.html b/InvenTree/templates/admin_button.html
index 221d7f6c8e..abc3d2d91c 100644
--- a/InvenTree/templates/admin_button.html
+++ b/InvenTree/templates/admin_button.html
@@ -1,4 +1,12 @@
+{% load inventree_extras %}
 {% load i18n %}
-<button id='admin-button' title='{% trans "View in administration panel" %}' type='button' class='btn btn-primary admin-button' url='{{ url }}'>
-    <span class='fas fa-user-shield'></span>
-</button>
+
+{% inventree_customize 'hide_admin_link' as hidden %}
+
+{% if not hidden and user.is_staff %}
+<a href='{{ url }}'>
+    <button id='admin-button' href='{{ url }}' title='{% trans "View in administration panel" %}' type='button' class='btn btn-primary admin-button'>
+        <span class='fas fa-user-shield'></span>
+    </button>
+</a>
+{% endif %}