]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Host delete action should be disabled if not managed by Orchestrator 36874/head
authorVolker Theile <vtheile@suse.com>
Wed, 24 Jun 2020 10:32:01 +0000 (12:32 +0200)
committerLaura Paduano <lpaduano@suse.com>
Fri, 28 Aug 2020 10:29:56 +0000 (12:29 +0200)
Fixes: https://tracker.ceph.com/issues/46146
Signed-off-by: Volker Theile <vtheile@suse.com>
(cherry picked from commit 4fbe49a793f1bd09a823620414f36a3bbfc426a0)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts

index 05f3d962f0e4047ac3b71af59f9d42d50f0c3c62..695898c25ae50e1e567e8d30f79f2914973e4e79 100644 (file)
@@ -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();
+    });
+  });
 });
index 41594c1f55e7924504adb5cd137c36e031cafd19..52414bdf3ef0ceed7ce0a709cf5d8ed4ca578116 100644 (file)
@@ -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;