From ae442f2de8ffaaf4d45abd2e8b5c4b6a517b9b58 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 18 Dec 2024 11:15:36 -0300 Subject: [PATCH] Bug 28478: Make opac-*detail.pl scripts use Koha::Biblio->opac_suppressed() This patch makes the following scripts use the new method for checking suppression: * opac/opac-ISBDdetail.pl * opac/opac-MARCdetail.pl * opac/opac-detail.pl In the `opac-detail.pl` case, it is a simple change by removing MARC data traversal in favor of the new method. The code checking suppression gets moved up so we don't process or make any other calculations if the record is suppressed. The other two scripts where completely missing the check and thus leaking suppressed records. To test: 1. Pick two records, one marked as suppressed, and the other not suppressed. 2. Try acessing them in the OPAC detail page. => SUCCESS: Suppressed records are suppressed, and not suppressed ones are not. 3. Try the same records on the ISBD and MARC view => FAIL: They are not suppressed! 4. Apply this patch 5. Repeat 2 => SUCCESS: Suppression is still respected 6. Repeat 3 => SUCCESS: Suppression is respected on the ISBD and MARC views 7. Sign off :-D Signed-off-by: Magnus Enger Works as advertised. Remember to activate OPAC suppression with OpacSuppression. Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Alex Buckley (cherry picked from commit 5b775aee691268a17bdf39739e0db83eb269116c) Signed-off-by: Fridolin Somers --- opac/opac-ISBDdetail.pl | 27 +++++++++++++++++++ opac/opac-MARCdetail.pl | 27 +++++++++++++++++++ opac/opac-detail.pl | 58 +++++++++++++++++++---------------------- 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index a70d2ccf76..88317276c0 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -76,6 +76,33 @@ if( !$biblio ) { exit; } +# If record should be suppressed, handle it early +if ( C4::Context->preference('OpacSuppression') ) { + + # redirect to opac-blocked info page or 404? + my $redirect_url; + if ( C4::Context->preference("OpacSuppressionRedirect") ) { + $redirect_url = "/cgi-bin/koha/opac-blocked.pl"; + } else { + $redirect_url = "/cgi-bin/koha/errors/404.pl"; + } + if ( $biblio->opac_suppressed() ) { + + # if OPAC suppression by IP address + if ( C4::Context->preference('OpacSuppressionByIPRange') ) { + my $IPAddress = $ENV{'REMOTE_ADDR'}; + my $IPRange = C4::Context->preference('OpacSuppressionByIPRange'); + if ( $IPAddress !~ /^$IPRange/ ) { + print $query->redirect($redirect_url); + exit; + } + } else { + print $query->redirect($redirect_url); + exit; + } + } +} + #open template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 406d2d4ceb..2710de2fa8 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -99,6 +99,33 @@ if ( ! $record ) { exit; } +# If record should be suppressed, handle it early +if ( C4::Context->preference('OpacSuppression') ) { + + # redirect to opac-blocked info page or 404? + my $redirect_url; + if ( C4::Context->preference("OpacSuppressionRedirect") ) { + $redirect_url = "/cgi-bin/koha/opac-blocked.pl"; + } else { + $redirect_url = "/cgi-bin/koha/errors/404.pl"; + } + if ( $biblio->opac_suppressed() ) { + + # if OPAC suppression by IP address + if ( C4::Context->preference('OpacSuppressionByIPRange') ) { + my $IPAddress = $ENV{'REMOTE_ADDR'}; + my $IPRange = C4::Context->preference('OpacSuppressionByIPRange'); + if ( $IPAddress !~ /^$IPRange/ ) { + print $query->redirect($redirect_url); + exit; + } + } else { + print $query->redirect($redirect_url); + exit; + } + } +} + unless ( $patron and $patron->category->override_hidden_items ) { # only skip this check if there's a logged in user # and its category overrides OpacHiddenItems diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 36c2670b2a..14ce8aea5b 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -112,6 +112,33 @@ unless ( $biblio && $record ) { exit; } +# If record should be suppressed, handle it early +if ( C4::Context->preference('OpacSuppression') ) { + + # redirect to opac-blocked info page or 404? + my $redirect_url; + if ( C4::Context->preference("OpacSuppressionRedirect") ) { + $redirect_url = "/cgi-bin/koha/opac-blocked.pl"; + } else { + $redirect_url = "/cgi-bin/koha/errors/404.pl"; + } + if ( $biblio->opac_suppressed() ) { + + # if OPAC suppression by IP address + if ( C4::Context->preference('OpacSuppressionByIPRange') ) { + my $IPAddress = $ENV{'REMOTE_ADDR'}; + my $IPRange = C4::Context->preference('OpacSuppressionByIPRange'); + if ( $IPAddress !~ /^$IPRange/ ) { + print $query->redirect($redirect_url); + exit; + } + } else { + print $query->redirect($redirect_url); + exit; + } + } +} + my $items = $biblio->items->search_ordered; if ($specific_item) { $items = $items->search( { itemnumber => scalar $query->param('itemnumber') } ); @@ -140,37 +167,6 @@ my $record_processor = Koha::RecordProcessor->new({ }); $record_processor->process($record); -# redirect if opacsuppression is enabled and biblio is suppressed -if (C4::Context->preference('OpacSuppression')) { - # FIXME hardcoded; the suppression flag ought to be materialized - # as a column on biblio or the like - my $opacsuppressionfield = '942'; - my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield); - # redirect to opac-blocked info page or 404? - my $opacsuppressionredirect; - if ( C4::Context->preference("OpacSuppressionRedirect") ) { - $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl"; - } else { - $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl"; - } - if ( $opacsuppressionfieldvalue && - $opacsuppressionfieldvalue->subfield("n") && - $opacsuppressionfieldvalue->subfield("n") == 1) { - # if OPAC suppression by IP address - if (C4::Context->preference('OpacSuppressionByIPRange')) { - my $IPAddress = $ENV{'REMOTE_ADDR'}; - my $IPRange = C4::Context->preference('OpacSuppressionByIPRange'); - if ($IPAddress !~ /^$IPRange/) { - print $query->redirect($opacsuppressionredirect); - exit; - } - } else { - print $query->redirect($opacsuppressionredirect); - exit; - } - } -} - $template->param( biblio => $biblio );