<div class="row" *ngIf="loading">
<div class="col-lg-6 offset-lg-3">
- <eg-progress-inline></eg-progress-inline>
+ <eg-progress-inline #progress></eg-progress-inline>
</div>
</div>
<div class="col-lg-5">{{perm.code()}}</div>
<div class="col-lg-1">
<input class="form-check-input ml-0 pl-0" type="checkbox"
+ [disabled]="!canGrantPerm(perm)"
[(ngModel)]="permsApplied[perm.id()]"/>
</div>
<div class="col-lg-2">
<select class="form-control" [(ngModel)]="permDepths[perm.id()]">
- <option *ngFor="let depth of orgDepths" [value]="depth">{{depth}}</option>
+ <ng-container *ngFor="let depth of orgDepths">
+ <option [disabled]="depth < canGrantPermAtDepth(perm)"
+ [value]="depth">{{depth}}</option>
+ </ng-container>
</select>
</div>
+ <div class="col-lg-2">
+ <input class="form-check-input ml-0 pl-0" type="checkbox"
+ [disabled]="!canGrantPerm(perm)"
+ [(ngModel)]="permsGrantable[perm.id()]"/>
+ </div>
</div>
</div>
</ng-container>
import {ServerStoreService} from '@eg/core/server-store.service';
import {PatronService} from '@eg/staff/share/patron/patron.service';
import {PatronContextService} from './patron.service';
+import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
@Component({
templateUrl: 'perms.component.html',
selector: 'eg-patron-perms'
})
-export class PatronPermsComponent implements OnInit {
+export class PatronPermsComponent implements OnInit, AfterViewInit {
@Input() patronId: number;
workOuMaps: IdlObject[];
permsApplied: {[id: number]: boolean} = {};
permDepths: {[id: number]: number} = {};
- permGrantable: {[id: number]: boolean} = {};
+ permsGrantable: {[id: number]: boolean} = {};
+
+ myPermsApplied: {[id: number]: boolean} = {};
+ myPermDepths: {[id: number]: number} = {};
+ myPermsGrantable: {[id: number]: boolean} = {};
+
orgDepths: number[];
+ @ViewChild('progress') private progress: ProgressInlineComponent;
+
constructor(
private idl: IdlService,
private org: OrgService,
this.org.list().forEach(org => depths[org.ou_type().depth()] = true);
this.orgDepths = Object.keys(depths).map(d => Number(d)).sort();
+ }
+
+ ngAfterViewInit() {
+
+ this.progress.update({max: 9, value: 0});
+
this.net.request(
'open-ils.actor',
'open-ils.actor.user.get_work_ous',
this.auth.token(), this.patronId).toPromise()
.then(maps => {
+ this.progress.increment();
this.workOuMaps = maps;
maps.forEach(map => this.workOuSelector[map.work_ou()] = true);
})
.then(_ => { // All permissions
+ this.progress.increment();
return this.pcrud.retrieveAll('ppl', {order_by: {ppl: 'code'}})
.pipe(tap(perm => this.allPerms.push(perm))).toPromise();
})
.then(_ => { // Target user permissions
+ this.progress.increment();
return this.net.request(
'open-ils.actor',
'open-ils.actor.permissions.user_perms.retrieve',
this.auth.token(), this.patronId).toPromise()
.then(maps => {
+ this.progress.increment();
this.userPermMaps = maps;
maps.forEach(m => {
this.permsApplied[m.perm()] = true;
this.permDepths[m.perm()] = m.depth();
- this.permGrantable[m.perm()] = m.grantable() === 't';
+ this.permsGrantable[m.perm()] = m.grantable() === 't';
});
});
})
.then(_ => { // My permissions
+ this.progress.increment();
return this.net.request(
'open-ils.actor',
'open-ils.actor.permissions.user_perms.retrieve',
this.auth.token()).toPromise()
- .then(perms => this.myPermMaps = perms);
+ .then(maps => {
+ this.myPermMaps = maps
+ maps.forEach(m => {
+ this.myPermsApplied[m.perm()] = true;
+ this.myPermDepths[m.perm()] = m.depth();
+ this.myPermsGrantable[m.perm()] = m.grantable() === 't';
+ });
+ });
+ })
+
+ .then(_ => {
+ this.progress.increment();
+ return this.perms.hasWorkPermAt(['ASSIGN_WORK_ORG_UNIT'], true)
})
- .then(_ => this.perms.hasWorkPermAt(['ASSIGN_WORK_ORG_UNIT'], true))
.then(perms => {
+ this.progress.increment();
const orgIds = perms.ASSIGN_WORK_ORG_UNIT;
orgIds.forEach(id => this.canAssignWorkOrgs[id] = true);
})
+
.then(_ => this.loading = false);
}
+ canGrantPerm(perm: IdlObject): boolean {
+ return this.myPermsGrantable[perm.id()]
+ || this.auth.user().super_user() === 't';
+ }
+
+ canGrantPermAtDepth(perm: IdlObject): number {
+ if (this.auth.user().super_user() === 't') {
+ return this.org.root().ou_type().depth();
+ } else {
+ return this.myPermDepths[perm.id()];
+ }
+ }
+
save() {
// open-ils.actor.user.work_ous.update
}