LP1904036 user perm editor
authorBill Erickson <berickxx@gmail.com>
Tue, 6 Apr 2021 18:08:54 +0000 (14:08 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:30 +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 [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.ts [new file with mode: 0644]

diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.html
new file mode 100644 (file)
index 0000000..67ad3fc
--- /dev/null
@@ -0,0 +1,51 @@
+
+<div class="row" *ngIf="loading">
+  <div class="col-lg-6 offset-lg-3">
+    <eg-progress-inline></eg-progress-inline>
+  </div>
+</div>
+
+<ng-container *ngIf="!loading">
+  <h3 i18n>Working Location(s)</h3>
+
+  <div class="striped-rows-odd mt-3 mb-3">
+    <div class="row mt-2 pt-2 pb-2" *ngFor="let org of workableOrgs">
+      <div class="col-lg-12">
+        <div class="form-check form-check-inline">
+          <input class="form-check-input" type="checkbox" id="work-org-{{org.id()}}" 
+            [disabled]="!canAssignWorkOrgs[org.id()]" [(ngModel)]="workOuSelector[org.id()]">
+          <label class="form-check-label" for="work-org-{{org.id()}}" i18n>
+            {{org.shortname()}} ({{org.name()}})
+          </label>
+        </div>
+      </div>
+    </div>
+  </div>
+
+  <hr class="mt-2 mb-2"/>
+
+  <h3 i18n>User Permissions</h3>
+
+  <div class="striped-rows-odd mt-3">
+    <div class="row pt-1 pb-1">
+      <div class="col-lg-5 font-weight-bold" i18n>Permission</div>
+      <div class="col-lg-1 font-weight-bold" i18n>Applied</div>
+      <div class="col-lg-2 font-weight-bold" i18n>Depth</div>
+      <div class="col-lg-2 font-weight-bold" i18n>Grantable</div>
+    </div>
+    <div class="row pt-1 pb-1" *ngFor="let perm of allPerms">
+      <div class="col-lg-5">{{perm.code()}}</div>
+      <div class="col-lg-1">
+        <input class="form-check-input ml-0 pl-0" type="checkbox"
+          [(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>
+        </select>
+      </div>
+    </div>
+  </div>
+</ng-container>
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/perms.component.ts
new file mode 100644 (file)
index 0000000..ebaf12a
--- /dev/null
@@ -0,0 +1,106 @@
+import {Component, ViewChild, Input, OnInit, AfterViewInit} from '@angular/core';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {tap} from 'rxjs/operators';
+import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {OrgService} from '@eg/core/org.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+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';
+
+@Component({
+  templateUrl: 'perms.component.html',
+  selector: 'eg-patron-perms'
+})
+export class PatronPermsComponent implements OnInit {
+
+    @Input() patronId: number;
+    workOuMaps: IdlObject[];
+    workOuSelector: {[orgId: number]: boolean} = {};
+    workableOrgs: IdlObject[] = [];
+    canAssignWorkOrgs: {[orgId: number]: boolean} = {};
+    myPermMaps: IdlObject[] = [];
+    userPermMaps: IdlObject[] = [];
+    allPerms: IdlObject[] = [];
+    loading = true;
+
+    permsApplied: {[id: number]: boolean} = {};
+    permDepths: {[id: number]: number} = {};
+    permGrantable: {[id: number]: boolean} = {};
+    orgDepths: number[];
+
+    constructor(
+        private idl: IdlService,
+        private org: OrgService,
+        private auth: AuthService,
+        private net: NetService,
+        private pcrud: PcrudService,
+        private perms: PermService
+    ) {
+    }
+
+    ngOnInit() {
+
+        this.workableOrgs = this.org.filterList({canHaveUsers: true})
+        .sort((o1, o2) => o1.shortname() < o2.shortname() ? -1 : 1);
+
+        const depths = {};
+        this.org.list().forEach(org => depths[org.ou_type().depth()] = true);
+        this.orgDepths = Object.keys(depths).map(d => Number(d)).sort();
+
+        this.net.request(
+            'open-ils.actor',
+            'open-ils.actor.user.get_work_ous',
+            this.auth.token(), this.patronId).toPromise()
+
+        .then(maps => {
+            this.workOuMaps = maps;
+            maps.forEach(map => this.workOuSelector[map.work_ou()] = true);
+        })
+
+        .then(_ => { // All permissions
+            return this.pcrud.retrieveAll('ppl', {order_by: {ppl: 'code'}})
+            .pipe(tap(perm => this.allPerms.push(perm))).toPromise();
+        })
+
+        .then(_ => { // Target user permissions
+            return this.net.request(
+                'open-ils.actor',
+                'open-ils.actor.permissions.user_perms.retrieve',
+                this.auth.token(), this.patronId).toPromise()
+            .then(maps => {
+                this.userPermMaps = maps;
+                maps.forEach(m => {
+                    this.permsApplied[m.perm()] = true;
+                    this.permDepths[m.perm()] = m.depth();
+                    this.permGrantable[m.perm()] = m.grantable() === 't'
+
+                });
+            });
+        })
+
+        .then(_ => { // My permissions
+            return this.net.request(
+                'open-ils.actor',
+                'open-ils.actor.permissions.user_perms.retrieve',
+                this.auth.token()).toPromise()
+            .then(perms => this.myPermMaps = perms);
+        })
+
+        .then(_ => this.perms.hasWorkPermAt(['ASSIGN_WORK_ORG_UNIT'], true))
+        .then(perms => {
+            const orgIds = perms.ASSIGN_WORK_ORG_UNIT;
+            orgIds.forEach(id => this.canAssignWorkOrgs[id] = true);
+        })
+        .then(_ => this.loading = false);
+    }
+
+    save() {
+        // open-ils.actor.user.work_ous.update
+    }
+}
+