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';
EgIdlService,
EgNetService,
EgAuthService,
+ EgPermService,
EgPcrudService,
EgOrgService
],
// 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',
canHaveUsers?: boolean;
canHaveVolumes?: boolean;
opacVisible?: boolean;
+ inList?: number[];
+ notInList?: number[];
}
interface OrgSettingsBatch {
/**
* 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 => {
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);
});
--- /dev/null
+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<HasPermAtResult> {
+ 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<HasPermHereResult> {
+ 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;
+ });
+ }
+}
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';
private net: EgNetService,
private store: EgStoreService,
private auth: EgAuthService,
- private org: EgOrgService
+ private org: EgOrgService,
+ private perm: EgPermService
) {}
ngOnInit() {
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 {
// Components available to all staff/sub modules
EgOrgSelectComponent,
EgConfirmDialogComponent,
- CommonModule,
FormsModule,
NgbModule
]
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';