diff --git a/app/main/forms.py b/app/main/forms.py index 744724128..38c72b1c2 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -314,3 +314,7 @@ class RequestToGoLiveForm(Form): class ProviderForm(Form): priority = IntegerField('Priority', [validators.NumberRange(min=1, max=100, message="Must be between 1 and 100")]) + + +class ServiceReplyToEmailFrom(Form): + email_address = email_address() diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 30543f226..3c54e2cb5 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -19,7 +19,12 @@ from notifications_python_client.errors import HTTPError from app import service_api_client from app.main import main from app.utils import user_has_permissions, email_safe -from app.main.forms import ConfirmPasswordForm, ServiceNameForm, RequestToGoLiveForm +from app.main.forms import ( + ConfirmPasswordForm, + ServiceNameForm, + RequestToGoLiveForm, + ServiceReplyToEmailFrom +) from app import user_api_client from app import current_service @@ -217,3 +222,26 @@ def service_delete_confirm(service_id): heading='Delete this service from Notify', destructive=True, form=form) + + +@main.route("/services//service-settings/set-reply-to-email", methods=['GET', 'POST']) +@login_required +@user_has_permissions('manage_settings', admin_override=True) +def service_set_reply_to_email(service_id): + form = ServiceReplyToEmailFrom() + if form.validate_on_submit(): + message = 'Reply to email set to {}'.format(form.email_address.data) + service_api_client.update_service( + current_service['id'], + current_service['name'], + current_service['active'], + current_service['message_limit'], + current_service['restricted'], + current_service['users'], + current_service['email_from'], + reply_to_email_address=form.email_address.data) + flash(message, 'default_with_tick') + return redirect(url_for('.service_settings', service_id=service_id)) + return render_template( + 'views/service-settings/set-reply-to-email.html', + form=form) diff --git a/app/notify_client/api_client.py b/app/notify_client/api_client.py index 550821799..af5ed47ab 100644 --- a/app/notify_client/api_client.py +++ b/app/notify_client/api_client.py @@ -62,7 +62,8 @@ class ServiceAPIClient(NotificationsAPIClient): message_limit, restricted, users, - email_from): + email_from, + reply_to_email_address=None): """ Update a service. """ @@ -73,7 +74,8 @@ class ServiceAPIClient(NotificationsAPIClient): "message_limit": message_limit, "restricted": restricted, "users": users, - "email_from": email_from + "email_from": email_from, + "reply_to_email_address": reply_to_email_address } _attach_current_user(data) endpoint = "/service/{0}".format(service_id) diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index 57a44e7b4..c86f88d80 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -14,6 +14,10 @@ 'title': 'Change your service name', 'link': url_for('.service_name_change', service_id=current_service.id) }, + { + 'title': 'Set email reply to address', + 'link': url_for('.service_set_reply_to_email', service_id=current_service.id) + }, { 'title': 'Request to go live and turn off trial mode', 'link': url_for('.service_request_to_go_live', service_id=current_service.id), diff --git a/app/templates/views/service-settings/set-reply-to-email.html b/app/templates/views/service-settings/set-reply-to-email.html new file mode 100644 index 000000000..fcd77c303 --- /dev/null +++ b/app/templates/views/service-settings/set-reply-to-email.html @@ -0,0 +1,28 @@ +{% extends "withnav_template.html" %} +{% from "components/textbox.html" import textbox %} +{% from "components/page-footer.html" import page_footer %} + +{% block page_title %} + Request to go live – GOV.UK Notify +{% endblock %} + +{% block maincolumn_content %} + +
+
+

Set email reply to address

+
+ {{ textbox( + form.email_address, + width='1-1', + safe_error_message=True + ) }} + {{ page_footer( + 'Save', + back_link=url_for('.service_settings', service_id=current_service.id) + ) }} +
+
+
+ +{% endblock %} diff --git a/tests/__init__.py b/tests/__init__.py index 28929e720..ffd03e4e6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -35,7 +35,7 @@ def generate_uuid(): return uuid.uuid4() -def service_json(id_, name, users, message_limit=1000, active=False, restricted=True, email_from=None): +def service_json(id_, name, users, message_limit=1000, active=False, restricted=True, email_from=None, reply_to_email_address=None): # noqa return { 'id': id_, 'name': name, @@ -43,7 +43,8 @@ def service_json(id_, name, users, message_limit=1000, active=False, restricted= 'message_limit': message_limit, 'active': active, 'restricted': restricted, - 'email_from': email_from + 'email_from': email_from, + 'reply_to_email_address': reply_to_email_address } diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 7764606f4..ef53c1088 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -526,3 +526,26 @@ def test_route_for_platform_admin(mocker, app_, platform_admin_user, service_one [], platform_admin_user, service_one) + + +def test_set_reply_to_email_address(app_, + active_user_with_permissions, + mocker, + mock_update_service, + service_one): + with app_.test_request_context(): + with app_.test_client() as client: + client.login(active_user_with_permissions, mocker, service_one) + data = {"email_address": "test@someservice.gov.uk"} + response = client.post(url_for('main.service_set_reply_to_email', service_id=service_one['id']), + data=data, + follow_redirects=True) + assert response.status_code == 200 + mock_update_service.assert_called_with(service_one['id'], + service_one['name'], + service_one['active'], + service_one['message_limit'], + service_one['restricted'], + ANY, + service_one['email_from'], + "test@someservice.gov.uk") diff --git a/tests/conftest.py b/tests/conftest.py index 2a573f754..d181a2ebd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -99,10 +99,11 @@ def mock_update_service(mocker): message_limit, restricted, users, - email_from): + email_from, + reply_to_email_address=None): service = service_json( service_id, service_name, users, message_limit=message_limit, - active=active, restricted=restricted, email_from=email_from) + active=active, restricted=restricted, email_from=email_from, reply_to_email_address=reply_to_email_address) return {'data': service} return mocker.patch(