Update the service name validation in the ServiceNameForm and AddServiceForm to check the email_safe version

of the name against a list of all service email_from fields.
Update find_all_service_names to find_all_service_email_from, which returns the email_from of all services.
This commit is contained in:
Rebecca Law
2016-03-31 15:17:05 +01:00
parent 1871243cc8
commit 9a2cb60f5e
9 changed files with 53 additions and 31 deletions

View File

@@ -1,13 +1,14 @@
import re
from flask_wtf import Form
from utils.recipients import (
validate_phone_number,
InvalidPhoneError
)
from wtforms import (
StringField,
PasswordField,
ValidationError,
TextAreaField,
FileField,
RadioField,
BooleanField,
HiddenField
)
@@ -16,12 +17,6 @@ from wtforms.validators import (DataRequired, Email, Length, Regexp)
from app.main.validators import (Blacklist, CsvFileValidator, ValidEmailDomainRegex)
from utils.recipients import (
validate_phone_number,
format_phone_number,
InvalidPhoneError
)
def email_address(label='Email address'):
return EmailField(label, validators=[
@@ -159,7 +154,9 @@ class AddServiceForm(Form):
)
def validate_name(self, a):
if a.data.lower() in self._names_func():
from app.utils import email_safe
# make sure the email_from will be unique to all services
if email_safe(a.data) in self._names_func():
raise ValidationError('This service name is already in use')
@@ -180,7 +177,9 @@ class ServiceNameForm(Form):
])
def validate_name(self, a):
if a.data.lower() in self._names_func():
from app.utils import email_safe
# make sure the email_from will be unique to all services
if email_safe(a.data) in self._names_func():
raise ValidationError('This service name is already in use')