From 4e760b1c46874820a5f2787f4da4241cb964d698 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 28 Mar 2007 14:49:49 +0000 Subject: [PATCH] moved location editing to in-transaction cstore-editor calls git-svn-id: svn://svn.open-ils.org/ILS/trunk@7115 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/CopyLocations.pm | 97 +++++++++++----------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm index 600fe0762d..ab572bfa03 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm @@ -48,25 +48,27 @@ __PACKAGE__->register_method( @return The if of the new location object on success, event on error /); + sub cl_create { - my( $self, $client, $authtoken, $copyLoc ) = @_; - my( $requestor, $evt ) = $U->checkses($authtoken); - return $evt if $evt; - $evt = $U->check_perms($requestor->id, - $copyLoc->owning_lib, 'CREATE_COPY_LOCATION'); - return $evt if $evt; - - my $cl; - ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib); - return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl; - - my $id = $U->storagereq( - 'open-ils.storage.direct.asset.copy_location.create', $copyLoc ); - - return $U->DB_UPDATE_FAILED($copyLoc) unless $id; - return $id; + my( $self, $conn, $auth, $location ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + return $e->die_event unless + $e->allowed('CREATE_COPY_LOCATION', $location->owning_lib); + + # make sure there is no copy_location with the same name in the same place + my $existing = $e->search_asset_copy_location( + {owning_lib => $location->owning_lib, name => $location->name}, {idlist=>1}); + return OpenILS::Event->new('COPY_LOCATION_EXISTS') if @$existing; + + $e->create_asset_copy_location($location) or return $e->die_event; + $e->commit; + return $location->id; } + + __PACKAGE__->register_method ( api_name => 'open-ils.circ.copy_location.delete', method => 'cl_delete', @@ -79,26 +81,24 @@ __PACKAGE__->register_method ( @return 1 on success, event on error /); + sub cl_delete { - my( $self, $client, $authtoken, $id ) = @_; - my( $requestor, $evt ) = $U->checkses($authtoken); - return $evt if $evt; - - my $cl; - ($cl, $evt) = $U->fetch_copy_location($id); - return $evt if $evt; - - $evt = $U->check_perms($requestor->id, - $cl->owning_lib, 'DELETE_COPY_LOCATION'); - return $evt if $evt; - - my $resp = $U->storagereq( - 'open-ils.storage.direct.asset.copy_location.delete', $id ); - - return $U->DB_UPDATE_FAILED unless $resp; - return 1; + my( $self, $conn, $auth, $id ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + + my $cloc = $e->retrieve_asset_copy_location($id) + or return $e->die_event; + return $e->die_event unless + $e->allowed('DELETE_COPY_LOCATION', $cloc->owning_lib); + + $e->delete_asset_copy_location($cloc) or return $e->die_event; + $e->commit; + return 1; } + __PACKAGE__->register_method ( api_name => 'open-ils.circ.copy_location.update', method => 'cl_update', @@ -111,29 +111,32 @@ __PACKAGE__->register_method ( @return 1 on success, event on error /); + sub cl_update { - my( $self, $client, $authtoken, $copyLoc ) = @_; + my( $self, $conn, $auth, $location ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; - my( $requestor, $evt ) = $U->checkses($authtoken); - return $evt if $evt; + # check permissions against the original copy location + my $orig_loc = $e->retrieve_asset_copy_location($location->id) + or return $e->die_event; - my $cl; - ($cl, $evt) = $U->fetch_copy_location($copyLoc->id); - return $evt if $evt; + return $e->die_event unless + $e->allowed('UPDATE_COPY_LOCATION', $orig_loc->owning_lib); - $evt = $U->check_perms($requestor->id, - $cl->owning_lib, 'UPDATE_COPY_LOCATION'); - return $evt if $evt; + # disallow hijacking of the location + $location->owning_lib($orig_loc->owning_lib); - $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib + $e->update_asset_copy_location($location) + or return $e->die_event; - my $resp = $U->storagereq( - 'open-ils.storage.direct.asset.copy_location.update', $copyLoc ); - - return 1; # if there was no exception thrown, then the update was a success + $e->commit; + return 1; } + __PACKAGE__->register_method( method => 'fetch_loc', api_name => 'open-ils.circ.copy_location.retrieve', -- 2.11.0