From 91cdc9ffcba6d847ea7eee0eae21da8e130fd364 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Sun, 15 Oct 2017 13:40:49 +0100 Subject: [PATCH] Auto populate the phone number when replying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the only way of ‘replying’ to an inbound message is by copy/pasting the phone number from the inbound page into the send one off page. Rather than making people copy/paste, this commit puts the phone number in the session, if the user is going through the new reply flow. --- app/main/views/conversation.py | 23 ++++++++++++++++ .../views/templates/choose-reply.html | 2 +- tests/app/main/views/test_conversation.py | 26 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/main/views/conversation.py b/app/main/views/conversation.py index ffda0f6e4..abdd416de 100644 --- a/app/main/views/conversation.py +++ b/app/main/views/conversation.py @@ -1,5 +1,7 @@ from flask import ( jsonify, + session, + redirect, render_template, url_for, ) @@ -60,9 +62,30 @@ def conversation_reply( show_search_box=(len(templates) > 7), template_type='sms', search_form=SearchTemplatesForm(), + notification_id=notification_id, ) +@main.route("/services//conversation//reply-with/") +@login_required +@user_has_permissions('send_texts', admin_override=True) +def conversation_reply_with_template( + service_id, + notification_id, + template_id, +): + + session['recipient'] = get_user_number(service_id, notification_id) + session['placeholders'] = {'phone number': session['recipient']} + + return redirect(url_for( + 'main.send_one_off_step', + service_id=service_id, + template_id=template_id, + step_index=1, + )) + + def get_conversation_partials(service_id, user_number): return { diff --git a/app/templates/views/templates/choose-reply.html b/app/templates/views/templates/choose-reply.html index 3094748b2..11927b0c6 100644 --- a/app/templates/views/templates/choose-reply.html +++ b/app/templates/views/templates/choose-reply.html @@ -43,7 +43,7 @@ {% for template in templates %}

- {{ template.name }} + {{ template.name }}

{{ message_count_label(1, template.template_type, suffix='')|capitalize }} template diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index b5b296a02..1da8caf3b 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -257,8 +257,32 @@ def test_conversation_reply_shows_templates( assert normalize_spaces(link.text) == expected assert link.select_one('a')['href'].startswith( url_for( - 'main.view_template', + 'main.conversation_reply_with_template', service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, template_id='', ) ) + + +def test_conversation_reply_redirects_with_phone_number_from_notification( + client_request, + fake_uuid, + mock_get_notification, + mock_get_service_template, +): + + page = client_request.get( + 'main.conversation_reply_with_template', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + template_id=fake_uuid, + _follow_redirects=True, + ) + + for element, expected_text in [ + ('h1', 'Preview of Two week reminder'), + ('.sms-message-recipient', 'To: 07123 456789'), + ('.sms-message-wrapper', 'service one: Template content with & entity'), + ]: + assert normalize_spaces(page.select_one(element).text) == expected_text