From 787d625852dda54bdca2fecc0ed9012a19d18f68 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Wed, 24 Jun 2020 12:32:01 +0200 Subject: [PATCH] mgr/dashboard: Host delete action should be disabled if not managed by Orchestrator Fixes: https://tracker.ceph.com/issues/46146 Signed-off-by: Volker Theile (cherry picked from commit 4fbe49a793f1bd09a823620414f36a3bbfc426a0) --- .../cluster/hosts/hosts.component.spec.ts | 42 ++++++++++++++++++- .../app/ceph/cluster/hosts/hosts.component.ts | 22 +++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts index 05f3d962f0e4..695898c25ae5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts @@ -112,7 +112,7 @@ describe('HostsComponent', () => { }); expect(tableAction.disable(component.selection)).toBeTruthy(); expect(component.getEditDisableDesc(component.selection)).toBe( - 'Host editing is disabled because the host is not managed by Orchestrator.' + 'Host editing is disabled because the selected host is not managed by Orchestrator.' ); }); @@ -132,4 +132,44 @@ describe('HostsComponent', () => { expect(component.getEditDisableDesc(component.selection)).toBeUndefined(); }); }); + + describe('getDeleteDisableDesc', () => { + it('should return message (not managed by Orchestrator)', () => { + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + component.selection.add({ + sources: { + ceph: true, + orchestrator: false + } + }); + expect(component.getDeleteDisableDesc(component.selection)).toBe( + 'Host deletion is disabled because a selected host is not managed by Orchestrator.' + ); + }); + + it('should return undefined (no selection)', () => { + expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined(); + }); + + it('should return undefined (managed by Orchestrator)', () => { + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined(); + }); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts index 41594c1f55e7..52414bdf3ef0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts @@ -107,7 +107,10 @@ export class HostsComponent extends ListWithDetails implements OnInit { () => this.deleteAction() ); }, - disable: () => !this.selection.hasSelection + disable: (selection: CdTableSelection) => + !selection.hasSelection || + !selection.selected.every((selected) => selected.sources.orchestrator), + disableDesc: this.getDeleteDisableDesc.bind(this) } ]; } @@ -191,7 +194,9 @@ export class HostsComponent extends ListWithDetails implements OnInit { getEditDisableDesc(selection: CdTableSelection): string | undefined { if (selection && selection.hasSingleSelection && !selection.first().sources.orchestrator) { - return this.i18n('Host editing is disabled because the host is not managed by Orchestrator.'); + return this.i18n( + 'Host editing is disabled because the selected host is not managed by Orchestrator.' + ); } return undefined; } @@ -212,6 +217,19 @@ export class HostsComponent extends ListWithDetails implements OnInit { }); } + getDeleteDisableDesc(selection: CdTableSelection): string | undefined { + if ( + selection && + selection.hasSelection && + !selection.selected.every((selected) => selected.sources.orchestrator) + ) { + return this.i18n( + 'Host deletion is disabled because a selected host is not managed by Orchestrator.' + ); + } + return undefined; + } + getHosts(context: CdTableFetchDataContext) { if (this.isLoadingHosts) { return; -- 2.47.3