From 34371d030c844b32b8c99ac29b3e6929f22f39ec Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 16 Oct 2017 10:30:59 +0100 Subject: [PATCH] Link to conversation from notification page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you’re using inbound SMS then I reckon it’s useful to be able to naviagate from one message to the context in which that message sits (ie the conversation). This commit adds that link. This is maybe a stopgap until we do something more like chat, where you can reply on the same screen where you see the conversation, but maybe it turns out we don’t want to do that – lets see how this works. --- app/main/views/notifications.py | 2 + .../views/notifications/notification.html | 6 +++ tests/app/main/views/test_notifications.py | 42 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 81f72343c..1ac400eaf 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -82,6 +82,8 @@ def view_notification(service_id, notification_id): created_at=notification['created_at'], help=get_help_argument(), estimated_letter_delivery_date=get_letter_timings(notification['created_at']).earliest_delivery, + notification_id=notification['id'], + can_receive_inbound=('inbound_sms' in current_service['permissions']), ) diff --git a/app/templates/views/notifications/notification.html b/app/templates/views/notifications/notification.html index 90e6ef54a..7c1592cfc 100644 --- a/app/templates/views/notifications/notification.html +++ b/app/templates/views/notifications/notification.html @@ -42,4 +42,10 @@ {{ ajax_block(partials, updates_url, 'status', finished=finished) }} {% endif %} + {% if current_user.has_permissions(['send_texts'], admin_override=True) and template.template_type == 'sms' and can_receive_inbound %} +

+ See all text messages sent to this phone number +

+ {% endif %} + {% endblock %} diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index c3edc957f..0849a3f19 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -161,3 +161,45 @@ def test_should_show_image_of_letter_notification( assert response.get_data(as_text=True) == 'foo' assert isinstance(mocked_preview.call_args[0][0], LetterImageTemplate) assert mocked_preview.call_args[0][1] == 'png' + + +@pytest.mark.parametrize('service_permissions, template_type, link_expected', [ + ([], '', False), + (['inbound_sms'], 'email', False), + (['inbound_sms'], 'letter', False), + (['inbound_sms'], 'sms', True), +]) +def test_notification_page_has_link_to_send_another_for_sms( + client_request, + mocker, + fake_uuid, + service_one, + service_permissions, + template_type, + link_expected, +): + + service_one['permissions'] = service_permissions + mock_get_notification(mocker, fake_uuid, template_type=template_type) + + page = client_request.get( + 'main.view_notification', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + + last_paragraph = page.select('main p')[-1] + + if link_expected: + assert normalize_spaces(last_paragraph.text) == ( + 'See all text messages sent to this phone number' + ) + assert last_paragraph.select_one('a')['href'] == url_for( + '.conversation', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + _anchor='n{}'.format(fake_uuid), + ) + else: + # covers ‘Delivered’, ‘Expected delivery date’ + assert 'deliver' in normalize_spaces(last_paragraph.text).lower()