From 4d3f3466a2f2dfd41781d635d6e0b4bca2886c7b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 27 Jun 2016 12:12:52 -0300 Subject: [PATCH] [PASSED QA] Bug 15023: Allow patron anonymize/bulk delete tool to be limited by branch This patch makes the bulk patron delete/anonymize functionality be limited by branch. It does so by adding a branch selection dropdown and using the already defined APIs for filtering by branch. It makes use of C4::Branches::onlymine for the IndependentBranches use case and it adds a way to call it from the Branches template plugin. To test: - Apply the patch 1) Have a superlibrarian user - Go to Tools > Batch patron deletion/anonymization => SUCCESS: Verify you can pick a branch (or all of them) - Try doing some operations => SUCCESS: Verify the selection is respected, and carried around all steps 2) Have a user with tools/delete_anonymize_patrons permissions - Set IndependentBranches on - Go to Tools > Batch patron deletion/anonymization => SUCCESS: It picks the librarian's branch and doesn't let us choose another one - Try doing some operations => SUCCESS: Verify the user's branch is respected, and carried around all steps - Sign off :-D Sponsored-by: VOKAL Signed-off-by: Liz Rea Signed-off-by: Katrin Fischer --- Koha/Template/Plugin/Branches.pm | 4 +++ .../prog/en/modules/tools/cleanborrowers.tt | 38 ++++++++++++++++++++-- tools/cleanborrowers.pl | 29 +++++++++++++---- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index 880b2c4..0b95e42 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -54,6 +54,10 @@ sub GetURL { return $b->{branchurl}; } +sub OnlyMine { + return C4::Branch::onlymine; +} + sub all { my ( $self, $params ) = @_; my $selected = $params->{selected}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt index 9e68141..ae7df4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tt @@ -1,5 +1,6 @@ [% USE Koha %] [% USE KohaDates %] +[% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools › Batch patron deletion/anonymization [% IF step == 2 %]› Confirm[% END %][% IF step == 3 %]› Finished[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -37,6 +38,13 @@ function checkForm2(form) { return true; } + + $(document).ready(function() { + $('#selectlibrary').find("input:submit").hide(); + $('#branch').change(function() { + $('#selectlibrary').submit(); + }); + }); // ]]> @@ -52,13 +60,35 @@
+[% IF !Branches.OnlyMine %] +
+ Select a library : + +
+ [% IF current_branch == '*' %] +

Batch patron deletion/anonymization

+ [% ELSE %] +

Batch patron deletion/anonymization for [% Branches.GetName( current_branch ) %]

+ [% END %] +[% ELSE %] +

Batch patron deletion/anonymization for [% Branches.GetName( Branches.GetLoggedInBranchcode ) %]

+[% END %] + +[% IF step == 1 %] + -

Batch patron deletion/anonymization

This tool allows you to delete patrons and anonymize checkout history. For deleting patrons, any combination of limits can be used.

-[% IF step == 1 %] -
@@ -119,6 +149,7 @@ +
@@ -162,6 +193,7 @@ +
Cancel
diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index d108d53..df2196f 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -31,9 +31,8 @@ This script allows to do 2 things. =cut -use strict; +use Modern::Perl; -#use warnings; FIXME - Bug 2505 use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; @@ -78,6 +77,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +my $branch = $params->{ branch } || '*'; +$template->param( current_branch => $branch ); + if ( $step == 2 ) { my %checkboxes = map { $_ => 1 } split /\0/, $params->{'checkbox'}; @@ -90,6 +92,7 @@ if ( $step == 2 ) { $borrower_dateexpiry, $borrower_categorycode, $patron_list_id, + $branch ) ); } @@ -97,13 +100,17 @@ if ( $step == 2 ) { my $members_to_anonymize; if ( $checkboxes{issue} ) { - $members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); + if ( $branch eq '*' ) { + $members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date); + } else { + $members_to_anonymize = GetBorrowersWithIssuesHistoryOlderThan($last_issue_date, $branch); + } } $template->param( patrons_to_delete => $patrons_to_delete, patrons_to_anonymize => $members_to_anonymize, - patron_list_id => $patron_list_id, + patron_list_id => $patron_list_id ); } @@ -117,8 +124,11 @@ elsif ( $step == 3 ) { if ($do_delete) { my $patrons_to_delete = GetBorrowersToExpunge( _get_selection_params( - $not_borrowed_since, $borrower_dateexpiry, - $borrower_categorycode, $patron_list_id + $not_borrowed_since, + $borrower_dateexpiry, + $borrower_categorycode, + $patron_list_id, + $branch ) ); _skip_borrowers_with_nonzero_balance($patrons_to_delete); @@ -183,7 +193,8 @@ sub _skip_borrowers_with_nonzero_balance { } sub _get_selection_params { - my ($not_borrowed_since, $borrower_dateexpiry, $borrower_categorycode, $patron_list_id) = @_; + my ($not_borrowed_since, $borrower_dateexpiry, + $borrower_categorycode, $patron_list_id, $branch) = @_; my $params = {}; $params->{not_borrowed_since} = output_pref({ @@ -199,5 +210,9 @@ sub _get_selection_params { $params->{category_code} = $borrower_categorycode if $borrower_categorycode; $params->{patron_list_id} = $patron_list_id if $patron_list_id; + if ( defined $branch and $branch ne '*' ) { + $params->{ branchcode } = $branch; + } + return $params; }; -- 1.9.1