mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
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:
@@ -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("{} isn’t 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 can’t 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)
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user