@@ -18,6 +18,7 @@ import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
1818import { FinishedTask } from '~/app/shared/models/finished-task' ;
1919import { ModalCdsService } from '~/app/shared/services/modal-cds.service' ;
2020import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service' ;
21+ import { PERMISSION_NAMES } from '~/app/shared/models/cephfs.model' ;
2122
2223const 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}
0 commit comments