error when users put non-GSM chars in a sms template

additionally, this moves the formatted_list jinja macro into a python
function, so that it can be called from the form validator
This commit is contained in:
Leo Hemsted
2017-02-13 13:11:29 +00:00
parent cb54db82b4
commit 41fa158635
6 changed files with 51 additions and 52 deletions

View File

@@ -1,13 +1,15 @@
from wtforms import ValidationError
from notifications_utils.template import Template
from notifications_utils.gsm import get_non_gsm_characters
from app.main._blacklisted_passwords import blacklisted_passwords
from app.utils import (
Spreadsheet,
is_gov_user
)
from ._blacklisted_passwords import blacklisted_passwords
class Blacklist(object):
class Blacklist:
def __init__(self, message=None):
if not message:
message = 'Password is blacklisted.'
@@ -18,7 +20,7 @@ class Blacklist(object):
raise ValidationError(self.message)
class CsvFileValidator(object):
class CsvFileValidator:
def __init__(self, message='Not a csv file'):
self.message = message
@@ -28,7 +30,7 @@ class CsvFileValidator(object):
raise ValidationError("{} isnt a spreadsheet that Notify can read".format(field.data.filename))
class ValidGovEmail(object):
class ValidGovEmail:
def __call__(self, form, field):
from flask import url_for
@@ -40,7 +42,7 @@ class ValidGovEmail(object):
raise ValidationError(message)
class NoCommasInPlaceHolders():
class NoCommasInPlaceHolders:
def __init__(self, message='You cant have commas in your fields'):
self.message = message
@@ -48,3 +50,12 @@ class NoCommasInPlaceHolders():
def __call__(self, form, field):
if ',' in ''.join(Template({'content': field.data}).placeholders):
raise ValidationError(self.message)
class OnlyGSMCharacters:
def __call__(self, form, field):
non_gsm_characters = get_non_gsm_characters(field.data)
if non_gsm_characters:
raise ValidationError('The following characters are not allowed in text messages: {}'.format(
', '.join(non_gsm_characters)
))