LP1888723 Item location select honors context org
authorBill Erickson <berickxx@gmail.com>
Fri, 28 Aug 2020 19:16:20 +0000 (15:16 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 10 Sep 2020 21:22:46 +0000 (17:22 -0400)
The Angular <eg-item-location-select /> 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 <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts

index d5a3baf..97ffc53 100644 (file)
@@ -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<number[]> {
-        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 {