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 <magnus@libriotech.no>
Works as advertised. Remember to activate OPAC suppression with
OpacSuppression.
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomas Cohen Arazi 2024-12-18 11:15:36 -03:00 committed by Katrin Fischer
parent 1b4bb57092
commit e360959752
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 81 additions and 34 deletions

View File

@ -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(
{

View File

@ -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

View File

@ -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