Bug 32721 - Allow specifying UserCSS and UserJS at library level for the OPAC
Summary: Allow specifying UserCSS and UserJS at library level for the OPAC
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Matt Blenkinsop
QA Contact: Nick Clemens (kidclamp)
URL:
Keywords:
: 20320 (view as bug list)
Depends on:
Blocks: 34536 34537 35530 34464 36916
  Show dependency treegraph
 
Reported: 2023-01-25 11:55 UTC by Matt Blenkinsop
Modified: 2024-05-22 08:30 UTC (History)
11 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact: Caroline Cyr La Rose
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/802
Text to go in the release notes:
With this feature it's possible to add library specific CSS and JavaScript on the library administration pages. This works in combination with the global '*UserJS' and '*UserCSS' functionality and allows for multiple OPACs with different CSS and JavaScript customizations.
Version(s) released in:
23.11.00
Circulation function:


Attachments
Bug 32721: Add branch specific userjs and usercss (10.88 KB, patch)
2023-01-27 12:54 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Database update to add userjs and usercss to branches table (3.34 KB, patch)
2023-01-27 12:56 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: DBIC Schema (1.66 KB, patch)
2023-01-27 12:58 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Add unit tests (1.81 KB, patch)
2023-01-27 13:00 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Tidy up - duplicate fetching of userjs and css (3.40 KB, patch)
2023-01-27 13:02 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (4.90 KB, patch)
2023-01-27 14:52 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (5.51 KB, patch)
2023-01-27 15:49 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Add branch specific userjs and usercss (10.90 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: Database update to add userjs and usercss to branches table (3.37 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: DBIC Schema (1.70 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: Add unit tests (1.84 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: Tidy up - duplicate fetching of userjs and css (3.44 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (3.58 KB, patch)
2023-02-03 17:33 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add missing imports (4.44 KB, patch)
2023-02-24 17:06 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Add branch specific userjs and usercss (10.91 KB, patch)
2023-04-19 10:45 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Database update to add userjs and usercss to branches table (3.38 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: DBIC Schema (1.71 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Add unit tests (1.86 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Tidy up - duplicate fetching of userjs and css (3.29 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (3.60 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add missing imports (4.41 KB, patch)
2023-04-19 10:46 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Highlight the branch specific option from the global syspref (1.68 KB, patch)
2023-05-05 08:27 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: Add branch specific userjs and usercss (10.95 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: Database update to add userjs and usercss to branches table (3.42 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: DBIC Schema (1.75 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: Add unit tests (1.90 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: Tidy up - duplicate fetching of userjs and css (3.33 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (3.63 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add missing imports (4.45 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: Highlight the branch specific option from the global syspref (1.74 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests (3.09 KB, patch)
2023-05-05 11:23 UTC, Nick Clemens (kidclamp)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests (3.16 KB, patch)
2023-05-05 14:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Drop fields from API response (1.42 KB, patch)
2023-05-05 14:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Rename fields to opac* (10.77 KB, patch)
2023-05-05 14:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: DBIC Schema update (1.59 KB, patch)
2023-05-05 14:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Fix rebase errors (1.85 KB, patch)
2023-05-05 14:14 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 32721: Add branch specific userjs and usercss (10.81 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Database update to add userjs and usercss to branches table (3.44 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: DBIC Schema (1.84 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Add unit tests (1.91 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow up) - fix QA issues (10.40 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: Highlight the branch specific option from the global syspref (1.75 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests (3.18 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Drop fields from API response (13.10 KB, patch)
2023-09-25 13:33 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 32721: (QA follow-up) Drop fields from API response (12.55 KB, patch)
2023-10-18 14:57 UTC, Matt Blenkinsop
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Blenkinsop 2023-01-25 11:55:32 UTC
It would be useful to be able to add UserCSS and JS at branch level rather than globally across all OPACs. This will improve customisation and streamline the way we inject the UserJS and UserCSS into the templates.
Comment 1 Matt Blenkinsop 2023-01-27 12:54:34 UTC
Created attachment 145731 [details] [review]
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
Comment 2 Matt Blenkinsop 2023-01-27 12:56:54 UTC
Created attachment 145732 [details] [review]
Bug 32721: Database update to add userjs and usercss to branches table

This patch adds the columns for userjs and usercss to the branches table

Test plan as per previous commit
Comment 3 Matt Blenkinsop 2023-01-27 12:58:30 UTC
Created attachment 145733 [details] [review]
Bug 32721: DBIC Schema

This commit adds the DBIC Schema for the database change
Comment 4 Matt Blenkinsop 2023-01-27 13:00:40 UTC
Created attachment 145734 [details] [review]
Bug 32721: Add unit tests

Unit tests to test two new functions: GetBranchSpecificJS and GetBranchSpecificCSS

Test plan:
1) In the shell run prove -t t/db_dependent/Template/Plugin/Branches.t
Comment 5 Matt Blenkinsop 2023-01-27 13:02:40 UTC
Created attachment 145735 [details] [review]
Bug 32721: Tidy up - duplicate fetching of userjs and css

Currently UserJS and UserCSS is injected into the template as a parameter through Auth.pm but is then fetched using Koha.Preference() in the template. This patch tidies this up by removing the parameters from Auth.pm

Test plan as per first commit
Comment 6 Owen Leonard 2023-01-27 13:26:44 UTC
This appears to work well, but there are a few issues raised by the QA tool which need to be addressed.
Comment 7 Matt Blenkinsop 2023-01-27 14:52:16 UTC
Created attachment 145754 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests.
Comment 8 Matt Blenkinsop 2023-01-27 15:49:55 UTC
Created attachment 145759 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests. It also adds a missed import of the Branches file in the document head
Comment 9 Lucas Gass (lukeg) 2023-02-01 00:09:56 UTC
Im confused by this step:

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)

If I log out of the OPAC I should be seeing the branch level JS/CSS?
Comment 10 Matt Blenkinsop 2023-02-01 09:20:25 UTC
Hi Lucas, if you are logged in then your user will have a default branch - you should see the UserJs and CSS for that patron branch which may be different to the branch that you set in your Apache config.

For example if you set the OPAC as having a default code of FPL and you are logged into the OPAC with a patron that has a branch code of CPL, you will see the settings for CPL and not FPL as the patron will override the default. Therefore you would need to log out to see your UserJS and CSS changes for the FPL branch. 

You can also set specific UserJS and CSS for the CPL branch and that will appear when you are logged in as a CPL user.

Hope that makes sense!
Comment 11 Lucas Gass (lukeg) 2023-02-03 17:33:10 UTC
Created attachment 146159 [details] [review]
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>
Comment 12 Lucas Gass (lukeg) 2023-02-03 17:33:14 UTC
Created attachment 146160 [details] [review]
Bug 32721: Database update to add userjs and usercss to branches table

This patch adds the columns for userjs and usercss to the branches table

Test plan as per previous commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 13 Lucas Gass (lukeg) 2023-02-03 17:33:19 UTC
Created attachment 146161 [details] [review]
Bug 32721: DBIC Schema

This commit adds the DBIC Schema for the database change

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 14 Lucas Gass (lukeg) 2023-02-03 17:33:24 UTC
Created attachment 146162 [details] [review]
Bug 32721: Add unit tests

Unit tests to test two new functions: GetBranchSpecificJS and GetBranchSpecificCSS

Test plan:
1) In the shell run prove -t t/db_dependent/Template/Plugin/Branches.t

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 15 Lucas Gass (lukeg) 2023-02-03 17:33:28 UTC
Created attachment 146163 [details] [review]
Bug 32721: Tidy up - duplicate fetching of userjs and css

Currently UserJS and UserCSS is injected into the template as a parameter through Auth.pm but is then fetched using Koha.Preference() in the template. This patch tidies this up by removing the parameters from Auth.pm

Test plan as per first commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 16 Lucas Gass (lukeg) 2023-02-03 17:33:32 UTC
Created attachment 146164 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests. It also adds a missed import of the Branches file in the document head

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 17 Jonathan Druart 2023-02-23 15:17:32 UTC
QA comments:
1. There are still a couple of ref to tinymce in the template
2. Not blocker but it would be nice to see the codemirror code centralised in an include file to avoid code duplication
3. You didn't modify all the occurrences of OPACUserCSS in template, is that on purpose?

koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt:[% IF ( Koha.Preference('OPACUserCSS') ) %]<style>[% Koha.Preference('OPACUserCSS') | $raw %]</style>[% END %]
koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/help.tt:[% IF ( Koha.Preference('OPACUserCSS') ) %]<style>[% Koha.Preference('OPACUserCSS') | $raw %]</style>[% END %]
koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt:[% IF ( Koha.Preference('OPACUserCSS') ) %]<style>[% Koha.Preference('OPACUserCSS') | $raw %]</style>[% END %]

I don't know if it's relevant, just asking.

4. There is one more QA failure
 FAIL   installer/data/mysql/atomicupdate/bug_32721-add_branch_level_js.pl
   FAIL   file permissions
                File must have the exec flag
Comment 18 Matt Blenkinsop 2023-02-24 17:06:00 UTC
Created attachment 147373 [details] [review]
Bug 32721: (QA follow-up) Add missing imports

Missing imports added in three template files
Exec flag added to atomic update file
Tinymce imports removed

A new bug will be created to move codemirror into an inc file at latest
version

Test plan as before
Comment 19 Jonathan Druart 2023-03-22 14:11:23 UTC
I got a conflict on the "Tidy up" patch that I managed to fix, but then another one: error: sha1 information is lacking or useless (koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt).
Comment 20 Matt Blenkinsop 2023-04-19 10:45:59 UTC
Created attachment 149860 [details] [review]
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>
Comment 21 Matt Blenkinsop 2023-04-19 10:46:01 UTC
Created attachment 149861 [details] [review]
Bug 32721: Database update to add userjs and usercss to branches table

This patch adds the columns for userjs and usercss to the branches table

Test plan as per previous commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 22 Matt Blenkinsop 2023-04-19 10:46:04 UTC
Created attachment 149862 [details] [review]
Bug 32721: DBIC Schema

This commit adds the DBIC Schema for the database change

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 23 Matt Blenkinsop 2023-04-19 10:46:07 UTC
Created attachment 149863 [details] [review]
Bug 32721: Add unit tests

Unit tests to test two new functions: GetBranchSpecificJS and GetBranchSpecificCSS

Test plan:
1) In the shell run prove -t t/db_dependent/Template/Plugin/Branches.t

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 24 Matt Blenkinsop 2023-04-19 10:46:12 UTC
Created attachment 149864 [details] [review]
Bug 32721: Tidy up - duplicate fetching of userjs and css

Currently UserJS and UserCSS is injected into the template as a parameter through Auth.pm but is then fetched using Koha.Preference() in the template. This patch tidies this up by removing the parameters from Auth.pm

Test plan as per first commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 25 Matt Blenkinsop 2023-04-19 10:46:15 UTC
Created attachment 149865 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests. It also adds a missed import of the Branches file in the document head

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 26 Matt Blenkinsop 2023-04-19 10:46:18 UTC
Created attachment 149866 [details] [review]
Bug 32721: (QA follow-up) Add missing imports

Missing imports added in three template files
Exec flag added to atomic update file
Tinymce imports removed

A new bug will be created to move codemirror into an inc file at latest
version

Test plan as before
Comment 27 Matt Blenkinsop 2023-04-19 10:47:18 UTC
Rebased - resetting to Signed off as previous status
Comment 28 Martin Renvoize (ashimema) 2023-05-05 08:27:38 UTC
Created attachment 150713 [details] [review]
Bug 32721: Highlight the branch specific option from the global syspref

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 29 Nick Clemens (kidclamp) 2023-05-05 11:23:08 UTC
Created attachment 150724 [details] [review]
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>
Comment 30 Nick Clemens (kidclamp) 2023-05-05 11:23:11 UTC
Created attachment 150725 [details] [review]
Bug 32721: Database update to add userjs and usercss to branches table

This patch adds the columns for userjs and usercss to the branches table

Test plan as per previous commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 31 Nick Clemens (kidclamp) 2023-05-05 11:23:13 UTC
Created attachment 150726 [details] [review]
Bug 32721: DBIC Schema

This commit adds the DBIC Schema for the database change

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 32 Nick Clemens (kidclamp) 2023-05-05 11:23:16 UTC
Created attachment 150727 [details] [review]
Bug 32721: Add unit tests

Unit tests to test two new functions: GetBranchSpecificJS and GetBranchSpecificCSS

Test plan:
1) In the shell run prove -t t/db_dependent/Template/Plugin/Branches.t

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 33 Nick Clemens (kidclamp) 2023-05-05 11:23:18 UTC
Created attachment 150728 [details] [review]
Bug 32721: Tidy up - duplicate fetching of userjs and css

Currently UserJS and UserCSS is injected into the template as a parameter through Auth.pm but is then fetched using Koha.Preference() in the template. This patch tidies this up by removing the parameters from Auth.pm

Test plan as per first commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 34 Nick Clemens (kidclamp) 2023-05-05 11:23:21 UTC
Created attachment 150729 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests. It also adds a missed import of the Branches file in the document head

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 35 Nick Clemens (kidclamp) 2023-05-05 11:23:23 UTC
Created attachment 150730 [details] [review]
Bug 32721: (QA follow-up) Add missing imports

Missing imports added in three template files
Exec flag added to atomic update file
Tinymce imports removed

A new bug will be created to move codemirror into an inc file at latest
version

Test plan as before

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 36 Nick Clemens (kidclamp) 2023-05-05 11:23:26 UTC
Created attachment 150731 [details] [review]
Bug 32721: Highlight the branch specific option from the global syspref

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 37 Nick Clemens (kidclamp) 2023-05-05 11:23:28 UTC
Created attachment 150732 [details] [review]
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests

Added tests for case of no branch specific settings and when no branch passed

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 38 Nick Clemens (kidclamp) 2023-05-05 11:28:16 UTC
One question: You add the fields to the api, do we want them? They feel like they may be somewhat Koha specific, not needed for outside connections?
Comment 39 Nick Clemens (kidclamp) 2023-05-05 12:54:30 UTC
One more question: should these be 'opacuserjs' and 'opacusercss' in the case of implementing the same feature in the staff client?
Comment 40 Martin Renvoize (ashimema) 2023-05-05 13:37:57 UTC
Comment on attachment 150728 [details] [review]
Bug 32721: Tidy up - duplicate fetching of userjs and css

Review of attachment 150728 [details] [review]:
-----------------------------------------------------------------

::: C4/Auth.pm
@@ +1364,5 @@
> +        OpacCloud                             => C4::Context->preference("OpacCloud"),
> +        OpacTopissue                          => C4::Context->preference("OpacTopissue"),
> +        OpacAuthorities                       => C4::Context->preference("OpacAuthorities"),
> +        OpacBrowser                           => C4::Context->preference("OpacBrowser"),
> +        TagsEnabled                           => C4::Context->preference("TagsEnabled"),

Were these deliberately added.. they feel like a rebase mistake to me?
Comment 41 Martin Renvoize (ashimema) 2023-05-05 13:39:50 UTC
(In reply to Nick Clemens from comment #38)
> One question: You add the fields to the api, do we want them? They feel like
> they may be somewhat Koha specific, not needed for outside connections?

Hmm, I agree.. we perhaps don't need to add them in.. instead we could map them to undef to drop them in API responses
Comment 42 Martin Renvoize (ashimema) 2023-05-05 13:40:09 UTC
(In reply to Nick Clemens from comment #39)
> One more question: should these be 'opacuserjs' and 'opacusercss' in the
> case of implementing the same feature in the staff client?

You're probably right there too
Comment 43 Martin Renvoize (ashimema) 2023-05-05 14:14:15 UTC
Created attachment 150754 [details] [review]
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests

Added tests for case of no branch specific settings and when no branch passed

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 44 Martin Renvoize (ashimema) 2023-05-05 14:14:18 UTC
Created attachment 150755 [details] [review]
Bug 32721: (QA follow-up) Drop fields from API response

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 45 Martin Renvoize (ashimema) 2023-05-05 14:14:22 UTC
Created attachment 150756 [details] [review]
Bug 32721: (QA follow-up) Rename fields to opac*

This patch updates the field names to reflect that they're OPAC
related.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 46 Martin Renvoize (ashimema) 2023-05-05 14:14:25 UTC
Created attachment 150757 [details] [review]
Bug 32721: DBIC Schema update

Update after field change
Comment 47 Martin Renvoize (ashimema) 2023-05-05 14:14:29 UTC
Created attachment 150758 [details] [review]
Bug 32721: (QA follow-up) Fix rebase errors

We let some superflous template params creep back in during a rebase
somewhere.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 48 Martin Renvoize (ashimema) 2023-05-05 14:15:22 UTC
Matt's on leave at the minute, so I took care of the thoughts raised by Nick..

They all made sense to me.

Back to PQA
Comment 49 Matt Blenkinsop 2023-05-16 08:27:42 UTC
Thanks Martin and Nick!
Comment 50 David Cook 2023-08-03 04:45:23 UTC
+1 for UserCSS but I'm thinking that we might want to start killing off UserJS...
Comment 51 Tomás Cohen Arazi (tcohen) 2023-09-22 15:16:37 UTC
Please, rebase ASAP.

- Squash the patches as appropriate.
- Leave the DBIC schema update as a single/separate commit we can drop if it doesn't apply due to later changes
Comment 52 Matt Blenkinsop 2023-09-25 13:33:19 UTC
Created attachment 156157 [details] [review]
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>
Comment 53 Matt Blenkinsop 2023-09-25 13:33:23 UTC
Created attachment 156158 [details] [review]
Bug 32721: Database update to add userjs and usercss to branches table

This patch adds the columns for userjs and usercss to the branches table

Test plan as per previous commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 54 Matt Blenkinsop 2023-09-25 13:33:26 UTC
Created attachment 156159 [details] [review]
Bug 32721: DBIC Schema

This commit adds the DBIC Schema for the database change

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 32721: DBIC Schema update

Update after field change
Comment 55 Matt Blenkinsop 2023-09-25 13:33:30 UTC
Created attachment 156160 [details] [review]
Bug 32721: Add unit tests

Unit tests to test two new functions: GetBranchSpecificJS and GetBranchSpecificCSS

Test plan:
1) In the shell run prove -t t/db_dependent/Template/Plugin/Branches.t

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 56 Matt Blenkinsop 2023-09-25 13:33:33 UTC
Created attachment 156161 [details] [review]
Bug 32721: (QA follow up) - fix QA issues

This patches addresses issues raised by the QA tests. It also adds a missed import of the Branches file in the document head

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 32721: (QA follow-up) Add missing imports

Missing imports added in three template files
Exec flag added to atomic update file
Tinymce imports removed

A new bug will be created to move codemirror into an inc file at latest
version

Test plan as before

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Bug 32721: Tidy up - duplicate fetching of userjs and css

Currently UserJS and UserCSS is injected into the template as a parameter through Auth.pm but is then fetched using Koha.Preference() in the template. This patch tidies this up by removing the parameters from Auth.pm

Test plan as per first commit

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 57 Matt Blenkinsop 2023-09-25 13:33:36 UTC
Created attachment 156162 [details] [review]
Bug 32721: Highlight the branch specific option from the global syspref

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 58 Matt Blenkinsop 2023-09-25 13:33:39 UTC
Created attachment 156163 [details] [review]
Bug 32721: (QA follow-up) Add exec flag to DB update and expand tests

Added tests for case of no branch specific settings and when no branch passed

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 59 Matt Blenkinsop 2023-09-25 13:33:43 UTC
Created attachment 156164 [details] [review]
Bug 32721: (QA follow-up) Drop fields from API response

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 32721: (QA follow-up) Rename fields to opac*

This patch updates the field names to reflect that they're OPAC
related.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 32721: (QA follow-up) Fix rebase errors

We let some superflous template params creep back in during a rebase
somewhere.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 60 Matt Blenkinsop 2023-09-25 13:34:25 UTC
Rebased

DBIC left in a separate commit and patches squashed where appropriate
Comment 61 Katrin Fischer 2023-10-01 21:37:46 UTC
*** Bug 20320 has been marked as a duplicate of this bug. ***
Comment 62 Tomás Cohen Arazi (tcohen) 2023-10-18 11:46:29 UTC
The last follow-up contains this change which doesn't seem correct:

+++ b/C4/Auth.pm
@@ -1372,14 +1372,6 @@ sub checkauth {
         OpacFavicon                           => C4::Context->preference("OpacFavicon"),
         opacreadinghistory                    => C4::Context->preference("opacreadinghistory"),
         opaclanguagesdisplay                  => C4::Context->preference("opaclanguagesdisplay"),
-        opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
-        OpacCloud                             => C4::Context->preference("OpacCloud"),
-        OpacTopissue                          => C4::Context->preference("OpacTopissue"),
-        OpacAuthorities                       => C4::Context->preference("OpacAuthorities"),
-        OpacBrowser                           => C4::Context->preference("OpacBrowser"),
-        TagsEnabled                           => C4::Context->preference("TagsEnabled"),
-        OPACUserJS                            => C4::Context->preference("OPACUserJS"),
-        OPACUserCSS                           => C4::Context->preference("OPACUserCSS"),
         intranetcolorstylesheet               => C4::Context->preference("intranetcolorstylesheet"),
         intranetstylesheet                    => C4::Context->preference("intranetstylesheet"),
         IntranetNav                           => C4::Context->preference("IntranetNav"),

I still think we should've implemented bug 26129, and use it for this cases. But I abandoned it so I won't block this.
Comment 63 Matt Blenkinsop 2023-10-18 14:57:08 UTC
Created attachment 157335 [details] [review]
Bug 32721: (QA follow-up) Drop fields from API response

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 32721: (QA follow-up) Rename fields to opac*

This patch updates the field names to reflect that they're OPAC
related.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Bug 32721: (QA follow-up) Fix rebase errors

We let some superflous template params creep back in during a rebase
somewhere.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 64 Matt Blenkinsop 2023-10-18 14:57:55 UTC
Just fixed that commit to only remove OPACUserJS and OPACUserCSS - should be good to go now
Comment 65 Tomás Cohen Arazi (tcohen) 2023-10-19 19:02:13 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 66 Fridolin Somers 2023-10-25 20:59:29 UTC
Enhancement not pushed to 23.05.x
Comment 67 Fridolin Somers 2023-10-25 21:09:23 UTC
I add a release note, feel free to modify
Comment 68 Fridolin Somers 2023-10-25 21:39:52 UTC
BTW : 
It would be nice to add library option to plugin hook adding JS and CSS, right ?
Hook added by Bug 20181

Currently one can use, for OPAC, selector "body.branch-LIBRARY"
Comment 69 Katrin Fischer 2023-12-10 15:13:35 UTC
From the GUI it's not obvious that the new options are for the OPAC - was this intentional?
Comment 70 Katrin Fischer 2023-12-10 15:17:09 UTC
(In reply to Nick Clemens from comment #39)
> One more question: should these be 'opacuserjs' and 'opacusercss' in the
> case of implementing the same feature in the staff client?

It was not changed/updated in the end, I filed:
Bug 35530 - Can't tell if UserCSS and UserJS in ibraries are for staff interface or OPAC