diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index f285b72b8..0d273c76d 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -474,12 +474,17 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id): first_email_address = current_service.count_email_reply_to_addresses == 0 notification = notification_api_client.get_notification(current_app.config["NOTIFY_SERVICE_ID"], notification_id) replace = request.args.get('replace', False) + replace = False if replace == "False" else replace + existing_is_default = False + if replace: + existing = current_service.get_email_reply_to_address(replace) + existing_is_default = existing['is_default'] verification_status = "pending" is_default = True if (request.args.get('is_default', False) == "True") else False if notification["status"] in DELIVERED_STATUSES: verification_status = "success" if notification["to"] not in [i["email_address"] for i in current_service.email_reply_to_addresses]: - if replace and replace != "False": + if replace: service_api_client.update_reply_to_email_address( current_service.id, replace, email_address=notification["to"], is_default=is_default ) @@ -505,6 +510,7 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id): notification_id=notification_id, verification_status=verification_status, is_default=is_default, + existing_is_default=existing_is_default, form=form, first_email_address=first_email_address, replace=replace 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 index ce19444d7..ae6420c31 100644 --- a/app/templates/views/service-settings/email-reply-to/_verify-updates.html +++ b/app/templates/views/service-settings/email-reply-to/_verify-updates.html @@ -36,7 +36,7 @@

{% endcall %} - {% if replace and replace != "False" %} + {% if replace %} {% set form_url = url_for('.service_edit_email_reply_to', service_id=service_id, reply_to_email_id=replace) %} {% else %} {% set form_url = url_for('.service_add_email_reply_to', service_id=service_id) %} @@ -50,7 +50,7 @@ safe_error_message=True, hint='This should be a shared inbox managed by your team, not your own email address' ) }} - {% if not first_email_address and not replace %} + {% if not first_email_address and not existing_is_default %}
{{ checkbox(form.is_default) }}
diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index eb742153e..e19d06eec 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -2040,7 +2040,16 @@ def test_add_reply_to_email_address_sends_test_notification( ]) @freeze_time("2018-06-01 11:11:00.061258") def test_service_verify_reply_to_address( - mocker, client_request, fake_uuid, status, expected_failure, expected_success, is_default, replace, expected_header + mocker, + client_request, + fake_uuid, + get_non_default_reply_to_email_address, + status, + expected_failure, + expected_success, + is_default, + replace, + expected_header ): notification = { "id": fake_uuid,