From ecf33c37ca6bc4bda06882d8d940e7f700879159 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 9 Jun 2021 19:29:19 +0000 Subject: [PATCH] Bug 27734: Add OpacHiddenRecordRedirect system preference This patch adds option analogous to OpacSuppressionRedirect for OpacHiddtenItems Test plan: 1. Apply patch 2. Create a bibiliographic record and add an item to it. Note down its biblionumber. It will be later reffered to as . 3. Set system preference OpacHiddenRecordRedirect on 4. Create HTML customization OpacHiddenRecordMessage. Add some placeholder content in it. 5. Enable OpacHiddenItemsHidesRecord and hide a biblio using OpacHiddenItems: biblionumber: [] e.g. biblionumber: [123] 6. Test OpacHiddenRecordRedirect and OpacHiddenRecordMessage to ensure they work as expected 7. Hit these links: http://koha/cgi-bin/koha/opac-detail.pl?biblionumber= http://koha/cgi-bin/koha/opac-MARCdetail.pl?biblionumber= http://koha/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber= 8. When OpacHiddenRecordRedirect set to 404 you get a 404 9. When OpacHiddenRecordRedirect set to 'an explanatory page' you get 'opac-blocked.pl' 10. If you set a message in OpacHiddenRecordMessage it displays on opac-blocked.pl 11. Using preference OpacHiddenItemsExceptions, exclude your patron category 12. Observe the record is no longer blocked when your patron category is excluded --- Koha/AdditionalContents.pm | 2 +- installer/data/mysql/atomicupdate/bug_27734.perl | 9 +++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/includes/html-customization-help.inc | 4 ++++ .../prog/en/modules/admin/preferences/opac.pref | 6 ++++++ .../opac-tmpl/bootstrap/en/modules/opac-blocked.tt | 11 +++++++++-- opac/opac-blocked.pl | 4 ++++ 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_27734.perl diff --git a/Koha/AdditionalContents.pm b/Koha/AdditionalContents.pm index 98a1b162194..e65848565c7 100644 --- a/Koha/AdditionalContents.pm +++ b/Koha/AdditionalContents.pm @@ -170,7 +170,7 @@ sub get_html_customizations_options { 'OpacMaintenanceNotice', 'OPACResultsSidebar', 'OpacSuppressionMessage', 'SCOMainUserBlock', 'SelfCheckInMainUserBlock', 'SelfCheckHelpMessage', 'CatalogConcernHelp', 'CatalogConcernTemplate', 'CookieConsentBar', 'CookieConsentPopup', 'PatronSelfRegistrationAdditionalInstructions', - 'ILLModuleCopyrightClearance' + 'ILLModuleCopyrightClearance', 'OpacHiddenRecordMessage' ]; } diff --git a/installer/data/mysql/atomicupdate/bug_27734.perl b/installer/data/mysql/atomicupdate/bug_27734.perl new file mode 100644 index 00000000000..9c65a21bda2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_27734.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('OpacHiddenRecordRedirect','0','Redirect the opac detail page for records hidden by OpacHiddenItems to an explanatory page (otherwise redirect to 404 error page)','','YesNo') + }); + + NewVersion( $DBversion, 27734, "Add OpacHiddenRecordRedirect preference"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index c3fa93d5041..a2e47247ae8 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -514,6 +514,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacHiddenItems','','','This syspref allows to define custom rules for hiding specific items at the OPAC. See https://wiki.koha-community.org/wiki/OpacHiddenItems for more information.','Textarea'), ('OpacHiddenItemsExceptions','',NULL,'List of borrower categories, separated by comma, that can see items otherwise hidden by OpacHiddenItems','Textarea'), ('OpacHiddenItemsHidesRecord','1','','Hide biblio record when all its items are hidden because of OpacHiddenItems','YesNo'), +('OpacHiddenRecordRedirect','0','Redirect the opac detail page for records hidden by OpacHiddenItems to an explanatory page (otherwise redirect to 404 error page)','','YesNo'), ('OpacHighlightedWords','1','','If Set, then queried words are higlighted in OPAC','YesNo'), ('OPACHoldingsDefaultSortField','first_column','first_column|homebranch|holdingbranch','Default sort field for the holdings table at the OPAC','choice'), ('OpacHoldNotes','0','','Show hold notes on OPAC','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html-customization-help.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html-customization-help.inc index 13730322962..2d5c3107819 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html-customization-help.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html-customization-help.inc @@ -26,6 +26,10 @@
Include this content on the library information page in the OPAC.
+
+ Display the following message on the redirect page for hidden bibliographic records. Depends on the system preferences OpacHiddenItems and OpacHiddenRecordRedirect. +
+
Show this content on the OPAC login form when a patron is not logged in.
Show this content on the OPAC when the OpacMaintenance system preference is enabled.
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index e7645752111..86f5bffdd60 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -681,6 +681,12 @@ OPAC: 0: "Don't hide" 1: Hide - "the bibliographic record when all its items are hidden by OpacHiddenItems." + -
Redirect the opac detail page for hidden records to + - pref: OpacHiddenRecordRedirect + choices: + 1: "an explanatory page ('This record is blocked')." + 0: "the 404 error page ('Not found')." + - "
Display a message on the redirect page for suppressed bibliographic records with HTML customization OpacHiddenRecordMessage." - - pref: OpacAllowPublicListCreation default: 1 diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt index df59d8765db..f3f4cc29688 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE AdditionalContents %] [% SET OpacSuppressionMessage = AdditionalContents.get( location => "OpacSuppressionMessage", lang => lang, library => branchcode || default_branch ) %] +[% SET OpacHiddenRecordMessage = AdditionalContents.get( location => "OpacHiddenRecordMessage", lang => lang, library => branchcode || default_branch ) %] [% PROCESS 'i18n.inc' %] [% PROCESS 'html_helpers.inc' %] [% INCLUDE 'doc-head-open.inc' %] @@ -29,8 +30,14 @@

Record blocked

You are not authorized to view this record.

- [% IF ( OpacSuppressionMessage ) %] -
[% PROCESS koha_news_block news => OpacSuppressionMessage %]
+ [% IF ( OpacSuppressionMessage ) || ( hidden ) %] +
+ [% IF hidden %] + [% PROCESS koha_news_block news => OpacHiddenRecordMessage %] + [% ELSE %] + [% PROCESS koha_news_block news => OpacSuppressionMessage %] + [% END %] +
[% END %]
diff --git a/opac/opac-blocked.pl b/opac/opac-blocked.pl index 27d9ef458b0..64d19ce41c7 100755 --- a/opac/opac-blocked.pl +++ b/opac/opac-blocked.pl @@ -33,4 +33,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); +if ( $query->param('hidden') ) { + $template->param( hidden => 1 ); +} + output_with_http_headers $query, $cookie, $template->output, 'html'; -- 2.34.1