X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fconfig%2Fedit-custom-config%2Fedit-custom-config.component.ts;h=f2a3464cb83ad991c8121e68ed53388bbdf85eed;hb=d18d64787b3ea174f7dc2740c8c8c9555625047e;hp=3f92054603c5fdcfcac6a43c88d5e1272118eeb1;hpb=b1d40cff89f7cff565a98cdbcea9a624196a169a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 3f9205460..f2a3464cb 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -17,6 +17,7 @@ import { import { NotificationsService } from 'angular2-notifications' import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' import { I18n } from '@ngx-translate/i18n-polyfill' +import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-edit-custom-config', @@ -44,38 +45,11 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { { value: 8, label: '8' } ] - form: FormGroup - formErrors = { - instanceName: '', - instanceShortDescription: '', - instanceDescription: '', - instanceTerms: '', - instanceDefaultClientRoute: '', - instanceDefaultNSFWPolicy: '', - servicesTwitterUsername: '', - cachePreviewsSize: '', - signupLimit: '', - adminEmail: '', - userVideoQuota: '', - transcodingThreads: '', - customizationJavascript: '', - customizationCSS: '' - } - validationMessages = { - instanceShortDescription: INSTANCE_SHORT_DESCRIPTION.MESSAGES, - instanceName: INSTANCE_NAME.MESSAGES, - servicesTwitterUsername: SERVICES_TWITTER_USERNAME, - cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES, - signupLimit: SIGNUP_LIMIT.MESSAGES, - adminEmail: ADMIN_EMAIL.MESSAGES, - userVideoQuota: USER_VIDEO_QUOTA.MESSAGES - } - private oldCustomJavascript: string private oldCustomCSS: string constructor ( - private formBuilder: FormBuilder, + protected formValidatorService: FormValidatorService, private router: Router, private notificationsService: NotificationsService, private configService: ConfigService, @@ -90,39 +64,35 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { return 'transcodingResolution' + resolution } - buildForm () { + ngOnInit () { const formGroupData = { - instanceName: [ '', INSTANCE_NAME.VALIDATORS ], - instanceShortDescription: [ '', INSTANCE_SHORT_DESCRIPTION.VALIDATORS ], - instanceDescription: [ '' ], - instanceTerms: [ '' ], - instanceDefaultClientRoute: [ '' ], - instanceDefaultNSFWPolicy: [ '' ], - servicesTwitterUsername: [ '', SERVICES_TWITTER_USERNAME.VALIDATORS ], - servicesTwitterWhitelisted: [ ], - cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], - signupEnabled: [ ], - signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], - adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ], - userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ], - transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ], - transcodingEnabled: [ ], - customizationJavascript: [ '' ], - customizationCSS: [ '' ] + instanceName: INSTANCE_NAME, + instanceShortDescription: INSTANCE_SHORT_DESCRIPTION, + instanceDescription: null, + instanceTerms: null, + instanceDefaultClientRoute: null, + instanceDefaultNSFWPolicy: null, + servicesTwitterUsername: SERVICES_TWITTER_USERNAME, + servicesTwitterWhitelisted: null, + cachePreviewsSize: CACHE_PREVIEWS_SIZE, + signupEnabled: null, + signupLimit: SIGNUP_LIMIT, + adminEmail: ADMIN_EMAIL, + userVideoQuota: USER_VIDEO_QUOTA, + transcodingThreads: TRANSCODING_THREADS, + transcodingEnabled: null, + customizationJavascript: null, + customizationCSS: null } + const defaultValues: BuildFormDefaultValues = {} for (const resolution of this.resolutions) { const key = this.getResolutionKey(resolution) - formGroupData[key] = [ false ] + defaultValues[key] = 'false' + formGroupData[key] = null } - this.form = this.formBuilder.group(formGroupData) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() + this.buildForm(formGroupData) this.configService.getCustomConfig() .subscribe( @@ -161,14 +131,14 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { const customizationsText = customizations.join('/') // FIXME: i18n service does not support string concatenation - const message = this.i18n('You set custom {{ customizationsText }}. ', { customizationsText }) + + const message = this.i18n('You set custom {{customizationsText}}. ', { customizationsText }) + this.i18n('This could lead to security issues or bugs if you do not understand it. ') + this.i18n('Are you sure you want to update the configuration?') const label = this.i18n( - 'Please type "I understand the {{ customizationsText }} I set" to confirm.', + 'Please type "I understand the {{customizationsText}} I set" to confirm.', { customizationsText } ) - const expectedInputValue = this.i18n('I understand the {{ customizationsText }} I set', { customizationsText}) + const expectedInputValue = this.i18n('I understand the {{customizationsText}} I set', { customizationsText }) const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue) if (confirmRes === false) return