From d678d8076c2a4c5edfe489d553e3c8770462f023 Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Wed, 4 Nov 2020 11:00:21 +0800 Subject: [PATCH] mgr/dashboard: disable cluster selection in NFS export editing form We should not allow changing an export's cluster because an export ID might live in one cluster but not in another one. Editing a non-existing export in a cluster causes an error. Fixes: https://tracker.ceph.com/issues/47373 Signed-off-by: Kiefer Chang --- .../nfs/nfs-form/nfs-form.component.spec.ts | 22 +++++++------------ .../ceph/nfs/nfs-form/nfs-form.component.ts | 1 + 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts index f17ee20a3de..66b8af29b01 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts @@ -6,13 +6,10 @@ import { RouterTestingModule } from '@angular/router/testing'; import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap'; import { ToastrModule } from 'ngx-toastr'; -import { of } from 'rxjs'; import { ActivatedRouteStub } from '../../../../testing/activated-route-stub'; import { configureTestBed } from '../../../../testing/unit-test-helper'; import { LoadingPanelComponent } from '../../../shared/components/loading-panel/loading-panel.component'; -import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe'; -import { SummaryService } from '../../../shared/services/summary.service'; import { SharedModule } from '../../../shared/shared.module'; import { NfsFormClientComponent } from '../nfs-form-client/nfs-form-client.component'; import { NfsFormComponent } from './nfs-form.component'; @@ -38,23 +35,13 @@ describe('NfsFormComponent', () => { { provide: ActivatedRoute, useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined }) - }, - SummaryService, - CephReleaseNamePipe + } ] }, [LoadingPanelComponent] ); beforeEach(() => { - const summaryService = TestBed.inject(SummaryService); - spyOn(summaryService, 'refresh').and.callFake(() => true); - spyOn(summaryService, 'subscribeOnce').and.callFake(() => - of({ - version: 'master' - }) - ); - fixture = TestBed.createComponent(NfsFormComponent); component = fixture.componentInstance; httpTesting = TestBed.inject(HttpTestingController); @@ -119,6 +106,7 @@ describe('NfsFormComponent', () => { transportTCP: true, transportUDP: true }); + expect(component.nfsForm.get('cluster_id').disabled).toBeFalsy(); }); it('should prepare data when selecting an cluster', () => { @@ -142,6 +130,12 @@ describe('NfsFormComponent', () => { expect(component.nfsForm.getValue('daemons')).toEqual([]); }); + it('should not allow changing cluster in edit mode', () => { + component.isEdit = true; + component.ngOnInit(); + expect(component.nfsForm.get('cluster_id').disabled).toBeTruthy(); + }); + describe('should submit request', () => { beforeEach(() => { component.nfsForm.patchValue({ diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts index 52568696f91..d51ef427149 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.ts @@ -118,6 +118,7 @@ export class NfsFormComponent extends CdForm implements OnInit { this.getData(promises); }); + this.nfsForm.get('cluster_id').disable(); } else { this.action = this.actionLabels.CREATE; this.getData(promises); -- 2.39.5