Don’t validate phone numbers when sending emails

If you have a placeholder called `((phone number))` in your email
template, and you try to send a one-off message then the form input will
attempt to validate your ‘phone number’.

This is not helpful if you’re trying to put a landline number in your
email, for example.

This only affects messages being sent through the one-off interface.

This commit makes the form be aware of template type, which fixes the
problem.
This commit is contained in:
Chris Hill-Scott
2018-03-16 14:17:43 +00:00
parent b2c199e609
commit 5a2fafb66b
3 changed files with 34 additions and 18 deletions

View File

@@ -873,13 +873,20 @@ class SMSPrefixForm(StripWhitespaceForm):
def get_placeholder_form_instance(
placeholder_name,
dict_to_populate_from,
template_type,
optional_placeholder=False,
allow_international_phone_numbers=False,
):
if Columns.make_key(placeholder_name) == 'emailaddress':
if (
Columns.make_key(placeholder_name) == 'emailaddress' and
template_type == 'email'
):
field = email_address(label=placeholder_name, gov_user=False)
elif Columns.make_key(placeholder_name) == 'phonenumber':
elif (
Columns.make_key(placeholder_name) == 'phonenumber' and
template_type == 'sms'
):
if allow_international_phone_numbers:
field = international_phone_number(label=placeholder_name)
else:

View File

@@ -379,6 +379,7 @@ def send_test_step(service_id, template_id, step_index):
form = get_placeholder_form_instance(
current_placeholder,
dict_to_populate_from=get_normalised_placeholders_from_session(),
template_type=template.template_type,
optional_placeholder=optional_placeholder,
allow_international_phone_numbers='international_sms' in current_service['permissions'],
)