diff --git a/app/main/views/conversation.py b/app/main/views/conversation.py index 8f32fba1e..ffda0f6e4 100644 --- a/app/main/views/conversation.py +++ b/app/main/views/conversation.py @@ -7,6 +7,7 @@ from flask_login import login_required from notifications_utils.recipients import format_phone_number_human_readable from notifications_utils.template import SMSPreviewTemplate from app.main import main +from app.main.forms import SearchTemplatesForm from app.utils import user_has_permissions from app import notification_api_client, service_api_client from notifications_python_client.errors import HTTPError @@ -24,6 +25,7 @@ def conversation(service_id, notification_id): user_number=user_number, partials=get_conversation_partials(service_id, user_number), updates_url=url_for('.conversation_updates', service_id=service_id, notification_id=notification_id), + notification_id=notification_id, ) @@ -38,6 +40,29 @@ def conversation_updates(service_id, notification_id): )) +@main.route("/services//conversation//reply-with") +@login_required +@user_has_permissions('send_texts', admin_override=True) +def conversation_reply( + service_id, + notification_id, +): + + templates = [ + template + for template in service_api_client.get_service_templates(service_id)['data'] + if template['template_type'] == 'sms' + ] + + return render_template( + 'views/templates/choose-reply.html', + templates=templates, + show_search_box=(len(templates) > 7), + template_type='sms', + search_form=SearchTemplatesForm(), + ) + + def get_conversation_partials(service_id, user_number): return { diff --git a/app/templates/views/conversations/conversation.html b/app/templates/views/conversations/conversation.html index 6028ea791..b46b57950 100644 --- a/app/templates/views/conversations/conversation.html +++ b/app/templates/views/conversations/conversation.html @@ -22,6 +22,12 @@ 'messages', ) }} + {% if current_user.has_permissions(['send_texts'], admin_override=True) %} +

+ Send a text message to this phone number +

+ {% endif %} + {% endblock %} diff --git a/app/templates/views/templates/choose-reply.html b/app/templates/views/templates/choose-reply.html new file mode 100644 index 000000000..3094748b2 --- /dev/null +++ b/app/templates/views/templates/choose-reply.html @@ -0,0 +1,56 @@ +{% from "components/pill.html" import pill %} +{% from "components/message-count-label.html" import message_count_label %} +{% from "components/textbox.html" import textbox %} + +{% extends "withnav_template.html" %} + +{% block service_page_title %} + Choose a template +{% endblock %} + +{% block maincolumn_content %} + +

Choose a template

+ + {% if not templates %} + + {% if current_user.has_permissions(permissions=['manage_templates'], any_=True) %} +

+ You need a template before you can send text messages. +

+ Add a new template + {% else %} +

+ You need to ask your service manager to add templates before you + can send text messages. +

+ {% endif %} + + {% else %} + + {% if show_search_box %} +
+ +
+ {% endif %} + + + {% endif %} + +{% endblock %} diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index 5076b9bb5..b5b296a02 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -214,3 +214,51 @@ def test_view_conversation_with_empty_inbound( messages = page.select('.sms-message-wrapper') assert len(messages) == 1 + + +def test_conversation_links_to_reply( + client_request, + fake_uuid, + mock_get_notification, + mock_get_notifications, + mock_get_inbound_sms, +): + page = client_request.get( + 'main.conversation', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + + assert page.select('main p')[-1].select_one('a')['href'] == ( + url_for( + '.conversation_reply', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + ) + + +def test_conversation_reply_shows_templates( + client_request, + fake_uuid, + mock_get_service_templates, +): + page = client_request.get( + 'main.conversation_reply', + service_id=SERVICE_ONE_ID, + notification_id=fake_uuid, + ) + + for index, expected in enumerate([ + 'sms_template_one', + 'sms_template_two', + ]): + link = page.select('.message-name')[index] + assert normalize_spaces(link.text) == expected + assert link.select_one('a')['href'].startswith( + url_for( + 'main.view_template', + service_id=SERVICE_ONE_ID, + template_id='', + ) + )