From b2903680c4cfa26fc8bb9a7fd997aa64d35a3603 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 4 Nov 2025 21:45:08 +0000 Subject: [PATCH] Bug 34069: Deal with view_borrower_infos_from_any_libraries Signed-off-by: Katie Bliss --- Koha/Old/Patron.pm | 8 ++++++ .../tools/restore_deleted_borrowers.tt | 27 ++++++++++++++++-- tools/restore_deleted_borrowers.pl | 28 +++++++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Koha/Old/Patron.pm b/Koha/Old/Patron.pm index 62264ed3fac..a395a0ef839 100644 --- a/Koha/Old/Patron.pm +++ b/Koha/Old/Patron.pm @@ -84,6 +84,14 @@ sub restore_deleted_borrower { # Retrive all the data about this patron from deleteborrowers table my $patron_data = $self->unblessed; + # some fields must be cleared + # borrower_debarments table is cleared on delete, we must also removed the debarment from the patron record + $patron_data->{debarred} = undef; + $patron_data->{debarredcomment} = undef; + + #dont restore borrowers with flags, those will have to be re-added + $patron_data->{flags} = undef; + # Create the Koha::Patron object my $patron = Koha::Patron->new($patron_data); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore_deleted_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore_deleted_borrowers.tt index d5770e0845e..499adaf3fb0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore_deleted_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore_deleted_borrowers.tt @@ -77,8 +77,12 @@
  • @@ -243,6 +247,25 @@ }); [% END %] + $("#restore_form").on("submit", function(e) { + var checked = $("#deleted_patrons_table tbody input[type='checkbox']:checked").length; + + if (checked === 0) { + e.preventDefault(); + alert(_("Please select at least one patron to restore.")); + return false; + } + + var message = __("Are you sure you want to restore %s patron(s)?").format(checked); + + if (!confirm(message)) { + e.preventDefault(); + return false; + } + + return true; + }); + }); [% END %] diff --git a/tools/restore_deleted_borrowers.pl b/tools/restore_deleted_borrowers.pl index 02f93e3ef6a..81ed20d34a7 100755 --- a/tools/restore_deleted_borrowers.pl +++ b/tools/restore_deleted_borrowers.pl @@ -23,7 +23,7 @@ use CGI qw ( -utf8 ); use Try::Tiny; use Scalar::Util qw( blessed ); -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user haspermission ); use C4::Output qw( output_html_with_http_headers ); use C4::Context; @@ -39,10 +39,34 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( template_name => "tools/restore_deleted_borrowers.tt", query => $input, type => "intranet", - flagsrequired => { tools => 'restore_deleted_patrons' }, + flagsrequired => { borrowers => 'restore_deleted_borrowers' }, } ); +#check if the user can view patrons from any branch, or just thier own +my $logged_in_patron = Koha::Patrons->find($loggedinuser); +my $can_view_all_libraries = + haspermission( $logged_in_patron->userid, { borrowers => 'view_borrower_infos_from_any_libraries' } ); + +my @libraries; +if ($can_view_all_libraries) { + + # User can view all branches, get them all + @libraries = Koha::Libraries->search( {}, { order_by => 'branchname' } )->as_list; +} else { + + # User can only view their branch or branches in the group, get only those + @libraries = Koha::Libraries->search_filtered( + { only_from_group => 1 }, + { order_by => ['branchname'] } + )->as_list; +} + +$template->param( + allowed_libraries => \@libraries, + can_view_all_libraries => $can_view_all_libraries, +); + if ( $op eq 'search' ) { # Get search parameters -- 2.39.5