From d89f1e41ceee898c0261bae9c401023446e3cd11 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 8 Aug 2018 14:41:15 -0400 Subject: [PATCH] LP#1775466 Apache/doc Perm check repairs for admin pages / grids Signed-off-by: Bill Erickson --- .../src/app/share/fm-editor/fm-editor.component.ts | 14 +++++++------- .../share/grid/grid-toolbar-button.component.ts | 22 ++++++++++++++++------ .../src/app/share/grid/grid-toolbar.component.html | 1 + Open-ILS/src/eg2/src/app/share/grid/grid.ts | 1 + .../share/admin-page/admin-page.component.html | 3 ++- .../staff/share/admin-page/admin-page.component.ts | 19 +++++++++++++++++++ 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index ebde00959f..308218a96c 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -153,6 +153,13 @@ export class FmRecordEditorComponent private initRecord(): Promise { + const pc = this.idlDef.permacrud || {}; + this.modePerms = { + view: pc.retrieve ? pc.retrieve.perms : [], + create: pc.create ? pc.create.perms : [], + update: pc.update ? pc.update.perms : [], + }; + if (this.mode === 'update' || this.mode === 'view') { return this.pcrud.retrieve(this.idlClass, this.recId) .toPromise().then(rec => { @@ -168,13 +175,6 @@ export class FmRecordEditorComponent }); } - const pc = this.idlDef.permacrud || {}; - this.modePerms = { - view: pc.retrieve ? pc.retrieve.perms : [], - create: pc.create ? pc.create.perms : [], - update: pc.update ? pc.update.perms : [], - }; - // create a new record from scratch this.pkeyIsEditable = !('pkey_sequence' in this.idlDef); this.record = this.idl.create(this.idlClass); diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts index ae71b18b64..8287483863 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts @@ -13,8 +13,20 @@ export class GridToolbarButtonComponent implements OnInit { @Input() label: string; @Input() action: () => any; + @Input() set disabled(d: boolean) { + // Support asynchronous disabled values by appling directly + // to our button object as values arrive. + if (this.button) { + this.button.disabled = d; + } + } + + button: GridToolbarButton; + // get a reference to our container grid. - constructor(@Host() private grid: GridComponent) {} + constructor(@Host() private grid: GridComponent) { + this.button = new GridToolbarButton(); + } ngOnInit() { @@ -23,11 +35,9 @@ export class GridToolbarButtonComponent implements OnInit { return; } - const btn = new GridToolbarButton(); - btn.label = this.label; - btn.action = this.action; - - this.grid.context.toolbarButtons.push(btn); + this.button.label = this.label; + this.button.action = this.action; + this.grid.context.toolbarButtons.push(this.button); } } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index 48b9e3913e..442bab1d14 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -6,6 +6,7 @@
diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 0c40a7633c..a152fd8c64 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -890,6 +890,7 @@ export class GridToolbarAction { export class GridToolbarButton { label: string; action: () => any; + disabled: boolean; } export class GridToolbarCheckbox { diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html index 9435dc2a32..5f0eadded3 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html @@ -40,7 +40,8 @@ - + diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts index 29d0545246..afe9e97857 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts @@ -6,6 +6,7 @@ import {ToastService} from '@eg/share/toast/toast.service'; import {Pager} from '@eg/share/util/pager'; import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; +import {PermService} from '@eg/core/perm.service'; import {AuthService} from '@eg/core/auth.service'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; import {StringComponent} from '@eg/share/string/string.component'; @@ -73,12 +74,14 @@ export class AdminPageComponent implements OnInit { contextOrg: IdlObject; orgFieldLabel: string; viewPerms: string; + canCreate: boolean; constructor( private idl: IdlService, private org: OrgService, private auth: AuthService, private pcrud: PcrudService, + private perm: PermService, private toast: ToastService ) {} @@ -124,6 +127,7 @@ export class AdminPageComponent implements OnInit { this.viewPerms = pc.retrieve.perms; } + this.checkCreatePerms(); this.applyOrgValues(); // If the caller provides not data source, create a generic one. @@ -169,6 +173,21 @@ export class AdminPageComponent implements OnInit { }; } + checkCreatePerms() { + this.canCreate = false; + const pc = this.idlClassDef.permacrud || {}; + const perms = pc.create ? pc.create.perms : []; + if (perms.length === 0) { return; } + + this.perm.hasWorkPermAt(perms, true).then(permMap => { + Object.keys(permMap).forEach(key => { + if (permMap[key].length > 0) { + this.canCreate = true; + } + }); + }); + } + orgOnChange(org: IdlObject) { this.contextOrg = org; this.grid.reload(); -- 2.11.0