Fixups and inline documentation
authorMike Rylander <miker@esilibrary.com>
Wed, 3 Aug 2016 18:31:17 +0000 (14:31 -0400)
committerMike Rylander <miker@esilibrary.com>
Wed, 3 Aug 2016 18:31:17 +0000 (14:31 -0400)
Signed-off-by: Mike Rylander <miker@esilibrary.com>
Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircNotify.pm

index 2ecd618..3776c0d 100644 (file)
        <event code='7026' textcode='COPY_STATUS_LOST_AND_PAID'>
                <desc xml:lang="en-US">Copy is marked as lost and paid</desc>
        </event>
+       <event code='7028' textcode='PATRON_CIRC_MISMATCH'>
+               <desc xml:lang="en-US">Potentially notified patron does not own the circulation.</desc>
+       </event>
 
 
        <!-- ================================================================ -->
index e819936..c3c5974 100644 (file)
@@ -44,19 +44,20 @@ sub circ_batch_notify {
     my $circs = $e->search_action_circulation({ id => $circlist });
     return $e->event if $e->event;
 
+    my $hook = 'circ.checkout.batch_notify';
+    $hook .= '.session' if $self->api_name =~ /session/;
+
     for my $circ (@$circs) {
-        return undef if $circ->usr != $patronid;
+        # WISHLIST: This may become more sophisticated and check "friend" permissions
+        # in the future, at lease in the non-session variant.
+        return OpenILS::Event->new('PATRON_CIRC_MISMATCH') if $circ->usr != $patronid;
         return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $circ->circ_lib);
     }
 
-    my $hook = 'circ.checkout.batch_notify';
-    $hook .= '.session' if $self->api_name =~ /session/;
-        
-
     my %events;
     my $multi = OpenSRF::MultiSession->new(
         app                 => 'open-ils.trigger',
-        cap                 => 3, # 
+        cap                 => 3,
         success_handler     => sub {
             my $self = shift;
             my $req = shift;
@@ -80,10 +81,14 @@ sub circ_batch_notify {
     $multi->session_wait(1);
     $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
 
+    if (!keys(%events)) {
+        return $client->respond_complete;
+    }
+
     my @out;
     $multi = OpenSRF::MultiSession->new(
         app                 => 'open-ils.trigger',
-        cap                 => 3, # 
+        cap                 => 3,
         success_handler     => sub {
             my $self = shift;
             my $req = shift;
@@ -97,15 +102,42 @@ sub circ_batch_notify {
     ) for ( sort keys %events );
 
     $multi->session_wait(1);
-    $client->respond_complete;
+    return $client->respond_complete;
 }
 __PACKAGE__->register_method(
-    method => 'circ_batch_notify',
+    method   => 'circ_batch_notify',
     api_name => 'open-ils.circ.checkout.batch_notify',
+    stream   => 1,
+    signature => {
+        desc   => 'Creates and fires grouped events for a set of circulation IDs',
+        params => [
+            { name => 'authtoken', desc => 'Staff auth token',   type => 'string' },
+            { name => 'patronid', desc => 'actor.usr.id of patron which must own the circulations', type => 'number' }
+            { name => 'circlist', desc => 'Arrayref of circulation IDs to bundle into the event group', type => 'array' }
+        ],
+        return => {
+            desc => 'Event on error, stream of zero or more event group firing results '.
+                    'otherwise. See: open-ils.trigger.event_group.fire'
+        }
+    }
 );
 __PACKAGE__->register_method(
-    method => 'circ_batch_notify',
+    method   => 'circ_batch_notify',
     api_name => 'open-ils.circ.checkout.batch_notify.session',
+    stream   => 1,
+    signature => {
+        desc   => 'Creates and fires grouped events for a set of circulation IDs.  '.
+                  'For use by session-specific actions such as self-checkout or circ desk checkout.',
+        params => [
+            { name => 'authtoken', desc => 'Staff auth token',   type => 'string' },
+            { name => 'patronid', desc => 'actor.usr.id of patron which must own the circulations', type => 'number' }
+            { name => 'circlist', desc => 'Arrayref of circulation IDs to bundle into the event group', type => 'array' }
+        ],
+        return => {
+            desc => 'Event on error, stream of zero or more event group firing results '.
+                    'otherwise. See: open-ils.trigger.event_group.fire'
+        }
+    }
 );
 
 1;