LP1904036 user perm editor
authorBill Erickson <berickxx@gmail.com>
Mon, 12 Apr 2021 22:01:32 +0000 (18:01 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:31 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.html
Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.ts

index 67ad3fc..7962dee 100644 (file)
@@ -1,7 +1,7 @@
 
 <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>
index aba79b1..cad6c8b 100644 (file)
@@ -11,12 +11,13 @@ import {PermService} from '@eg/core/perm.service';
 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[];
@@ -30,9 +31,16 @@ export class PatronPermsComponent implements OnInit {
 
     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,
@@ -52,53 +60,90 @@ export class PatronPermsComponent implements OnInit {
         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
     }