diff --git a/app/main/forms.py b/app/main/forms.py index eeb90fe0f..5b0f74f4d 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -47,6 +47,7 @@ from app.main.validators import ( MustContainAlphanumericCharacters, NoCommasInPlaceHolders, NoEmbeddedImagesInSVG, + NoPlaceholders, OnlySMSCharacters, ValidEmail, ValidGovEmail, @@ -1217,6 +1218,7 @@ class SMSTemplateForm(BaseTemplateForm): class BroadcastTemplateForm(SMSTemplateForm): def validate_template_content(self, field): OnlySMSCharacters(template_type='broadcast')(None, field) + NoPlaceholders()(None, field) class LetterAddressForm(StripWhitespaceForm): diff --git a/app/main/validators.py b/app/main/validators.py index 9434c39c4..104b4a932 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -108,6 +108,18 @@ class OnlySMSCharacters: ) +class NoPlaceholders: + + def __init__(self, message=None): + self.message = message or ( + 'You can’t use ((double brackets)) to personalise this message' + ) + + def __call__(self, form, field): + if Field(field.data).placeholders: + raise ValidationError(self.message) + + class LettersNumbersFullStopsAndUnderscoresOnly: regex = re.compile(r'^[a-zA-Z0-9\s\._]+$') diff --git a/app/templates/views/edit-broadcast-template.html b/app/templates/views/edit-broadcast-template.html index cb753d478..8c5d7cfe9 100644 --- a/app/templates/views/edit-broadcast-template.html +++ b/app/templates/views/edit-broadcast-template.html @@ -24,7 +24,7 @@ }) }}
- {{ textbox(form.template_content, highlight_placeholders=True, width='1-1', rows=5) }} + {{ textbox(form.template_content, highlight_placeholders=False, width='1-1', rows=5) }} {{ sticky_page_footer('Save') }}
diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index a69c1a58e..cbf30a6cf 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -399,6 +399,21 @@ def test_should_show_page_for_one_template( mock_get_service_template.assert_called_with(SERVICE_ONE_ID, template_id, None) +def test_broadcast_template_doesnt_highlight_placeholders( + client_request, + service_one, + mock_get_broadcast_template, + fake_uuid, +): + service_one['permissions'] += ['broadcast'] + page = client_request.get( + '.edit_service_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + ) + assert page.select_one('textarea')['data-highlight-placeholders'] == 'false' + + def test_caseworker_redirected_to_one_off( client_request, mock_get_service_templates, @@ -2389,3 +2404,40 @@ def test_set_template_sender_escapes_letter_contact_block_names( radio_text = page.select_one('.govuk-grid-column-three-quarters label[for="sender-1"]').decode_contents() assert "<script>" in radio_text assert "