From 18d7ee6efe4e94352dfd4ebd48b7ec95b9d50475 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 1 Aug 2018 17:50:08 -0400 Subject: [PATCH] LP#1775466 Add limit perm option to org select Signed-off-by: Bill Erickson --- .../app/share/org-select/org-select.component.ts | 37 ++++++++++++++++++++-- .../src/app/staff/sandbox/sandbox.component.html | 7 ++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts index 539b2fe326..bd63ed5b96 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts @@ -12,6 +12,7 @@ import {AuthService} from '@eg/core/auth.service'; import {StoreService} from '@eg/core/store.service'; import {OrgService} from '@eg/core/org.service'; import {IdlObject} from '@eg/core/idl.service'; +import {PermService} from '@eg/core/perm.service'; import {NgbTypeahead, NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap'; // Use a unicode char for spacing instead of ASCII=32 so the browser @@ -80,6 +81,11 @@ export class OrgSelectComponent implements OnInit { } } + permLimitOrgs: number[]; + @Input() set limitPerms(perms: string[]) { + this.applyPermLimitOrgs(perms); + } + // Modify the selected org unit by ID via data binding. // This WILL result in an onChange event firing. @Input() set applyOrgId(id: number) { @@ -95,8 +101,11 @@ export class OrgSelectComponent implements OnInit { constructor( private auth: AuthService, private store: StoreService, - private org: OrgService - ) {} + private org: OrgService, + private perm: PermService + ) { + this.permLimitOrgs = []; + } ngOnInit() { @@ -118,6 +127,23 @@ export class OrgSelectComponent implements OnInit { } } + // + applyPermLimitOrgs(perms: string[]) { + + if (!perms || perms.length === 0) { + this.permLimitOrgs = []; + return; + } + + // NOTE: If permLimitOrgs is useful in a non-staff context + // we need to change this to support non-staff perm checks. + this.perm.hasWorkPermAt(perms, true).then(permMap => { + this.permLimitOrgs = + // safari-friendly version of Array.flat() + Object.values(permMap).reduce((acc,val) => acc.concat(val), []); + }); + } + // Format for display in the selector drop-down and input. formatForDisplay(org: IdlObject): OrgDisplay { return { @@ -155,6 +181,13 @@ export class OrgSelectComponent implements OnInit { this.hidden.filter(id => org.id() === id).length === 0 ); + if (this.permLimitOrgs && this.permLimitOrgs.length) { + // Avoid showing org units where the user does + // not have the requested permission. + orgs = orgs.filter(org => + this.permLimitOrgs.includes(org.id())); + } + if (term !== '_CLICK_') { // For search-driven events, limit to the matching // org units. diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index db47b59a7e..0f76d51086 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -58,6 +58,13 @@
+
+ Org select with limit perms +
+
+ + +
-- 2.11.0