From fbe77e5b52a35d2c2689579da9c6a1b65b29f7bd Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Dec 2021 15:49:30 -0300 Subject: [PATCH] Bug 29742: Make deletemem.pl use Koha::Patron->safe_to_delete This patch makes the deletemem.pl controller script reuse the safe_to_delete method introduced by bug 29741. This way, it will use the same logic as the rest of the Koha pieces, like the API. To test: 1. Verify this conditions make deletion be denied: - Has a guarantee - Is the system-defined anonymous patron - Has outstanding debits - Has items checked out 2. Verify that this conditions display relevant information when trying to delete the patron: - Has outstanding credit - Has holds placed - Has pending suggestions 3. Apply this patch 4. Repeat 1 and 2 => SUCCESS: Things didn't change! [*] 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/members/deletemem.tt | 20 ++++----- members/deletemem.pl | 41 ++++++++++--------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt index 0b4eb50a32..1e1e01faf0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt @@ -33,17 +33,15 @@
[% INCLUDE 'members-toolbar.inc' %] - [% IF ItemsOnIssues || debits || is_guarantor %] + [% IF safe_to_delete != 'ok' %]

Cannot delete patron

    - [% IF ( ItemsOnIssues ) %] -
  • Patron has [% ItemsOnIssues | html %] item(s) checked out.
  • - [% END %] - [% IF debits %] -
  • Patron has [% debits | $Price %] in fines.
  • - [% END %] - [% IF is_guarantor %] + [% IF safe_to_delete == 'has_checkouts' %] +
  • Patron has [% checkouts_count | html %] item(s) checked out.
  • + [% ELSIF safe_to_delete == 'has_debt' %] +
  • Patron has [% charges | $Price %] in outstanding charges.
  • + [% ELSIF safe_to_delete == 'has_guarantees' %]
  • Patron's record has guaranteed accounts attached.
  • [% END %]
@@ -51,10 +49,10 @@ [% ELSIF op == 'delete_confirm' and patron %] [%# TODO add "patron does not exist" unless patron %]
- [% IF ItemsOnHold or credits or pending_suggestions > 0 %] + [% IF holds_count or credits or pending_suggestions > 0 %]
    - [% IF ItemsOnHold %] -
  • Patron has [% ItemsOnHold | html %] hold(s). Deleting patron cancels all their holds.
  • + [% IF holds_count %] +
  • Patron has [% holds_count | html %] hold(s). Deleting patron cancels all their holds.
  • [% END %] [% IF credits %]
  • Patron has a [% credits | $Price %] credit.
  • diff --git a/members/deletemem.pl b/members/deletemem.pl index 5faf87dc47..e7815a6678 100755 --- a/members/deletemem.pl +++ b/members/deletemem.pl @@ -45,8 +45,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -#print $input->header; -my $member = $input->param('member'); +my $member = $input->param('member'); #Do not delete yourself... if ( $loggedinuser == $member ) { @@ -58,9 +57,6 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser ); my $patron = Koha::Patrons->find( $member ); output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); -my $debits = $patron->account->outstanding_debits->total_outstanding; -my $credits = abs $patron->account->outstanding_credits->total_outstanding; -my $countissues = $patron->checkouts->count; my $userenv = C4::Context->userenv; if ($patron->category->category_type eq "S") { @@ -85,17 +81,14 @@ if (C4::Context->preference("IndependentBranches")) { } } -if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) { - if ( $patron->id eq $anonymous_patron ) { - print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_ANONYMOUS_PATRON"); - exit 0; # Exit without error - } +my $safe_to_delete = $patron->safe_to_delete; + +if ( $safe_to_delete eq 'is_anonymous_patron' ) { + print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_ANONYMOUS_PATRON"); + exit 0; # Exit without error } my $op = $input->param('op') || 'delete_confirm'; -my $dbh = C4::Context->dbh; -my $is_guarantor = $patron->guarantee_relationships->count; -my $countholds = $dbh->selectrow_array("SELECT COUNT(*) FROM reserves WHERE borrowernumber=?", undef, $member); # Add warning if patron has pending suggestions $template->param( @@ -106,16 +99,24 @@ $template->param( } ); +my $account = $patron->account; +my $credits = abs $account->outstanding_credits->total_outstanding; + $template->param( - patron => $patron, - ItemsOnIssues => $countissues, - debits => $debits, - credits => $credits, - is_guarantor => $is_guarantor, - ItemsOnHold => $countholds, + credits => $credits, + holds_count => $patron->holds->count, + patron => $patron, + safe_to_delete => $safe_to_delete, ); -if ( $op eq 'delete_confirm' or $countissues > 0 or $debits or $is_guarantor ) { +if ( $safe_to_delete eq 'has_checkouts' ) { + $template->param( checkouts_count => $patron->checkouts->count, ); +} +elsif ( $safe_to_delete eq 'has_debt' ) { + $template->param( charges => $account->outstanding_debits->total_outstanding, ); +} + +if ( $op eq 'delete_confirm' or $safe_to_delete ne 'ok' ) { $template->param( op => 'delete_confirm', csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }), -- 2.32.0