From 7f0b1d720344bc417e24613650592dd7e262c8f8 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 12 Oct 2011 11:46:12 -0400 Subject: [PATCH] LP872862, delete user function and open xacts Prevent deletion of a user with open circulations or unpaid bills Link up an error message on attempt to delete a patron with open xacts Signed-off-by: Michael Peters Signed-off-by: Jason Etheridge Signed-off-by: Bill Erickson --- Open-ILS/src/extras/ils_events.xml | 3 +++ .../perlmods/lib/OpenILS/Application/Actor.pm | 17 +++++++++++++++-- .../server/locale/en-US/patron.properties | 1 + .../xul/staff_client/server/patron/display.js | 11 ++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index 0a8b7a8cc9..59ff421751 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -760,6 +760,9 @@ There was an internal server error + + The user you have attempted to delete cannot be deleted because it has open circulations and/or unpaid bills. + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index b1ec6d811b..d2d60b2eb9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -3593,7 +3593,21 @@ sub really_delete_user { my($self, $conn, $auth, $user_id, $dest_user_id) = @_; my $e = new_editor(authtoken => $auth, xact => 1); return $e->die_event unless $e->checkauth; + + # Find all unclosed billings for for user $user_id, thereby, also checking for open circs + my $open_bills = $e->json_query({ + select => { mbts => ['id'] }, + from => 'mbts', + where => { + xact_finish => { '=' => undef }, + usr => { '=' => $user_id }, + } + }) or return $e->die_event; + my $user = $e->retrieve_actor_user($user_id) or return $e->die_event; + + # No deleting patrons with open billings or checked out copies + return $e->die_event(OpenILS::Event->new('ACTOR_USER_DELETE_OPEN_XACTS')) if @$open_bills; # No deleting yourself - UI is supposed to stop you first, though. return $e->die_event unless $e->requestor->id != $user->id; return $e->die_event unless $e->allowed('DELETE_USER', $user->home_ou); @@ -3602,14 +3616,13 @@ sub really_delete_user { my $evt = group_perm_failed($session, $e->requestor, $user); return $e->die_event($evt) if $evt; my $stat = $e->json_query( - {from => ['actor.usr_delete', $user_id, $dest_user_id]})->[0] + {from => ['actor.usr_delete', $user_id, $dest_user_id]})->[0] or return $e->die_event; $e->commit; return 1; } - __PACKAGE__->register_method ( method => 'user_payments', api_name => 'open-ils.actor.user.payments.retrieve', diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties index f910d3702a..3bd00ce5c3 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/patron.properties @@ -94,6 +94,7 @@ staff.patron.display.cmd_patron_delete.dest_user.default_value= staff.patron.display.cmd_patron_delete.dest_user.title=Destination User staff.patron.display.cmd_patron_delete.dest_user.failure=Failed to retrieve destination user. User deletion aborted. staff.patron.display.cmd_patron_delete.dest_user.self_reference_failure=Cannot specify the deleted user as the destination user. User deletion aborted. +staff.patron.display.cmd_patron_delete.open_xact=The user you have attempted to delete cannot be deleted because it has open circulations and/or unpaid bills. staff.patron.display.spawn_editor.editing_related_patron=Editing Related Patron staff.patron.display.init.retrieving_patron=Retrieving Patron... staff.patron.display.init.retrieving=Retrieving... diff --git a/Open-ILS/xul/staff_client/server/patron/display.js b/Open-ILS/xul/staff_client/server/patron/display.js index 2e17b8bb1b..3eba4f4d4d 100644 --- a/Open-ILS/xul/staff_client/server/patron/display.js +++ b/Open-ILS/xul/staff_client/server/patron/display.js @@ -123,7 +123,16 @@ patron.display.prototype = { } params.push( dest_usr.id() ); } - obj.network.simple_request( 'FM_AU_DELETE', params ); + var robj = obj.network.simple_request( 'FM_AU_DELETE', params ); + alert(js2JSON(robj)); + if (typeof robj.ilsevent != 'undefined') { + switch(Number(robj.ilsevent)) { + case 2004 /* ACTOR_USER_DELETE_OPEN_XACTS */ : + alert(document.getElementById('patronStrings').getString('staff.patron.display.cmd_patron_delete.open_xact')); + return; + break; + } + } obj.refresh_all(); } } catch(E) { -- 2.43.2