Bug 40841: Add limits configuration UI

This patch adds branch limits selection to the Z30.50/SRU configuration
page.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Tomás Cohen Arazi 2025-10-29 10:01:27 -03:00 committed by Martin Renvoize
parent d6aae094b4
commit 3c87468669
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
2 changed files with 76 additions and 26 deletions

View File

@ -28,10 +28,10 @@ use CGI qw ( -utf8 );
use C4::Context; use C4::Context;
use C4::Auth qw( get_template_and_user ); use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers ); use C4::Output qw( output_html_with_http_headers );
use Koha::Database;
use Koha::Z3950Servers; use Koha::Z3950Servers;
use Try::Tiny qw( catch try );
# Initialize CGI, template, database # Initialize CGI, template
my $input = CGI->new; my $input = CGI->new;
my $op = $input->param('op') || 'list'; my $op = $input->param('op') || 'list';
@ -48,8 +48,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
} }
); );
my $schema = Koha::Database->new()->schema();
# Main code # Main code
# First process a confirmed delete, or save a validated record # First process a confirmed delete, or save a validated record
@ -67,18 +65,30 @@ if ( $op eq 'cud-delete_confirmed' && $id ) {
recordtype checked servername servertype sru_options sru_fields attributes recordtype checked servername servertype sru_options sru_fields attributes
add_xslt/; add_xslt/;
my $formdata = _form_data_hashref( $input, \@fields ); my $formdata = _form_data_hashref( $input, \@fields );
my @branches = grep { $_ ne q{} } $input->multi_param('branches');
if ($id) { if ($id) {
my $server = Koha::Z3950Servers->find($id); my $server = Koha::Z3950Servers->find($id);
if ($server) { if ($server) {
$server->set($formdata)->store; try {
$template->param( msg_updated => 1, msg_add => $formdata->{servername} ); $server->set($formdata)->store;
$server->replace_library_limits( \@branches );
$template->param( msg_updated => 1, msg_add => $formdata->{servername} );
} catch {
$template->param( msg_error => 1, msg_add => $formdata->{servername} );
};
} else { } else {
$template->param( msg_notfound => 1, msg_add => $id ); $template->param( msg_notfound => 1, msg_add => $id );
} }
$id = 0; $id = 0;
} else { } else {
Koha::Z3950Server->new($formdata)->store; try {
$template->param( msg_added => 1, msg_add => $formdata->{servername} ); my $server = Koha::Z3950Server->new($formdata)->store;
$server->replace_library_limits( \@branches );
$template->param( msg_added => 1, msg_add => $formdata->{servername} );
} catch {
$template->param( msg_error => 1, msg_add => $formdata->{servername} );
};
} }
} elsif ( $op eq 'search' ) { } elsif ( $op eq 'search' ) {
@ -88,19 +98,37 @@ if ( $op eq 'cud-delete_confirmed' && $id ) {
# Now list multiple records, or edit one record # Now list multiple records, or edit one record
my $data = []; if ( $op eq 'add_form' ) {
if ( $op eq 'add_form' || $op eq 'edit_form' ) { my $server;
$data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id;
delete $data->[0]->{id} if @$data && $op eq 'add_form'; #cloning record if ($id) {
$server = Koha::Z3950Servers->find($id);
if ($server) {
# Cloning record - remove id
$server = $server->unblessed;
delete $server->{id};
}
}
$template->param( $template->param(
server => @$data ? $data->[0] : undef, server => $server,
op => $op, op => $op,
type => ( $op eq 'add_form' ) ? lc $type : '' type => lc $type
); );
} else { } elsif ( $op eq 'edit_form' ) {
$data = ServerSearch( $schema, $id, $searchfield ); my $server = Koha::Z3950Servers->find($id);
$template->param( $template->param(
loop => \@$data, searchfield => $searchfield, id => $id, server => $server,
op => $op,
type => ''
);
} else { # search
my $data = Koha::Z3950Servers->search(
$id ? { id => $id } : { servername => { like => $searchfield . '%' } },
);
$template->param(
loop => $data, searchfield => $searchfield, id => $id,
op => 'list' op => 'list'
); );
} }
@ -108,14 +136,6 @@ output_html_with_http_headers $input, $cookie, $template->output;
# End of main code # End of main code
sub ServerSearch { #find server(s) by id or name
my ( $schema, $id, $searchstring ) = @_;
return Koha::Z3950Servers->search(
$id ? { id => $id } : { servername => { like => $searchstring . '%' } },
)->unblessed;
}
sub _form_data_hashref { sub _form_data_hashref {
my ( $input, $fieldref ) = @_; my ( $input, $fieldref ) = @_;
return { map { ( $_ => scalar $input->param($_) // '' ) } @$fieldref }; return { map { ( $_ => scalar $input->param($_) // '' ) } @$fieldref };

View File

@ -2,6 +2,7 @@
[% USE Koha %] [% USE Koha %]
[% USE Asset %] [% USE Asset %]
[% USE HtmlTags %] [% USE HtmlTags %]
[% USE Branches %]
[% PROCESS 'i18n.inc' %] [% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %] [% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %] [% INCLUDE 'doc-head-open.inc' %]
@ -198,6 +199,13 @@
<input type="text" name="add_xslt" id="add_xslt" size="100" value="[% server.add_xslt | html %]" /> <input type="text" name="add_xslt" id="add_xslt" size="100" value="[% server.add_xslt | html %]" />
<div class="hint">Separate multiple filenames by commas.</div> <div class="hint">Separate multiple filenames by commas.</div>
</li> </li>
<li>
<label for="library_limitation">Library limitation: </label>
<select id="library_limitation" name="branches" multiple size="10">
[% PROCESS options_for_libraries libraries => Branches.all( selected => server.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
</select>
<div class="hint">Limits the use of this server to the selected libraries.</div>
</li>
</ol> </ol>
</fieldset> </fieldset>
@ -220,7 +228,7 @@
<thead <thead
><tr ><tr
><th>Target</th><th>Hostname/Port</th><th>Database</th><th>Userid</th><th>Password</th><th>Preselected</th><th>Rank</th><th>Syntax</th><th>Encoding</th><th>Timeout</th><th>Record type</th><th>Attributes</th ><th>Target</th><th>Hostname/Port</th><th>Database</th><th>Userid</th><th>Password</th><th>Preselected</th><th>Rank</th><th>Syntax</th><th>Encoding</th><th>Timeout</th><th>Record type</th><th>Attributes</th
><th class="no-export no-sort">Actions</th> ><th>Library limitations</th><th class="no-export no-sort">Actions</th>
</tr></thead </tr></thead
> >
<tbody> <tbody>
@ -237,6 +245,28 @@
[% END %] [% END %]
</td> </td>
<td>[% loo.attributes | html %]</td> <td>[% loo.attributes | html %]</td>
<td>
[% SET library_limits = loo.library_limits %]
[% IF library_limits && library_limits.count > 0 %]
[% library_str = "" %]
[% FOREACH library IN library_limits %]
[%- IF loop.first -%]
[% library_str = library.branchname _ " (" _ library.branchcode _ ")" %]
[% ELSE %]
[% library_str = library_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %]
[% END %]
[% END %]
<span class="library_limitation" data-bs-toggle="tooltip" title="[% library_str | html %]">
[% IF library_limits.count > 1 %]
<span>[% library_limits.count | html %] library limitations</span>
[% ELSE %]
<span>[% library_limits.count | html %] library limitation</span>
[% END %]
</span>
[% ELSE %]
<span>No limitation</span>
[% END %]
</td>
<td> <td>
<div class="btn-group dropup"> <div class="btn-group dropup">
<a class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-bs-toggle="dropdown" href="#"> Actions </a> <a class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-bs-toggle="dropdown" href="#"> Actions </a>