From 1f30a1853e38c20a45722dbd6d38aaaec63839e8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Feb 2018 15:29:32 +0100 Subject: Add confirm when admin use custom js/css --- .../edit-custom-config.component.ts | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'client/src/app/+admin/config/edit-custom-config') 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 027268536..ccec89a8e 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 @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core' import { FormBuilder, FormGroup } from '@angular/forms' import { Router } from '@angular/router' import { ConfigService } from '@app/+admin/config/shared/config.service' +import { ConfirmService } from '@app/core' import { ServerService } from '@app/core/server/server.service' import { FormReactive, USER_VIDEO_QUOTA } from '@app/shared' import { @@ -61,12 +62,16 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { userVideoQuota: USER_VIDEO_QUOTA.MESSAGES } + private oldCustomJavascript: string + private oldCustomCSS: string + constructor ( private formBuilder: FormBuilder, private router: Router, private notificationsService: NotificationsService, private configService: ConfigService, - private serverService: ServerService + private serverService: ServerService, + private confirmService: ConfirmService ) { super() } @@ -109,6 +114,9 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { res => { this.customConfig = res + this.oldCustomCSS = this.customConfig.instance.customizations.css + this.oldCustomJavascript = this.customConfig.instance.customizations.javascript + this.updateForm() }, @@ -124,7 +132,27 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { return this.form.value['signupEnabled'] === true } - formValidated () { + async formValidated () { + const newCustomizationJavascript = this.form.value['customizationJavascript'] + const newCustomizationCSS = this.form.value['customizationCSS'] + + const customizations = [] + if (newCustomizationJavascript && newCustomizationJavascript !== this.oldCustomJavascript) customizations.push('JavaScript') + if (newCustomizationCSS && newCustomizationCSS !== this.oldCustomCSS) customizations.push('CSS') + + if (customizations.length !== 0) { + const customizationsText = customizations.join('/') + + const message = `You set custom ${customizationsText}. ` + + 'This could lead to security issues or bugs if you do not understand it. ' + + 'Are you sure you want to update the configuration?' + const label = `Please type "I understand the ${customizationsText} I set" to confirm.` + const expectedInputValue = `I understand the ${customizationsText} I set` + + const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue) + if (confirmRes === false) return + } + const data = { instance: { name: this.form.value['instanceName'], -- cgit v1.2.3