]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Host delete action should be disabled if not managed by Orchestrator 35745/head
authorVolker Theile <vtheile@suse.com>
Wed, 24 Jun 2020 10:32:01 +0000 (12:32 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 25 Jun 2020 11:15:29 +0000 (13:15 +0200)
Fixes: https://tracker.ceph.com/issues/46146
Signed-off-by: Volker Theile <vtheile@suse.com>
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 591b0f189fd5cae01a1b02400410b4990084e27c..b4ba5643fb8089ebe0a6ddebf1eca88c6e412f2b 100644 (file)
@@ -98,7 +98,7 @@ describe('HostsComponent', () => {
         }
       });
       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.'
       );
     });
 
@@ -116,4 +116,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;