LP1888723 Item location select honors context org
authorBill Erickson <berickxx@gmail.com>
Fri, 28 Aug 2020 19:16:20 +0000 (15:16 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Sun, 15 Aug 2021 23:56:57 +0000 (19:56 -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>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts

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