From 76aa79378e5e4f63e0b8f450c0025fe2ab943372 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 11 Jan 2021 14:15:33 -0500 Subject: [PATCH] LP1908743 Staff catalog honors org-not-pickup-lib 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 Signed-off-by: Terran McCanna Signed-off-by: Chris Sharp --- .../staff/catalog/hold/hold.component.html | 2 +- .../app/staff/catalog/hold/hold.component.ts | 19 +++++ .../lib/OpenILS/Application/Actor/Settings.pm | 69 +++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html index 02696dd76e..0e764ff9d6 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html @@ -82,7 +82,7 @@
+ [disableOrgs]="disableOrgs" [applyOrgId]="pickupLib">
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts index 02f9a4e333..47b5fc09b1 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts @@ -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]; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm index f627a1638f..b538af377e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm @@ -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; -- 2.43.2