[open-ils-commits] r17140 - trunk/Open-ILS/src/perlmods/OpenILS/Application (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Aug 9 14:30:29 EDT 2010


Author: scottmk
Date: 2010-08-09 14:30:25 -0400 (Mon, 09 Aug 2010)
New Revision: 17140

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
Add middle layer functions for maintaining actor.usr_saved_search.

M    Open-ILS/src/perlmods/OpenILS/Application/Actor.pm


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-08-09 14:45:26 UTC (rev 17139)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-08-09 18:30:25 UTC (rev 17140)
@@ -4095,6 +4095,120 @@
     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;



More information about the open-ils-commits mailing list