From 8ba75cf6ba0b7556da23fb393adf59bdfb3651be Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 16 Mar 2020 10:34:05 +0000 Subject: [PATCH] Warn users trying to use a personalised template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since contact lists only store the email address or phone number, this won’t work. So we should warn people, and highlight that the personalisation in the template is the problem, since this is what they will need to change. --- app/main/views/send.py | 2 +- app/templates/views/send-contact-list.html | 32 +++++++++++++++++----- tests/app/main/views/test_send.py | 28 +++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index 065862ce2..72d0166ee 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -510,7 +510,7 @@ def choose_from_contact_list(service_id, template_id): current_service.id, template_type=template.template_type, ), - template=current_service.get_template(template_id), + template=template, ) diff --git a/app/templates/views/send-contact-list.html b/app/templates/views/send-contact-list.html index 1827485a0..e5634d927 100644 --- a/app/templates/views/send-contact-list.html +++ b/app/templates/views/send-contact-list.html @@ -1,5 +1,6 @@ {% extends "withnav_template.html" %} {% from "components/big-number.html" import big_number -%} +{% from "components/list.html" import list_of_placeholders %} {% from "components/message-count-label.html" import recipient_count_label %} {% from "components/page-header.html" import page_header %} {% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading %} @@ -15,7 +16,20 @@ back_link=url_for('.send_one_off', service_id=current_service.id, template_id=template.id) ) }} - {% if contact_lists %} + {% if template.placeholders %} +
+
+

+ You cannot use a saved contact list with this template because it + is personalised with {{ list_of_placeholders(template.placeholders) }}. +

+

+ Saved contact lists can only store email addresses or phone + numbers. +

+
+
+ {% elif contact_lists %}
{% call(item, row_number) list_table( contact_lists, @@ -51,12 +65,16 @@ {% endcall %}
{% else %} -

- You have not saved any lists of {{ recipient_count_label(99, template.template_type) }} yet. -

-

- To upload and save a new contact list, go to the uploads page. -

+
+
+

+ You have not saved any lists of {{ recipient_count_label(99, template.template_type) }} yet. +

+

+ To upload and save a new contact list, go to the uploads page. +

+
+
{% endif %} {% endblock %} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index c7112599b..c96ae090d 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -3928,6 +3928,34 @@ def test_choose_from_contact_list( ) +def test_choose_from_contact_list_with_personalised_template( + mocker, + client_request, + mock_get_contact_lists, + fake_uuid, +): + template = create_template( + content="Hey ((name)) ((thing)) is happening" + ) + mocker.patch( + 'app.service_api_client.get_service_template', + return_value={'data': template}, + ) + page = client_request.get( + 'main.choose_from_contact_list', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + ) + assert [ + normalize_spaces(p.text) for p in page.select('main p') + ] == [ + 'You cannot use a saved contact list with this template because ' + 'it is personalised with ((name)) and ((thing)).', + 'Saved contact lists can only store email addresses or phone numbers.', + ] + assert not page.select('table') + + def test_choose_from_contact_list_with_no_lists( mocker, client_request,