From: Bill Erickson Date: Tue, 26 Dec 2017 23:09:38 +0000 (-0500) Subject: LP#626157 ang2 perms X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=628cf4be3a5fea52e1d2bba6315044eb81847992;p=working%2FEvergreen.git LP#626157 ang2 perms Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/eg2-src/src/app/app.module.ts b/Open-ILS/eg2-src/src/app/app.module.ts index d9d06e3b27..ce8f2c15a3 100644 --- a/Open-ILS/eg2-src/src/app/app.module.ts +++ b/Open-ILS/eg2-src/src/app/app.module.ts @@ -19,6 +19,7 @@ import {EgStoreService} from '@eg/core/store'; import {EgIdlService} from '@eg/core/idl'; import {EgNetService} from '@eg/core/net'; import {EgAuthService} from '@eg/core/auth'; +import {EgPermService} from '@eg/core/perm'; import {EgPcrudService} from '@eg/core/pcrud'; import {EgOrgService} from '@eg/core/org'; @@ -39,6 +40,7 @@ import {EgOrgService} from '@eg/core/org'; EgIdlService, EgNetService, EgAuthService, + EgPermService, EgPcrudService, EgOrgService ], diff --git a/Open-ILS/eg2-src/src/app/core/auth.ts b/Open-ILS/eg2-src/src/app/core/auth.ts index ac2120676f..f6688c2f39 100644 --- a/Open-ILS/eg2-src/src/app/core/auth.ts +++ b/Open-ILS/eg2-src/src/app/core/auth.ts @@ -204,8 +204,6 @@ export class EgAuthService { // to expire on the server. let pollTime = this.authtime() * 1000 + 5000; - console.debug('EgAuth session poll at ' + pollTime); - this.pollTimeout = setTimeout(() => { this.net.request( 'open-ils.auth', diff --git a/Open-ILS/eg2-src/src/app/core/org.ts b/Open-ILS/eg2-src/src/app/core/org.ts index bc1124aa6c..8508c41da2 100644 --- a/Open-ILS/eg2-src/src/app/core/org.ts +++ b/Open-ILS/eg2-src/src/app/core/org.ts @@ -11,6 +11,8 @@ interface OrgFilter { canHaveUsers?: boolean; canHaveVolumes?: boolean; opacVisible?: boolean; + inList?: number[]; + notInList?: number[]; } interface OrgSettingsBatch { @@ -43,9 +45,10 @@ export class EgOrgService { /** * Returns a list of org units that match the selected criteria. + * All filters must match for an org to be included in the result set. * Unset filter options are ignored. */ - filterList(filter: OrgFilter, asId: boolean): any[] { + filterList(filter: OrgFilter, asId?: boolean): any[] { let list = []; this.list().forEach(org => { @@ -61,6 +64,12 @@ export class EgOrgService { if (ov && !this.opacVisible(org)) return; if (ov === false && this.opacVisible(org)) return; + if (filter.inList && filter.inList.indexOf(org.id()) == -1) + return; + + if (filter.notInList && filter.notInList.indexOf(org.id()) > -1) + return; + // All filter tests passed. Add it to the list list.push(asId ? org.id() : org); }); diff --git a/Open-ILS/eg2-src/src/app/core/perm.ts b/Open-ILS/eg2-src/src/app/core/perm.ts new file mode 100644 index 0000000000..6f7cd9faae --- /dev/null +++ b/Open-ILS/eg2-src/src/app/core/perm.ts @@ -0,0 +1,58 @@ +import {Injectable} from '@angular/core'; +import {EgNetService} from './net'; +import {EgOrgService} from './org'; +import {EgAuthService} from './auth'; + +interface HasPermAtResult { + [permName: string]: number[]; +} + +interface HasPermHereResult { + [permName: string]: boolean; +} + +@Injectable() +export class EgPermService { + + constructor( + private net: EgNetService, + private org: EgOrgService, + private auth: EgAuthService, + ) {} + + // workstation not required. + hasWorkPermAt(permNames: string[], asId?: boolean): Promise { + return this.net.request( + 'open-ils.actor', + 'open-ils.actor.user.has_work_perm_at.batch', + this.auth.token(), permNames + ).toPromise().then(resp => { + var answer: HasPermAtResult = {}; + permNames.forEach(perm => { + var orgs = []; + resp[perm].forEach(oneOrg => { + orgs = orgs.concat(this.org.descendants(oneOrg, asId)); + }); + answer[perm] = orgs; + }); + + return answer; + }); + } + + // workstation required + hasWorkPermHere(permNames: string[]): Promise { + let wsId: number = +this.auth.user().wsid(); + + if (!wsId) + return Promise.reject('hasWorkPermHere requires a workstation'); + + return this.hasWorkPermAt(permNames, true).then(resp => { + let answer: HasPermHereResult = {}; + Object.keys(resp).forEach(perm => { + answer[perm] = resp[perm].indexOf(wsId) > -1; + }); + return answer; + }); + } +} diff --git a/Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.ts b/Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.ts index 96d0784d53..73827a7d8a 100644 --- a/Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.ts +++ b/Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.ts @@ -3,6 +3,7 @@ import {Router, ActivatedRoute} from '@angular/router'; import {EgStoreService} from '@eg/core/store'; import {EgIdlObject} from '@eg/core/idl'; import {EgNetService} from '@eg/core/net'; +import {EgPermService} from '@eg/core/perm'; import {EgAuthService} from '@eg/core/auth'; import {EgOrgService} from '@eg/core/org'; import {EgEventService} from '@eg/core/event'; @@ -44,7 +45,8 @@ export class WorkstationsComponent implements OnInit { private net: EgNetService, private store: EgStoreService, private auth: EgAuthService, - private org: EgOrgService + private org: EgOrgService, + private perm: EgPermService ) {} ngOnInit() { @@ -60,8 +62,15 @@ export class WorkstationsComponent implements OnInit { if (rm) this.removeSelected(this.removeWorkstation = rm) }) - // TODO: perm limits required here too - this.disableOrgs = this.org.filterList({canHaveUsers : true}, true); + this.perm.hasWorkPermAt(['REGISTER_WORKSTATION'], true) + .then(perms => { + // Disable org units that cannot have users and any + // that this user does not have work perms for. + this.disableOrgs = + this.org.filterList({canHaveUsers : false}, true) + .concat(this.org.filterList( + {notInList : perms.REGISTER_WORKSTATION}, true)); + }); } selected(): Workstation { diff --git a/Open-ILS/eg2-src/src/app/staff/app.module.ts b/Open-ILS/eg2-src/src/app/staff/app.module.ts index 39561db86e..6cefff5698 100644 --- a/Open-ILS/eg2-src/src/app/staff/app.module.ts +++ b/Open-ILS/eg2-src/src/app/staff/app.module.ts @@ -32,7 +32,6 @@ import {EgConfirmDialogComponent} from '@eg/share/confirm-dialog.component'; // Components available to all staff/sub modules EgOrgSelectComponent, EgConfirmDialogComponent, - CommonModule, FormsModule, NgbModule ] diff --git a/Open-ILS/eg2-src/src/app/staff/resolver.service.ts b/Open-ILS/eg2-src/src/app/staff/resolver.service.ts index 28e228fd50..a9c393e9ec 100644 --- a/Open-ILS/eg2-src/src/app/staff/resolver.service.ts +++ b/Open-ILS/eg2-src/src/app/staff/resolver.service.ts @@ -2,8 +2,7 @@ import {Injectable} from '@angular/core'; import {Location} from '@angular/common'; import {Observable, Observer} from 'rxjs/Rx'; import {Router, Resolve, RouterStateSnapshot, - ActivatedRoute, - ActivatedRouteSnapshot} from '@angular/router'; + ActivatedRoute, ActivatedRouteSnapshot} from '@angular/router'; import {EgStoreService} from '@eg/core/store'; import {EgNetService} from '@eg/core/net'; import {EgAuthService} from '@eg/core/auth';