From 05a07b423ef046935889d82107e93fd1cac8f615 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.8 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. --- Koha/ILL/Request.pm | 65 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index 777de51ce70..d6cf4b50b5e 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -1184,57 +1184,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; + return $params; + } - if ($plugin) { + my $plugin = $self->get_backend_plugin( $self->_backend->name ); - # New way of loading backends: Through plugins - $backend_dir = $plugin->bundle_path; - $backend_tmpl = $backend_dir; + # Generate path to file to load + my $backend_dir; + my $backend_tmpl; - } else { + if ($plugin) { - # Old way of loading backends: Through backend_dir config - $backend_dir = $self->_config->backend_dir; - $backend_tmpl = join "/", $backend_dir, $backend; - } + # New way of loading backends: Through plugins + $backend_dir = $plugin->bundle_path; + $backend_tmpl = $backend_dir; - my $intra_tmpl = join "/", $backend_tmpl, "intra-includes", - ( $params->{method} // q{} ) . ".inc"; - my $opac_tmpl = join "/", $backend_tmpl, "opac-includes", - ( $params->{method} // q{} ) . ".inc"; + } else { - # Set files to load - $params->{template} = $intra_tmpl; - $params->{opac_template} = $opac_tmpl; + # 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; } -- 2.39.5