From ee8349712060395fc3fc7f30bc86bcaaffb989e0 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 and OpacHiddenRecordMessage system preferences This patch adds options analogous to OpacSuppressionRedirect and OpacSuppressionMessage for OpacHiddtenItems Test plan: 1 - Apply patch 2 - Test OpacSupressionsRedirect and OpacSuppressionMessage prefs to ensure they work as before 3 - Enable OpacHiddenItemsHidesRecord and hide a biblio using OpacHiddenItems: biblionumber: [303] 3 - Test OpacHiddenRecordRedirect and OpacHiddenRecordMessage to ensure they work as expected 4 - Hit the link: http://localhost:8080/cgi-bin/koha/opac-detail.pl?biblionumber=303 5 - When OpacHiddenRecordRedirect set to 404 you get a 404 6 - When OpacHiddenRecordRedirect set to 'an explanatory page' you get 'opac-blocked.pl' 7 - If you set a message in OpacHiddenRecordMessage it displays on opac-blocked.pl Signed-off-by: marti Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/atomicupdate/bug_27734.perl | 12 ++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 2 ++ .../prog/en/modules/admin/preferences/opac.pref | 9 +++++++++ .../opac-tmpl/bootstrap/en/modules/opac-blocked.tt | 8 +++++++- opac/opac-blocked.pl | 4 ++++ opac/opac-detail.pl | 6 +++++- 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_27734.perl diff --git a/installer/data/mysql/atomicupdate/bug_27734.perl b/installer/data/mysql/atomicupdate/bug_27734.perl new file mode 100644 index 0000000000..990b4b6672 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_27734.perl @@ -0,0 +1,12 @@ +$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') + }); + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('OpacHiddenRecordMessage','','Display this message on the redirect page for hidden biblios','70|10','Textarea') + }); + NewVersion( $DBversion, 27734, "Add OpacHiddenRecordRedirect and OpacHiddenRecordMessage preferences"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 47f81a864e..6bb58248f1 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -491,6 +491,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacHiddenItems','','','This syspref allows to define custom rules for hiding specific items at the OPAC. See http://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'), +('OpacHiddenRecordMessage','','Display this message on the redirect page for hidden biblios','70|10','Textarea'), ('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/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 1be562220e..cf2168d493 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 @@ -641,6 +641,15 @@ 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 the following message on the redirect page for suppressed bibliographic records:" + - pref: OpacHiddenRecordMessage + type: textarea + class: code - - 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 906ebeb7d5..1c7fbafba3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-blocked.tt @@ -3,6 +3,7 @@ [% SET OpacSuppressionMessage = AdditionalContents.get( location => "OpacSuppressionMessage", lang => lang, library => branchcode || default_branch ) %] [% PROCESS 'i18n.inc' %] [% PROCESS 'html_helpers.inc' %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] [% FILTER collapse %] [% t("Record blocked") | html %] › @@ -26,7 +27,12 @@ <div id="opac-blocked-message" class="maincontent"> <h1>Record blocked</h1> <p>You are not authorized to view this record.</p> - [% IF ( OpacSuppressionMessage ) %] + [% IF hidden %] + [% SET OpacBlockedMessage = Koha.Preference("OpacHiddenRecordMessage") %] + [% ELSE %] + [% SET OpacBlockedMessage = Koha.Preference("OpacSuppressionMessage") %] + [% END %] + [% IF ( OpacBlockedMessage ) %] <div id="opacsuppressionmessage"> [% PROCESS koha_news_block news => OpacSuppressionMessage %] </div> diff --git a/opac/opac-blocked.pl b/opac/opac-blocked.pl index a604fefdbd..ac669c2e86 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'; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index e9f188da2b..8e9ec54a39 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -123,7 +123,11 @@ unless ( $patron and $patron->category->override_hidden_items ) { # only skip this check if there's a logged in user # and its category overrides OpacHiddenItems if ( $biblio->hidden_in_opac({ rules => C4::Context->yaml_preference('OpacHiddenItems') }) ) { - print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + if ( C4::Context->preference("OpacHiddenRecordRedirect") ) { + print $query->redirect("/cgi-bin/koha/opac-blocked.pl?hidden=1"); + } else { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + } exit; } if ( $items->count >= 1 ) { -- 2.34.1