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
}
}
+ 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) {
constructor(
private auth: AuthService,
private store: StoreService,
- private org: OrgService
- ) {}
+ private org: OrgService,
+ private perm: PermService
+ ) {
+ this.permLimitOrgs = [];
+ }
ngOnInit() {
}
}
+ //
+ 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 {
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.