Skip to content

Commit f43edd5

Browse files
authored
Merge pull request ceph#66332 from rhcs-dashboard/73854-CephFS-Authorize-modal-Update-issues
mgr/dashboard : fix - CephFS Authorize Modal Update issue Reviewed-by: Dnyaneshwari Talwekar [email protected]
2 parents 252ecc7 + f73f3be commit f43edd5

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-auth-modal/cephfs-auth-modal.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
<cds-checkbox i18n-label
109109
[id]="permission.name"
110110
[name]="permission.name"
111-
[formControlName]="permission.name">
111+
[formControlName]="permission.name"
112+
(checkedChange)="toggleFormControl($event, permission.name)">
112113
{{ permission.name | titlecase }}
113114
<cd-help-text *ngIf="permission.description">
114115
{{ permission.description }}

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-auth-modal/cephfs-auth-modal.component.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
1818
import { FinishedTask } from '~/app/shared/models/finished-task';
1919
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
2020
import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
21+
import { PERMISSION_NAMES } from '~/app/shared/models/cephfs.model';
2122

2223
const DEBOUNCE_TIMER = 300;
2324

@@ -35,26 +36,27 @@ export class CephfsAuthModalComponent extends CdForm implements OnInit, AfterVie
3536
action: string;
3637
resource: string;
3738
icons = Icons;
39+
readonly defaultdir: string = '/';
3840

3941
clientPermissions = [
4042
{
41-
name: 'read',
43+
name: PERMISSION_NAMES.READ,
4244
description: $localize`Read permission is the minimum givable access`
4345
},
4446
{
45-
name: 'write',
47+
name: PERMISSION_NAMES.WRITE,
4648
description: $localize`Permission to set layouts or quotas, write access needed`
4749
},
4850
{
49-
name: 'quota',
51+
name: PERMISSION_NAMES.QUOTA,
5052
description: $localize`Permission to set layouts or quotas, write access needed`
5153
},
5254
{
53-
name: 'snapshot',
55+
name: PERMISSION_NAMES.SNAPSHOT,
5456
description: $localize`Permission to create or delete snapshots, write access needed`
5557
},
5658
{
57-
name: 'rootSquash',
59+
name: PERMISSION_NAMES.ROOTSQUASH,
5860
description: $localize`Safety measure to prevent scenarios such as accidental sudo rm -rf /path`
5961
}
6062
];
@@ -83,11 +85,6 @@ export class CephfsAuthModalComponent extends CdForm implements OnInit, AfterVie
8385
this.directoryStore.loadDirectories(this.id, '/', 3);
8486
this.createForm();
8587
this.loadingReady();
86-
if (this.directoryStore?.isLoading) {
87-
this.form.get('directory').disable();
88-
} else {
89-
this.form.get('directory').disable();
90-
}
9188
}
9289

9390
createForm() {
@@ -98,10 +95,13 @@ export class CephfsAuthModalComponent extends CdForm implements OnInit, AfterVie
9895
validators: [Validators.required]
9996
}
10097
),
101-
directory: new FormControl(undefined, {
102-
updateOn: 'blur',
103-
validators: [Validators.required]
104-
}),
98+
directory: new FormControl(
99+
{ value: this.defaultdir, disabled: false },
100+
{
101+
updateOn: 'blur',
102+
validators: [Validators.required]
103+
}
104+
),
105105
userId: new FormControl(undefined, {
106106
validators: [Validators.required]
107107
}),
@@ -134,7 +134,7 @@ export class CephfsAuthModalComponent extends CdForm implements OnInit, AfterVie
134134
onSubmit() {
135135
const clientId: number = this.form.getValue('userId');
136136
const caps: string[] = [this.form.getValue('directory'), this.transformPermissions()];
137-
const rootSquash: boolean = this.form.getValue('rootSquash');
137+
const rootSquash: boolean = this.form.getValue(PERMISSION_NAMES.ROOTSQUASH);
138138
this.taskWrapper
139139
.wrapTaskAroundCall({
140140
task: new FinishedTask('cephfs/auth', {
@@ -151,16 +151,23 @@ export class CephfsAuthModalComponent extends CdForm implements OnInit, AfterVie
151151
}
152152

153153
transformPermissions(): string {
154-
const write = this.form.getValue('write');
155-
const snapshot = this.form.getValue('snapshot');
156-
const quota = this.form.getValue('quota');
154+
const write = this.form.getValue(PERMISSION_NAMES.WRITE);
155+
const snapshot = this.form.getValue(PERMISSION_NAMES.SNAPSHOT);
156+
const quota = this.form.getValue(PERMISSION_NAMES.QUOTA);
157157
return `r${write ? 'w' : ''}${quota ? 'p' : ''}${snapshot ? 's' : ''}`;
158158
}
159159

160-
toggleFormControl() {
161-
const snapshot = this.form.get('snapshot');
162-
const quota = this.form.get('quota');
163-
snapshot.disabled ? snapshot.enable() : snapshot.disable();
164-
quota.disabled ? quota.enable() : quota.disable();
160+
toggleFormControl(_event?: boolean, permisson?: string) {
161+
const snapshot = this.form.get(PERMISSION_NAMES.SNAPSHOT);
162+
const quota = this.form.get(PERMISSION_NAMES.QUOTA);
163+
if (_event && permisson == PERMISSION_NAMES.WRITE) {
164+
snapshot.disabled ? snapshot.enable() : snapshot.disable();
165+
quota.disabled ? quota.enable() : quota.disable();
166+
} else if (!_event && permisson == PERMISSION_NAMES.WRITE) {
167+
snapshot.setValue(false);
168+
quota.setValue(false);
169+
snapshot.disable();
170+
quota.disable();
171+
}
165172
}
166173
}

src/pybind/mgr/dashboard/frontend/src/app/shared/models/cephfs.model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ export interface MountData {
33
fsName: string;
44
path: string;
55
}
6+
7+
export const PERMISSION_NAMES = {
8+
READ: 'read',
9+
WRITE: 'write',
10+
SNAPSHOT: 'snapshot',
11+
QUOTA: 'quota',
12+
ROOTSQUASH: 'rootSquash'
13+
} as const;

0 commit comments

Comments
 (0)