From 47693d81f3c7f5178e5df890b3ab55ccaac7a19a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 28 Aug 2020 15:16:20 -0400 Subject: [PATCH] LP1888723 Item location select honors context org The Angular component now limits the locations to display to those within the specified context org unit. Instead of acting as the source of context org units, the permFilter org units now act as limiters. This is done so that users with global permissions won't by default result in retrieving all copy locations. In cases where all are needed, however, they can still be retrieved by setting the context org unit appropriately. Signed-off-by: Bill Erickson --- .../item-location-select.component.ts | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts b/Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts index d5a3baf4e0..97ffc530a6 100644 --- a/Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts @@ -153,21 +153,34 @@ export class ItemLocationSelectComponent return this.pcrud.retrieve('acpl', id).toPromise() .then(loc => { this.cache[loc.id()] = loc; - this.comboBox.entries.push( + this.comboBox.addAsyncEntry( {id: loc.id(), label: loc.name(), userdata: loc}); }); } setFilterOrgs(): Promise { - if (this.permFilter) { - return this.perm.hasWorkPermAt([this.permFilter], true) - .then(values => this.filterOrgs = values[this.permFilter]); + const org = this.contextOrgId || this.auth.user().ws_ou(); + const contextOrgIds = this.org.ancestors(org, true); + + if (!this.permFilter) { + return Promise.resolve(this.filterOrgs = contextOrgIds); } - const org = this.contextOrgId || this.auth.user().ws_ou(); - this.filterOrgs = this.org.ancestors(this.contextOrgId, true); + return this.perm.hasWorkPermAt([this.permFilter], true) + .then(values => { + // Always limit the org units to /at most/ those within + // scope of the context org ID. - return Promise.resolve(this.filterOrgs); + const permOrgIds = values[this.permFilter]; + const trimmedOrgIds = []; + permOrgIds.forEach(orgId => { + if (contextOrgIds.includes(orgId)) { + trimmedOrgIds.push(orgId); + } + }); + + return this.filterOrgs = trimmedOrgIds; + }); } orgName(orgId: number): string { -- 2.11.0