From 1603a9e91c5165c52da3dee9e0f3a86f190bdbbf Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 9 Aug 2010 18:30:25 +0000 Subject: [PATCH] Add middle layer functions for maintaining actor.usr_saved_search. M Open-ILS/src/perlmods/OpenILS/Application/Actor.pm git-svn-id: svn://svn.open-ils.org/ILS/trunk@17140 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 9d6c0b508..615b79ba7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -4095,6 +4095,120 @@ sub user_visible_circs { return undef; } +__PACKAGE__->register_method( + method => "user_saved_search_cud", + api_name => "open-ils.actor.user.saved_search.cud", + stream => 1, + signature => { + desc => 'Create/Update/Delete Access to user saved searches', + params => [ + { desc => 'Authentication token', type => 'string' }, + { desc => 'Saved Search Object', type => 'object', class => 'auss' } + ], + return => { + desc => q/The retrieved or updated saved search object, or id of a deleted object; Event on error/, + class => 'auss' + } + } +); + +__PACKAGE__->register_method( + method => "user_saved_search_cud", + api_name => "open-ils.actor.user.saved_search.retrieve", + stream => 1, + signature => { + desc => 'Retrieve a saved search object', + params => [ + { desc => 'Authentication token', type => 'string' }, + { desc => 'Saved Search ID', type => 'number' } + ], + return => { + desc => q/The saved search object, Event on error/, + class => 'auss' + } + } +); + +sub user_saved_search_cud { + my( $self, $client, $auth, $search ) = @_; + my $e = new_editor( authtoken=>$auth ); + return $e->die_event unless $e->checkauth; + + my $o_search; # prior version of the object, if any + my $res; # to be returned + + # branch on the operation type + + if( $self->api_name =~ /retrieve/ ) { # Retrieve + + # Get the old version, to check ownership + $o_search = $e->retrieve_actor_usr_saved_search( $search ) + or return $e->die_event; + + # You can't read somebody else's search + return OpenILS::Event->new('BAD_PARAMS') + unless $o_search->owner == $e->requestor->id; + + $res = $o_search; + + } else { + + $e->xact_begin; # start an editor transaction + + if( $search->isnew ) { # Create + + # You can't create a search for somebody else + return OpenILS::Event->new('BAD_PARAMS') + unless $search->owner == $e->requestor->id; + + $e->create_actor_usr_saved_search( $search ) + or return $e->die_event; + + $res = $search->id; + + } elsif( $search->ischanged ) { # Update + + # You can't change ownership of a search + return OpenILS::Event->new('BAD_PARAMS') + unless $search->owner == $e->requestor->id; + + # Get the old version, to check ownership + $o_search = $e->retrieve_actor_usr_saved_search( $search->id ) + or return $e->die_event; + + # You can't update somebody else's search + return OpenILS::Event->new('BAD_PARAMS') + unless $o_search->owner == $e->requestor->id; + + # Do the update + $e->update_actor_usr_saved_search( $search ) + or return $e->die_event; + + $res = $search; + + } elsif( $search->isdeleted ) { # Delete + + # Get the old version, to check ownership + $o_search = $e->retrieve_actor_usr_saved_search( $search->id ) + or return $e->die_event; + + # You can't delete somebody else's search + return OpenILS::Event->new('BAD_PARAMS') + unless $o_search->owner == $e->requestor->id; + + # Do the delete + $e->delete_actor_usr_saved_search( $o_search ) + or return $e->die_event; + + $res = $search->id; + } + + $e->commit; + } + + return $res; +} + 1; -- 2.11.0