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:
<opac_url>/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 <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2025-12-18 12:56:39 +00:00 committed by Laura Escamilla
parent 363c7ce18d
commit b6247e6891
No known key found for this signature in database
GPG Key ID: 6B1D9CA1AF817BC3
1 changed files with 35 additions and 42 deletions

View File

@ -1183,57 +1183,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;
}