LP#1879983: new APIs to implement claiming staging
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 Jun 2020 18:46:06 +0000 (14:46 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 Jun 2020 18:46:06 +0000 (14:46 -0400)
This adds two new open-ils.curbside methods to allow a staff
member to claim responsibility for staging a to-be-staged
appointment and to release such a claim:

open-ils.circ.curbside.claim_staging
open-ils.circ.curbside.unclaim_staging

This patch also tweaks the freshness check for the to-be-staged
queue to account for changes in claiming and unclaiming appointments.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm

index 8379bf3..80d6f0f 100644 (file)
@@ -419,7 +419,7 @@ sub fetch_to_be_staged {
     },{
         ($limit  ? (limit  => $limit) : ()),
         ($offset ? (offset => $offset) : ()),
-        flesh => 3, flesh_fields => {acsp => ['patron'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
+        flesh => 3, flesh_fields => {acsp => ['patron','stage_staff'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
         order_by => { acsp => 'slot' }
     }]);
 
@@ -489,9 +489,9 @@ sub fetch_latest_to_be_staged {
             { class => acsp => field => slot => direction => 'desc' },
             { class => acsp => field => id   => direction => 'desc' }
         ]
-    }],{ idlist => 1 });
+    }]);
 
-    return md5_hex( join(',', @$slots) );
+    return md5_hex( join(',', map { join('-', $_->id(), $_->stage_staff() // '') } @$slots) );
 }
 __PACKAGE__->register_method(
     method   => "fetch_latest_to_be_staged",
@@ -773,6 +773,56 @@ __PACKAGE__->register_method(
     }
 );
 
+sub manage_staging_claim {
+    my ($self, $conn, $authtoken, $appointment) = @_;
+    my $e = new_editor(xact => 1, authtoken => $authtoken);
+    return $e->die_event unless $e->checkauth;
+    return $e->die_event unless $e->allowed("STAFF_LOGIN");
+
+    my $slot = $e->retrieve_action_curbside($appointment);
+    return undef unless ($slot);
+
+    if ($self->api_name =~ /unclaim/) {
+        $slot->clear_stage_staff();
+    } else {
+        $slot->stage_staff($e->requestor->id);
+    }
+
+    $e->update_action_curbside($slot) or return $e->die_event;
+    $e->commit;
+
+    return $e->retrieve_action_curbside([
+        $slot->id, {
+            flesh => 3,
+            flesh_fields => {acsp => ['patron','stage_staff'], au => ['card','standing_penalties'], ausp => ['standing_penalty']},
+        }
+    ]);
+}
+__PACKAGE__->register_method(
+    method   => "manage_staging_claim",
+    api_name => "open-ils.curbside.claim_staging",
+    signature => {
+        params => [
+            {type => 'string', desc => 'Authentication token'},
+            {type => 'number', desc => 'Appointment ID'},
+        ],
+        return => { desc => 'Appointment on success, nothing when no appointment found, '.
+                            'an ILS Event on permission error'}
+    }
+);
+__PACKAGE__->register_method(
+    method   => "manage_staging_claim",
+    api_name => "open-ils.curbside.unclaim_staging",
+    signature => {
+        params => [
+            {type => 'string', desc => 'Authentication token'},
+            {type => 'number', desc => 'Appointment ID'},
+        ],
+        return => { desc => 'Appointment on success, nothing when no appointment found, '.
+                            'an ILS Event on permission error'}
+    }
+);
+
 sub mark_staged {
     my ($self, $conn, $authtoken, $appointment) = @_;
     my $e = new_editor(xact => 1, authtoken => $authtoken);