diff --git a/app/main/views/conversation.py b/app/main/views/conversation.py index 8f32fba1e..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, ) @@ -7,6 +9,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 +27,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 +42,50 @@ 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(), + 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/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/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/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/app/templates/views/templates/_search-box.html b/app/templates/views/templates/_search-box.html new file mode 100644 index 000000000..d150ebebe --- /dev/null +++ b/app/templates/views/templates/_search-box.html @@ -0,0 +1,10 @@ + {% if show_search_box %} +
+ +
+ {% endif %} \ No newline at end of file diff --git a/app/templates/views/templates/choose-reply.html b/app/templates/views/templates/choose-reply.html new file mode 100644 index 000000000..a356d0100 --- /dev/null +++ b/app/templates/views/templates/choose-reply.html @@ -0,0 +1,47 @@ +{% 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 %} + + {% include "views/templates/_search-box.html" %} + + + {% endif %} + +{% endblock %} diff --git a/app/templates/views/templates/choose.html b/app/templates/views/templates/choose.html index e00dd75fa..bbf445874 100644 --- a/app/templates/views/templates/choose.html +++ b/app/templates/views/templates/choose.html @@ -54,16 +54,7 @@ {% endif %} - {% if show_search_box %} -
- -
- {% endif %} + {% include "views/templates/_search-box.html" %}