mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
ensure emails still accept emoji
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask_wtf import Form
|
from flask_wtf import Form
|
||||||
@@ -251,7 +253,7 @@ class ConfirmPasswordForm(Form):
|
|||||||
raise ValidationError('Invalid password')
|
raise ValidationError('Invalid password')
|
||||||
|
|
||||||
|
|
||||||
class SMSTemplateForm(Form):
|
class BaseTemplateForm(Form):
|
||||||
name = StringField(
|
name = StringField(
|
||||||
u'Template name',
|
u'Template name',
|
||||||
validators=[DataRequired(message="Can’t be empty")])
|
validators=[DataRequired(message="Can’t be empty")])
|
||||||
@@ -260,8 +262,7 @@ class SMSTemplateForm(Form):
|
|||||||
u'Message',
|
u'Message',
|
||||||
validators=[
|
validators=[
|
||||||
DataRequired(message="Can’t be empty"),
|
DataRequired(message="Can’t be empty"),
|
||||||
NoCommasInPlaceHolders(),
|
NoCommasInPlaceHolders()
|
||||||
OnlyGSMCharacters()
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
process_type = RadioField(
|
process_type = RadioField(
|
||||||
@@ -275,7 +276,12 @@ class SMSTemplateForm(Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmailTemplateForm(SMSTemplateForm):
|
class SMSTemplateForm(BaseTemplateForm):
|
||||||
|
def validate_template_content(self, field):
|
||||||
|
OnlyGSMCharacters()(None, field)
|
||||||
|
|
||||||
|
|
||||||
|
class EmailTemplateForm(BaseTemplateForm):
|
||||||
subject = TextAreaField(
|
subject = TextAreaField(
|
||||||
u'Subject',
|
u'Subject',
|
||||||
validators=[DataRequired(message="Can’t be empty")])
|
validators=[DataRequired(message="Can’t be empty")])
|
||||||
@@ -480,7 +486,6 @@ class ServiceSmsSender(Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def validate_sms_sender(form, field):
|
def validate_sms_sender(form, field):
|
||||||
import re
|
|
||||||
if field.data and not re.match('^[a-zA-Z0-9\s]+$', field.data):
|
if field.data and not re.match('^[a-zA-Z0-9\s]+$', field.data):
|
||||||
raise ValidationError('Use letters and numbers only')
|
raise ValidationError('Use letters and numbers only')
|
||||||
|
|
||||||
|
|||||||
@@ -163,11 +163,12 @@ def add_service_template(service_id, template_type):
|
|||||||
form.process_type.data
|
form.process_type.data
|
||||||
)
|
)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.status_code == 400:
|
if (
|
||||||
if 'content' in e.message and any(['character count greater than' in x for x in e.message['content']]):
|
e.status_code == 400 and
|
||||||
form.template_content.errors.extend(e.message['content'])
|
'content' in e.message and
|
||||||
else:
|
any(['character count greater than' in x for x in e.message['content']])
|
||||||
raise e
|
):
|
||||||
|
form.template_content.errors.extend(e.message['content'])
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -629,10 +629,31 @@ def test_get_human_readable_delta(from_time, until_time, message):
|
|||||||
assert get_human_readable_delta(from_time, until_time) == message
|
assert get_human_readable_delta(from_time, until_time) == message
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_create_email_template_with_emoji(
|
||||||
|
logged_in_client,
|
||||||
|
service_one,
|
||||||
|
mock_create_service_template
|
||||||
|
):
|
||||||
|
data = {
|
||||||
|
'name': "new name",
|
||||||
|
'subject': "Food incoming!",
|
||||||
|
'template_content': "here's a burrito 🌯",
|
||||||
|
'template_type': 'email',
|
||||||
|
'service': service_one['id'],
|
||||||
|
'process_type': 'normal'
|
||||||
|
}
|
||||||
|
resp = logged_in_client.post(url_for(
|
||||||
|
'.add_service_template',
|
||||||
|
service_id=service_one['id'],
|
||||||
|
template_type='email'
|
||||||
|
), data=data)
|
||||||
|
|
||||||
|
assert resp.status_code == 302
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_create_sms_template_with_emoji(
|
def test_should_not_create_sms_template_with_emoji(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
service_one,
|
service_one,
|
||||||
mock_get_service_template,
|
|
||||||
mock_create_service_template
|
mock_create_service_template
|
||||||
):
|
):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user