From 32e3c273a8857f95d737c3a5af26051bf74275fa 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 (cherry picked from commit d678d8076c2a4c5edfe489d553e3c8770462f023) Conflicts: src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts - Unnecessary spies for SummaryService are removed in the master. - The LoadingPanelComponent is new in the master. --- .../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 7e271d6d4e9..2b9a07d8108 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,12 +6,9 @@ import { RouterTestingModule } from '@angular/router/testing'; import { TypeaheadModule } from 'ngx-bootstrap/typeahead'; import { ToastrModule } from 'ngx-toastr'; -import { of } from 'rxjs'; import { ActivatedRouteStub } from '../../../../testing/activated-route-stub'; import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; -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'; @@ -37,21 +34,11 @@ describe('NfsFormComponent', () => { provide: ActivatedRoute, useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined }) }, - i18nProviders, - SummaryService, - CephReleaseNamePipe + i18nProviders ] }); beforeEach(() => { - const summaryService = TestBed.get(SummaryService); - spyOn(summaryService, 'refresh').and.callFake(() => true); - spyOn(summaryService, 'subscribeOnce').and.callFake(() => - of({ - version: 'master' - }) - ); - fixture = TestBed.createComponent(NfsFormComponent); component = fixture.componentInstance; httpTesting = TestBed.get(HttpTestingController); @@ -116,6 +103,7 @@ describe('NfsFormComponent', () => { transportTCP: true, transportUDP: true }); + expect(component.nfsForm.get('cluster_id').disabled).toBeFalsy(); }); it('should prepare data when selecting an cluster', () => { @@ -139,6 +127,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 a85a32fc6f6..f1a0394698a 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 @@ -113,6 +113,7 @@ export class NfsFormComponent implements OnInit { this.getData(promises); }); + this.nfsForm.get('cluster_id').disable(); } else { this.action = this.actionLabels.CREATE; this.getData(promises); -- 2.47.3