1. Squash is not a mandatory field.
2. If the export is created from backend, then squash can have many
different names for each types of squash. for eg.
```
['root', 'root_squash', 'rootsquash', 'rootid', 'root_id_squash', 'rootidsquash', 'all', 'all_squash', 'allsquash', 'all_anomnymous', 'allanonymous', 'no_root_squash', 'none', 'noidsquash']
```
so we need a proper matching in the ui too otherwise the edit field will
not have any value for the squash field.
3. Removed unncessary dropdown helper if there are values for the squash
and access types.
Fixes: https://tracker.ceph.com/issues/57114
Signed-off-by: Nizamudeen A <nia@redhat.com>
(cherry picked from commit
23c00ed480b9e8001790efeb891b9687887ab65d)
@ContentChild('squashHelper', { static: true }) squashHelperTpl: TemplateRef<any>;
- nfsSquash: any[] = this.nfsService.nfsSquash;
+ nfsSquash: any[] = Object.keys(this.nfsService.nfsSquash);
nfsAccessType: any[] = this.nfsService.nfsAccessType;
icons = Icons;
clientsFormArray: FormArray;
<option *ngIf="nfsAccessType !== null && nfsAccessType.length === 0"
value=""
i18n>-- No access type available --</option>
- <option *ngIf="nfsAccessType !== null && nfsAccessType.length > 0"
- value=""
- i18n>-- Select the access type --</option>
<option *ngFor="let accessType of nfsAccessType"
[value]="accessType.value">{{ accessType.value }}</option>
</select>
<div class="form-group row">
<label class="cd-col-form-label"
for="squash">
- <span class="required"
- i18n>Squash</span>
+ <span i18n>Squash</span>
<ng-container *ngTemplateOutlet="squashHelper"></ng-container>
</label>
<div class="cd-col-form-input">
<option *ngIf="nfsSquash !== null && nfsSquash.length === 0"
value=""
i18n>-- No squash available --</option>
- <option *ngIf="nfsSquash !== null && nfsSquash.length > 0"
- value=""
- i18n>--Select what kind of user id squashing is performed --</option>
<option *ngFor="let squash of nfsSquash"
[value]="squash">{{ squash }}</option>
providers: [
{
provide: ActivatedRoute,
- useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
+ useValue: new ActivatedRouteStub({ cluster_id: 'mynfs', export_id: '1' })
}
]
},
[LoadingPanelComponent]
);
+ const matchSquash = (backendSquashValue: string, uiSquashValue: string) => {
+ component.ngOnInit();
+ httpTesting.expectOne('ui-api/nfs-ganesha/fsals').flush(['CEPH', 'RGW']);
+ httpTesting.expectOne('ui-api/nfs-ganesha/cephfs/filesystems').flush([{ id: 1, name: 'a' }]);
+ httpTesting.expectOne('api/nfs-ganesha/cluster').flush(['mynfs']);
+ httpTesting.expectOne('api/nfs-ganesha/export/mynfs/1').flush({
+ fsal: {
+ name: 'RGW'
+ },
+ export_id: 1,
+ transports: ['TCP', 'UDP'],
+ protocols: [4],
+ clients: [],
+ squash: backendSquashValue
+ });
+ httpTesting.verify();
+ expect(component.nfsForm.value).toMatchObject({
+ squash: uiSquashValue
+ });
+ };
+
beforeEach(() => {
fixture = TestBed.createComponent(NfsFormComponent);
component = fixture.componentInstance;
expect(component.nfsForm.get('protocolNfsv4')).toBeTruthy();
});
+ it('should match backend squash values with ui values', () => {
+ component.isEdit = true;
+ matchSquash('none', 'no_root_squash');
+ matchSquash('all', 'all_squash');
+ matchSquash('rootid', 'root_id_squash');
+ matchSquash('root', 'root_squash');
+ });
+
describe('should submit request', () => {
beforeEach(() => {
component.nfsForm.patchValue({
defaultAccessType = { RGW: 'RO' };
nfsAccessType: any[] = this.nfsService.nfsAccessType;
- nfsSquash: any[] = this.nfsService.nfsSquash;
+ nfsSquash: any[] = Object.keys(this.nfsService.nfsSquash);
action: string;
resource: string;
Validators.pattern('^/[^><|&()]*$')
]
}),
- access_type: new FormControl('RW', {
- validators: [Validators.required]
- }),
- squash: new FormControl(this.nfsSquash[0], {
- validators: [Validators.required]
- }),
+ access_type: new FormControl('RW'),
+ squash: new FormControl(this.nfsSquash[0]),
transportUDP: new FormControl(true, {
validators: [
CdValidators.requiredIf({ transportTCP: false }, (value: boolean) => {
res.transportUDP = res.transports.indexOf('UDP') !== -1;
delete res.transports;
+ Object.entries(this.nfsService.nfsSquash).forEach(([key, value]) => {
+ if (value.includes(res.squash)) {
+ res.squash = key;
+ }
+ });
+
res.clients.forEach((client: any) => {
let addressStr = '';
client.addresses.forEach((address: string) => {
}
];
- nfsSquash = ['no_root_squash', 'root_id_squash', 'root_squash', 'all_squash'];
+ nfsSquash = {
+ no_root_squash: ['no_root_squash', 'noidsquash', 'none'],
+ root_id_squash: ['root_id_squash', 'rootidsquash', 'rootid'],
+ root_squash: ['root_squash', 'rootsquash', 'root'],
+ all_squash: ['all_squash', 'allsquash', 'all', 'allanonymous', 'all_anonymous']
+ };
constructor(private http: HttpClient) {
super();