From c383cab8a57da66645797ed6b400ddbdc7801377 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 21 Jan 2025 08:32:22 -0300 Subject: [PATCH] Bug 38936: Introduce C4::Output::redirect_if_opac_suppressed Signed-off-by: Tomas Cohen Arazi --- C4/Output.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/C4/Output.pm b/C4/Output.pm index d8ea0bfb521..f1015ae9cc4 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -47,6 +47,7 @@ BEGIN { setlanguagecookie getlanguagecookie pagination_bar parametrized_url output_html_with_http_headers output_ajax_with_http_headers output_with_http_headers output_and_exit_if_error output_and_exit output_error + redirect_if_opac_suppressed ); } @@ -412,6 +413,43 @@ sub parametrized_url { return $ret; } +=item redirect_if_opac_suppressed + + redirect_if_opac_suppressed( $query, $biblio ) + if C4::Context->preference('OpacSuppression'); + +For a given I object, it handles redirection if it is suppressed +from the OPAC. + +=cut + +sub redirect_if_opac_suppressed { + my ( $query, $biblio ) = @_; + + # 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); + C4::Auth::safe_exit(); + } + } else { + print $query->redirect($redirect_url); + C4::Auth::safe_exit(); + } + } +} + END { } # module clean-up code here (global destructor) 1; -- 2.48.1