From 27404790546b4d8eefdde6548b0533d97ae63e4b 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds branch limits selection to the Z30.50/SRU configuration page. Signed-off-by: Tomás Cohen Arazi Signed-off-by: David Nind --- admin/z3950servers.pl | 71 ++++++++++++------- .../prog/en/modules/admin/z3950servers.tt | 32 ++++++++- 2 files changed, 76 insertions(+), 27 deletions(-) diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 22f94145f5..be76653555 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -28,10 +28,10 @@ use CGI qw ( -utf8 ); use C4::Context; 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 +# Initialize CGI, template my $input = CGI->new; 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 # 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 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' ) { @@ -88,34 +98,43 @@ if ( $op eq 'cud-delete_confirmed' && $id ) { # Now list multiple records, or edit one record -my $data = []; -if ( $op eq 'add_form' || $op eq 'edit_form' ) { - $data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id; - delete $data->[0]->{id} if @$data && $op eq 'add_form'; #cloning record +if ( $op eq 'add_form' ) { + my $server; + + if ($id) { + $server = Koha::Z3950Servers->find($id); + if ($server) { + + # Cloning record - remove id + $server = $server->unblessed; + delete $server->{id}; + } + } + $template->param( - server => @$data ? $data->[0] : undef, + server => $server, op => $op, - type => ( $op eq 'add_form' ) ? lc $type : '' + type => lc $type + ); +} elsif ( $op eq 'edit_form' ) { + my $server = Koha::Z3950Servers->find($id); + $template->param( + server => $server, + op => $op, + type => '' + ); +} else { # search + my $data = Koha::Z3950Servers->search( + $id ? { id => $id } : { servername => { like => $searchfield . '%' } }, ); -} else { - $data = ServerSearch( $schema, $id, $searchfield ); $template->param( - loop => \@$data, searchfield => $searchfield, id => $id, + loop => $data, searchfield => $searchfield, id => $id, op => 'list' ); } -output_html_with_http_headers $input, $cookie, $template->output; # 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 { my ( $input, $fieldref ) = @_; return { map { ( $_ => scalar $input->param($_) // '' ) } @$fieldref }; 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 4b481dd7cb..44cfc90dd3 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.50.1 (Apple Git-155)