From e36095975263f5d149ac87f2d163294178135aec 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: Katrin Fischer --- opac/opac-ISBDdetail.pl | 27 ++++++++++++++++++ opac/opac-MARCdetail.pl | 27 ++++++++++++++++++ opac/opac-detail.pl | 61 ++++++++++++++++++----------------------- 3 files changed, 81 insertions(+), 34 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 34b7560b02..0e9b5787ce 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -75,6 +75,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 1f99235f6e..f4a4198459 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -96,6 +96,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; + } + } +} + unless ( $patron and $patron->category->override_hidden_items ) { # only skip this check if there's a logged in user diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b7680060c7..9cd2364f84 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -111,6 +111,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 $metadata_extractor = $biblio->metadata_extractor; my $items = $biblio->items->search_ordered; @@ -144,40 +171,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 ); # get biblionumbers stored in the cart