From 2c4d154aa593d39dfa1c2e0a1c0e637047760b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 29 Oct 2025 10:01:27 -0300 Subject: [PATCH] Bug 40841: Add limits configuration UI This patch adds branch limits selection to the Z30.50/SRU configuration page. --- admin/z3950servers.pl | 37 ++++++++++++++----- .../prog/en/modules/admin/z3950servers.tt | 32 +++++++++++++++- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 04d1f7310d6..b420e2e1144 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -30,6 +30,7 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use Koha::Database; use Koha::Z3950Servers; +use Try::Tiny qw( catch try ); # Initialize CGI, template, database @@ -67,18 +68,30 @@ if ( $op eq 'cud-delete_confirmed' && $id ) { recordtype checked servername servertype sru_options sru_fields attributes add_xslt/; my $formdata = _form_data_hashref( $input, \@fields ); + my @branches = grep { $_ ne q{} } $input->multi_param('branches'); + if ($id) { my $server = Koha::Z3950Servers->find($id); if ($server) { - $server->set($formdata)->store; - $template->param( msg_updated => 1, msg_add => $formdata->{servername} ); + try { + $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 { $template->param( msg_notfound => 1, msg_add => $id ); } $id = 0; } else { - Koha::Z3950Server->new($formdata)->store; - $template->param( msg_added => 1, msg_add => $formdata->{servername} ); + try { + 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' ) { @@ -91,15 +104,21 @@ if ( $op eq 'cud-delete_confirmed' && $id ) { my $data = []; if ( $op eq 'add' || $op eq 'edit' ) { $data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id; - delete $data->[0]->{id} if @$data && $op eq 'add'; #cloning record + my $server = $data ? $data->next : undef; + if ( $server && $op eq 'add' ) { + + # Cloning record - remove id + $server = $server->unblessed; + delete $server->{id}; + } $template->param( - add_form => 1, server => @$data ? $data->[0] : undef, - op => $op, type => $op eq 'add' ? lc $type : '' + add_form => 1, server => $server, + op => $op, type => $op eq 'add' ? lc $type : '' ); } else { $data = ServerSearch( $schema, $id, $searchfield ); $template->param( - loop => \@$data, searchfield => $searchfield, id => $id, + loop => $data, searchfield => $searchfield, id => $id, op => 'list' ); } @@ -112,7 +131,7 @@ sub ServerSearch { #find server(s) by id or name return Koha::Z3950Servers->search( $id ? { id => $id } : { servername => { like => $searchstring . '%' } }, - )->unblessed; + ); } sub _form_data_hashref { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt index ef73637f27d..ce57b3df422 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -2,6 +2,7 @@ [% USE Koha %] [% USE Asset %] [% USE HtmlTags %] +[% USE Branches %] [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -198,6 +199,13 @@
Separate multiple filenames by commas.
+
  • + + +
    Limits the use of this server to the selected libraries.
    +
  • @@ -220,7 +228,7 @@ TargetHostname/PortDatabaseUseridPasswordPreselectedRankSyntaxEncodingTimeoutRecord typeAttributesActions + >Library limitationsActions @@ -237,6 +245,28 @@ [% END %] [% loo.attributes | html %] + + [% 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 %] + + [% IF library_limits.count > 1 %] + [% library_limits.count | html %] library limitations + [% ELSE %] + [% library_limits.count | html %] library limitation + [% END %] + + [% ELSE %] + No limitation + [% END %] +
    Actions -- 2.51.2