diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 559965ac3..57db02568 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -4,6 +4,7 @@ from flask import ( abort, current_app, flash, + jsonify, redirect, render_template, request, @@ -422,6 +423,22 @@ def service_add_email_reply_to(service_id): @login_required @user_has_permissions('manage_service') def verify_reply_to_address(service_id, notification_id): + return render_template( + 'views/service-settings/email-reply-to/verify.html', + service_id=service_id, + notification_id=notification_id, + partials=get_verify_reply_to_address_partials(service_id, notification_id) + ) + + +@main.route("/services//service-settings/email-reply-to//verify.json") +@login_required +@user_has_permissions('manage_service') +def verify_reply_to_address_updates(service_id, notification_id): + return jsonify(**get_verify_reply_to_address_partials(service_id, notification_id)) + + +def get_verify_reply_to_address_partials(service_id, notification_id): notification = notification_api_client.get_notification(current_app.config["NOTIFY_SERVICE_ID"], notification_id) verification_status = "pending" is_default = request.args.get('is_default', False) @@ -435,14 +452,16 @@ def verify_reply_to_address(service_id, notification_id): if notification["status"] in ["failed", "permanent-failure", "technical-failure", "temporary-failure"]: verification_status = "failure" # also include condition for when lots of time passes - return render_template( - 'views/service-settings/email-reply-to/verify.html', - reply_to_email_address=notification["to"], - service_id=service_id, - notification_id=notification_id, - verification_status=verification_status, - is_default=is_default - ) + return { + 'status': render_template( + 'views/service-settings/email-reply-to/_verify-updates.html', + reply_to_email_address=notification["to"], + service_id=current_service.id, + notification_id=notification_id, + verification_status=verification_status, + is_default=is_default, + ), + } @main.route( diff --git a/app/templates/views/service-settings/email-reply-to/_verify-updates.html b/app/templates/views/service-settings/email-reply-to/_verify-updates.html new file mode 100644 index 000000000..ad628f077 --- /dev/null +++ b/app/templates/views/service-settings/email-reply-to/_verify-updates.html @@ -0,0 +1,22 @@ +{% from "components/banner.html" import banner %} + +
+ {% if verification_status == "pending" %} +

+ We have sent a notification to {{ reply_to_email_address }} to check if it's a working email address. + +

+

+ Once we receive a delivery confirmation, we will update your list of reply-to email addresses. +

+ +

+ Refresh +

+ {% elif verification_status == "success" %} + {{ banner("Yay success! Your new reply-to email has been added ^__^", type='default', with_tick=True) }} + {% elif verification_status == "failure" %} + {{ banner("Sorry dawg, this email address doesn't seem to be working :d", type='dangerous') }} + Try again + {% endif %} +
diff --git a/app/templates/views/service-settings/email-reply-to/verify.html b/app/templates/views/service-settings/email-reply-to/verify.html index 86aceb915..d79b00080 100644 --- a/app/templates/views/service-settings/email-reply-to/verify.html +++ b/app/templates/views/service-settings/email-reply-to/verify.html @@ -4,6 +4,7 @@ {% from "components/page-header.html" import page_header %} {% from "components/page-footer.html" import page_footer %} {% from "components/form.html" import form_wrapper %} +{% from "components/ajax-block.html" import ajax_block %} {% block service_page_title %} Verifying your reply-to email address @@ -15,22 +16,10 @@ 'Verifying your reply-to email address', back_link=url_for('main.service_email_reply_to', service_id=current_service.id) ) }} - {% if verification_status == "pending" %} -

- We have sent a notification to {{ reply_to_email_address }} to check if it's a working email address. - -

-

- Once we receive a delivery confirmation, we will update your list of reply-to email addresses. -

- -

- Refresh -

- {% elif verification_status == "success" %} - {{ banner("Yay success! Your new reply-to email has been added ^__^", type='message', with_tick=True) }} - {% elif verification_status == "failure" %} - {{ banner("Sorry dawg, this email address doesn't seem to be working :d", type='dangerous') }} - Try again - {% endif %} + {{ ajax_block( + partials, + url_for('main.verify_reply_to_address_updates', service_id=service_id, notification_id=notification_id), + 'status', + finished=finished + ) }} {% endblock %} diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index b210baf1b..1957b4829 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -2056,7 +2056,7 @@ def test_verify_reply_to_address( ) assert page.find('h1').text == 'Verifying your reply-to email address' assert len(page.find_all('div', class_='banner-dangerous')) == expected_failure - assert len(page.find_all('div', class_='banner-message-with-tick')) == expected_success + assert len(page.find_all('div', class_='banner-default-with-tick')) == expected_success if status == "delivered": mock_add_reply_to_email_address.assert_called_once_with(