From a782f2116a9e96e1b59420f79bf563ba85d5319c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 12 Apr 2021 18:01:32 -0400 Subject: [PATCH] LP1904036 user perm editor Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../src/app/staff/circ/patron/perms.component.html | 13 ++++- .../src/app/staff/circ/patron/perms.component.ts | 55 ++++++++++++++++++++-- 2 files changed, 61 insertions(+), 7 deletions(-) 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 index 67ad3fcc14..7962dee297 100644 --- 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 @@ -1,7 +1,7 @@
- +
@@ -37,13 +37,22 @@
{{perm.code()}}
+
+ +
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 index aba79b1d7e..cad6c8b561 100644 --- 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 @@ -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 } -- 2.11.0