From 61cbf11222e7f0e657ae61815efad4466ff35204 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 Signed-off-by: Ruth Frasur Signed-off-by: Galen Charlton --- .../item-location-select.component.ts | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 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 f07e8566fe..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,28 +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]; - // then include ancestors - this.filterOrgs.forEach(ou => { - this.org.ancestors(ou, true).forEach(anc => this.filterOrgs.push(anc)); - }); - return this.filterOrgs; - }); + 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.43.2