From 7e459294d1e49c0e3397b897fb4d4b733a23bb99 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 18 Feb 2014 08:53:59 -0500 Subject: [PATCH] LP#1187035 Remove OpenILS::Utils::Editor part 4. Make sure all CStoreEditors in ClosedDates run updates in transactions, roll back transactions on error, and commit the transactions on success. Added a live test for closed data updating. Signed-off-by: Bill Erickson Signed-off-by: Jeff Godin --- .../OpenILS/Application/Actor/ClosedDates.pm | 28 ++++++++++--------- .../live_t/04-overdue_with_closed_dates.t | 18 +++++++++++- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/ClosedDates.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/ClosedDates.pm index 28cd1230a4..46337f5be1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/ClosedDates.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/ClosedDates.pm @@ -67,12 +67,13 @@ __PACKAGE__->register_method( sub delete_date { my( $self, $conn, $auth, $id ) = @_; - my $e = new_editor(authtoken=>$auth); - return $e->event unless $e->checkauth; - my $date = $e->retrieve_actor_org_unit_closed_date($id) or return $e->event; - return $e->event unless $e->allowed( # rely on the editor perm eventually + my $e = new_editor(authtoken=>$auth, xact => 1); + return $e->die_event unless $e->checkauth; + my $date = $e->retrieve_actor_org_unit_closed_date($id) or return $e->die_event; + return $e->die_event unless $e->allowed( 'actor.org_unit.closed_date.delete', $date->org_unit); - $e->delete_actor_org_unit_closed_date($date) or return $e->event; + $e->delete_actor_org_unit_closed_date($date) or return $e->die_event; + $e->commit; return 1; } @@ -91,15 +92,15 @@ sub create_date { my( $self, $conn, $auth, $date ) = @_; my $e = new_editor(authtoken=>$auth, xact =>1); - return $e->event unless $e->checkauth; + return $e->die_event unless $e->checkauth; - return $e->event unless $e->allowed( # rely on the editor perm eventually + return $e->die_event unless $e->allowed( 'actor.org_unit.closed_date.create', $date->org_unit); - $e->create_actor_org_unit_closed_date($date) or return $e->event; + $e->create_actor_org_unit_closed_date($date) or return $e->die_event; my $newobj = $e->retrieve_actor_org_unit_closed_date($date->id) - or return $e->event; + or return $e->die_event; $e->commit; return $newobj; @@ -117,16 +118,17 @@ __PACKAGE__->register_method( sub edit_date { my( $self, $conn, $auth, $date ) = @_; my $e = new_editor(authtoken=>$auth, xact =>1); - return $e->event unless $e->checkauth; + return $e->die_event unless $e->checkauth; # First make sure they have the right to update the selected date object my $odate = $e->retrieve_actor_org_unit_closed_date($date->id) - or return $e->event; + or return $e->die_event; - return $e->event unless $e->allowed( # rely on the editor perm eventually + return $e->die_event unless $e->allowed( 'actor.org_unit.closed_date.update', $odate->org_unit); - $e->update_actor_org_unit_closed_date($date) or return $e->event; + $e->update_actor_org_unit_closed_date($date) or return $e->die_event; + $e->commit; return 1; } diff --git a/Open-ILS/src/perlmods/live_t/04-overdue_with_closed_dates.t b/Open-ILS/src/perlmods/live_t/04-overdue_with_closed_dates.t index 3f9f3f5200..e00496e8cb 100644 --- a/Open-ILS/src/perlmods/live_t/04-overdue_with_closed_dates.t +++ b/Open-ILS/src/perlmods/live_t/04-overdue_with_closed_dates.t @@ -1,6 +1,6 @@ #!perl -use Test::More tests => 22; +use Test::More tests => 23; diag("Test fine generation with closed date on checkin against the admin user."); @@ -45,6 +45,16 @@ sub create_closed_date { return $resp; } +# returns "1" on success, event on error +sub update_closed_date { + my $aoucd = shift; + $aoucd->reason($aoucd->reason . ' modified'); + return $apputils->simplereq( + 'open-ils.actor', + 'open-ils.actor.org_unit.closed.update', + $script->authtoken, $aoucd); +} + sub delete_closed_date { my $aoucd = shift; my $resp = $apputils->simplereq( @@ -131,6 +141,12 @@ is( 'Created a closed date for 10 days ago' ); +is( + update_closed_date($closed_date_obj), + '1', + 'Updated closed date reason' +); + my $checkout_resp = $script->do_checkout({ patron => 1, barcode => ITEM_BARCODE}); -- 2.43.2