Bug 32721: Add branch specific userjs and usercss
authorMatt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Fri, 27 Jan 2023 12:34:39 +0000 (12:34 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 19 Oct 2023 19:00:52 +0000 (16:00 -0300)
commit82e2547e1b5d9d056d7aac88e02db948cbe3c1a5
treed8d532362cf7a930e1365442e3813a58eeb86d9e
parent7e23abcccb4868637d542147f25e6ca437ec5622
Bug 32721: Add branch specific userjs and usercss

This patch allows for branch specific userJS and userCSS to be added through the libraries table. This works in conjunction with the global UserJS and UserCSS functionality and allows for multiple OPACs with different css and js options.

Test plan:
1) Add to apache conf (/etc/apache2/sites-available/kohadev.conf)
    SetEnv OPAC_BRANCH_DEFAULT "FFL"
    RequestHeader add X-Koha-SetEnv "OPAC_BRANCH_DEFAULT FFL"
2) In the container, run restart_all
3) Navigate to the OPACUserJS and OPACUserCSS system preferences and add the following: OPACUserJS - console.log('Hello from global sysprefs');, OPACUserCSS - 'body { background-color: black; }'
4) Refresh the OPAC and the background should be black and the message should be logged to the console in developer tools
5) Navigate to Administration > Libraries
6) On the Fairfield branch (if this does not exist you will need to create a branch with a code matching the code that you added to the apache conf file), click edit
7) At the bottom there should be two fields to add userjs and usercss, complete with Codemirror syntax checking
8) In userjs add console.log('Hello from branch level'); and in usercss add 'body { background-color: blue; } then save
9) Return to the OPAC and refresh
10) If you are logged out of the OPAC it should now be logging both the message from global and from the branch level and the background should be blue (if not you will need to log out)
11) Log back into the OPAC using a user that DOES NOT have a default branch matching the branch you added to the Apache conf
12) The OPAC should now revert to only showing the global message in the console with a black background

Sponsored-by: PTFS Europe
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Template/Plugin/Branches.pm
admin/branches.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc