LP1908743 Staff catalog honors org-not-pickup-lib
authorBill Erickson <berickxx@gmail.com>
Mon, 11 Jan 2021 19:15:33 +0000 (14:15 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Tue, 16 Feb 2021 15:31:41 +0000 (10:31 -0500)
In the Angular staff catalog, disable org units in the pickup library
selector that have the 'opac.holds.org_unit_not_pickup_lib' org unit
setting applied, plus those that have false values for can-have-users or
can-have-vols.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm

index 02696dd..0e764ff 100644 (file)
@@ -82,7 +82,7 @@
         </div>
         <div class="col-lg-6">
           <eg-org-select (onChange)="pickupLib = $event ? $event.id() : null"
-            [applyOrgId]="pickupLib"></eg-org-select>
+            [disableOrgs]="disableOrgs" [applyOrgId]="pickupLib"></eg-org-select>
         </div>
       </div>
       <div class="row mt-2">
index 02f9a4e..47b5fc0 100644 (file)
@@ -86,6 +86,9 @@ export class HoldComponent implements OnInit {
 
     puLibWsFallback = false;
 
+    // Orgs which are not valid pickup locations
+    disableOrgs: number[] = [];
+
     @ViewChild('patronSearch', {static: false})
       patronSearch: PatronSearchDialogComponent;
 
@@ -132,6 +135,22 @@ export class HoldComponent implements OnInit {
         this.store.getItem('circ.staff_placed_holds_fallback_to_ws_ou')
         .then(setting => this.puLibWsFallback = setting === true);
 
+        this.org.list().forEach(org => {
+            if (org.ou_type().can_have_users() === 'f' ||
+                org.ou_type().can_have_vols() === 'f') {
+                this.disableOrgs.push(org.id());
+            }
+        });
+
+        this.net.request('open-ils.actor',
+            'open-ils.actor.settings.value_for_all_orgs',
+            null, 'opac.holds.org_unit_not_pickup_lib'
+        ).subscribe(resp => {
+            if (resp.summary.value) {
+                this.disableOrgs.push(Number(resp.org_unit));
+            }
+        });
+
         if (!Array.isArray(this.holdTargets)) {
             this.holdTargets = [this.holdTargets];
         }
index f627a16..b538af3 100644 (file)
@@ -314,5 +314,74 @@ sub applied_settings {
 }
 
 
+__PACKAGE__->register_method (
+    method      => 'setting_value_for_all_orgs',
+    api_name    => 'open-ils.actor.settings.value_for_all_orgs',
+    stream      => 1,
+    signature => {
+        desc => q/
+            Returns the value applied to all org units for a given org unit
+            setting.
+
+            No auth token is required to access publicly visible org
+            unit settings.  An auth token and necesessary permissions
+            are required to view protected settings.
+        /,
+        params => [
+            {desc => 'authtoken. Optional', type => 'string'},
+            {desc => 'setting', type => 'string'},
+        ],
+        return => {
+            desc => q/
+                Returns a stream of {org_unit => id, summary => summary} 
+                hashes, one per org unit.  The summary is a 
+                actor.cascade_setting_summary hash.
+            /,
+            type => 'object'
+        }
+    }
+);
+
+sub setting_value_for_all_orgs {
+    my ($self, $client, $auth, $setting) = @_;
+
+    my $e = new_editor();
+    my $user_id;
+
+    if ($auth) {
+        # Not required for publicly visible org unit setting values.
+        # If one is provided, though, it should be valid.
+        $e->authtoken($auth);
+        return $e->event unless $e->checkauth;
+        $user_id = $e->requestor->id;
+    }
+
+    # Setting names may only contain letters, numbers, unders, and dots.
+    $setting =~ s/$name_regex//g;
+
+    my $org_ids = $e->json_query({select => {aou => ['id']}, from => 'aou'});
+
+    for my $org_id (map { $_->{id} } @$org_ids) {
+
+        # Use actor.get_cascade_setting since it performs the necessary
+        # permission checks for us.
+        my $summary = $e->json_query({from => [
+            'actor.get_cascade_setting', $setting, $org_id, $user_id, undef]})->[0];
+
+        # It makes no sense to call this API with user/workstation settings.
+        return OpenILS::Event->new('BAD_PARAMS',
+            desc => 'This API does not support user/workstation settings'
+        ) if (
+            ($summary->{has_user_setting} || '') eq 't' || 
+            ($summary->{has_workstation_setting} || '') eq 't'
+        );
+
+        $client->respond({org_unit => $org_id, summary => $summary});
+    }
+
+    return undef;
+}
+
+
 
 1;