From 85318036d9c8b106c6aa94676fb7a49e48d1131c Mon Sep 17 00:00:00 2001 From: Imani Thomas Date: Tue, 18 Feb 2025 17:20:17 +0000 Subject: [PATCH] Bug 39142: Add debug permission to allow user to toggle JS and CSS customizations on/off To test: 1. Apply the patch 2. Use updatedatabase run to update your db 3. Add custom JS and CSS in the IntranetUserJS and IntranetUserCSS fields 4. With a superLibrarian account confirm you have 3 buttons at the bottom of your screen, Disable User JS, Disable User CSS, and load only default stylesheets 5. Clicking the buttons should reload the current page with a query to disable those things. 6. Log in as a user that is not a superlibrarian and does not have the debug UI permission enabled 7. Confirm the buttons are no longer visible 8. Add the debug UI permission to the user 9. Confirm the debug buttons are now visible for that user. Signed-off-by: Lari Strand Signed-off-by: Martin Renvoize --- Koha/Template/Plugin/Koha.pm | 20 +++++++++++++++++++ .../prog/en/includes/intranet-bottom.inc | 10 ++++++++++ .../prog/en/includes/permissions.inc | 3 +++ 3 files changed, 33 insertions(+) diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm index 11ed0cecf37..992b1974ecc 100644 --- a/Koha/Template/Plugin/Koha.pm +++ b/Koha/Template/Plugin/Koha.pm @@ -87,6 +87,26 @@ sub MultivaluePreference { return C4::Context->multivalue_preference($pref); } +=head3 debug_flag + +This method checks if the currently logged in user is allowed +access to the new debug ui permission. It should return +0 if no one is logged in or context is unavailable for some other reason + or they do not have the permission +1 if they are a superlibrarian +1<<32 if they do have the permission + +=cut + +sub debug_flag { + return 0 unless C4::Context->userenv(); + return 1 if C4::Context->IsSuperLibrarian(); + my $flags = C4::Context->userenv()->{'flags'}; + my $mask = 1 << 32; + return $flags & $mask; + +} + =head3 CSVDelimiter The delimiter option 'tabs' is stored in the DB as 'tabulation' to avoid issues diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc index 04766d3133d..40dce0dec39 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -186,6 +186,16 @@ [% END %] [% END %] +[% IF Koha.debug_flag %] +
+ + + +
+[% END # IF %] + [% IF ( footerjs ) %] [% INCLUDE js_includes.inc %] [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index 9aae9efba09..d1d7c46ad4f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -90,6 +90,9 @@ [%- CASE 'sip2' -%] Manage the SIP2 module ([% name | html %]) + [%- CASE 'debug' -%] + Display the Debug UI + ([% name | html %]) [%- END -%] [%- END -%] -- 2.51.1