From 9ccff23877ec8d740fcd5a9254fcd2424b62d2c8 Mon Sep 17 00:00:00 2001 From: Lucas Declercq Date: Wed, 10 Oct 2018 08:57:00 +0200 Subject: Add explicit error message that changing video ownership only works with local accounts (#1214) * Add explicit error message that changing video ownership only works with local accounts * Remove superfluous logger * Remove unneeded end() to error responses * Add a message on client side to prevent transfering ownership to a remote account --- .../video-change-ownership-validators.service.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts b/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts index 087b80b44..c6fbb7538 100644 --- a/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-change-ownership-validators.service.ts @@ -1,5 +1,5 @@ import { I18n } from '@ngx-translate/i18n-polyfill' -import { Validators } from '@angular/forms' +import { AbstractControl, ValidationErrors, Validators } from '@angular/forms' import { Injectable } from '@angular/core' import { BuildFormValidator } from '@app/shared' @@ -9,10 +9,19 @@ export class VideoChangeOwnershipValidatorsService { constructor (private i18n: I18n) { this.USERNAME = { - VALIDATORS: [ Validators.required ], + VALIDATORS: [ Validators.required, this.localAccountValidator ], MESSAGES: { - 'required': this.i18n('The username is required.') + 'required': this.i18n('The username is required.'), + 'localAccountOnly': this.i18n('You can only transfer ownership to a local account') } } } + + localAccountValidator (control: AbstractControl): ValidationErrors { + if (control.value.includes('@')) { + return { 'localAccountOnly': true } + } + + return null + } } -- cgit v1.2.3