From 6fcd7937f37637e2bb457a022f76e6dfdbdd7c32 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 18 Dec 2025 12:56:39 +0000 Subject: [PATCH] Bug 41478: Refactor: Readability + Never nester 1) Install the following dummy backend plugin: https://github.com/openfifth/koha-ill-backend-plugin/releases/tag/v2.0.9 2) Sys prefs preparation: Enable ILLModule, ILLOpacUnauthenticatedRequest and check PluginBackend on AutoILLBackendPriority 3) Logout, create a new Unauthenticated ILL request on the OPAC, visit: /cgi-bin/koha/opac-illrequests.pl?op=create&backend=Standard 4) Fill in the mandatory top fields (first name, last name, email address and library) 5) Pick 'Book' for type and enter 'green' in title. This will cause the dummy plugin to be available in the AutoILL logic. 6) At the bottom of the form, on the "Verification" captcha, purposely input a wrong captcha e.g. '123' 7) Click 'Create'. Notice an odd looking form is presented, this is the dummy backend form, but it should present the 'Standard' form when using AutoILLBackendPriority as that was also the form we were presented with originally. This happens because currently it's the backend that delegates back to Koha what template to render. When using AutoILLBackendPriority, however, Koha should handle this template delegation instead and present the Standard form. 8) Apply patches. Repeat test plan. Notice that now on step 7 you get the correct form, and error message (coming from Standard, as expected when using AutoILLBackendPriority). 9) Input the correct captcha this time 10) Confirm the created request landed in the PluginBackend backend. Signed-off-by: David Nind Signed-off-by: Lisette Scheer Signed-off-by: Lucas Gass (cherry picked from commit 6473a06916ed15f1d007ac32f2bb729386ed16c6) Signed-off-by: Jacob O'Mara --- Koha/ILL/Request.pm | 77 +++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index c5a91ab887..50a8f733bc 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -1185,57 +1185,50 @@ sub expand_template { my ( $self, $params ) = @_; my $backend = $self->_backend->name; - if ( - $backend eq 'Standard' - || ( $params->{method} && $params->{method} eq 'edititem' && C4::Context->preference("AutoILLBackendPriority") ) - ) - { + my $auto_priority = C4::Context->preference("AutoILLBackendPriority"); + my $unauth_request = C4::Context->preference("ILLOpacUnauthenticatedRequest"); + my $method = $params->{method} // q{}; + my $template_name = "ill/backends/Standard/$method.inc"; - my $template_name = 'ill/backends/Standard/' . ( $params->{method} // q{} ) . '.inc'; - - # Set files to load + if ( $backend eq 'Standard' || ( $method eq 'edititem' && $auto_priority ) ) { $params->{template} = $template_name; $params->{opac_template} = $template_name; - } elsif ( $params->{error} - && $params->{status} eq 'failed_captcha' - && C4::Context->preference("AutoILLBackendPriority") ) - { - my $template_name = 'ill/backends/Standard/' . ( $params->{method} // q{} ) . '.inc'; + return $params; + } - # Set files to load + if ( $params->{error} && $params->{status} eq 'failed_captcha' && $auto_priority && $unauth_request ) { $params->{template} = $template_name; $params->{opac_template} = $template_name; $params->{stage} = 'form'; - } else { - my $plugin = $self->get_backend_plugin( $self->_backend->name ); - - # Generate path to file to load - my $backend_dir; - my $backend_tmpl; - - if ($plugin) { - - # New way of loading backends: Through plugins - $backend_dir = $plugin->bundle_path; - $backend_tmpl = $backend_dir; - - } else { - - # Old way of loading backends: Through backend_dir config - $backend_dir = $self->_config->backend_dir; - $backend_tmpl = join "/", $backend_dir, $backend; - } - - my $intra_tmpl = join "/", $backend_tmpl, "intra-includes", - ( $params->{method} // q{} ) . ".inc"; - my $opac_tmpl = join "/", $backend_tmpl, "opac-includes", - ( $params->{method} // q{} ) . ".inc"; - - # Set files to load - $params->{template} = $intra_tmpl; - $params->{opac_template} = $opac_tmpl; + return $params; } + my $plugin = $self->get_backend_plugin( $self->_backend->name ); + + # Generate path to file to load + my $backend_dir; + my $backend_tmpl; + + if ($plugin) { + + # New way of loading backends: Through plugins + $backend_dir = $plugin->bundle_path; + $backend_tmpl = $backend_dir; + + } else { + + # Old way of loading backends: Through backend_dir config + $backend_dir = $self->_config->backend_dir; + $backend_tmpl = join "/", $backend_dir, $backend; + } + + my $intra_tmpl = join "/", $backend_tmpl, "intra-includes", "$method.inc"; + my $opac_tmpl = join "/", $backend_tmpl, "opac-includes", "$method.inc"; + + # Set files to load + $params->{template} = $intra_tmpl; + $params->{opac_template} = $opac_tmpl; + return $params; }