Merge pull request #3904 from alphagov/platform-admin-reply-to

Let platform admins add or update service reply to email address without the need for verification.
This commit is contained in:
Pea Tyczynska
2021-06-02 10:46:05 +01:00
committed by GitHub
2 changed files with 94 additions and 17 deletions

View File

@@ -511,22 +511,30 @@ def service_add_email_reply_to(service_id):
first_email_address = current_service.count_email_reply_to_addresses == 0
is_default = first_email_address if first_email_address else form.is_default.data
if form.validate_on_submit():
try:
notification_id = service_api_client.verify_reply_to_email_address(
service_id, form.email_address.data
)["data"]["id"]
except HTTPError as e:
if e.status_code == 409:
flash(e.message, 'error')
return redirect(url_for('.service_email_reply_to', service_id=service_id))
else:
raise e
return redirect(url_for(
'.service_verify_reply_to_address',
service_id=service_id,
notification_id=notification_id,
is_default=is_default
))
if current_user.platform_admin:
service_api_client.add_reply_to_email_address(
service_id,
email_address=form.email_address.data,
is_default=is_default
)
return redirect(url_for('.service_email_reply_to', service_id=service_id))
else:
try:
notification_id = service_api_client.verify_reply_to_email_address(
service_id, form.email_address.data
)["data"]["id"]
except HTTPError as e:
if e.status_code == 409:
flash(e.message, 'error')
return redirect(url_for('.service_email_reply_to', service_id=service_id))
else:
raise e
return redirect(url_for(
'.service_verify_reply_to_address',
service_id=service_id,
notification_id=notification_id,
is_default=is_default
))
return render_template(
'views/service-settings/email-reply-to/add.html',
@@ -630,7 +638,7 @@ def service_edit_email_reply_to(service_id, reply_to_email_id):
form.email_address.data = reply_to_email_address['email_address']
form.is_default.data = reply_to_email_address['is_default']
if form.validate_on_submit():
if form.email_address.data == reply_to_email_address["email_address"]:
if form.email_address.data == reply_to_email_address["email_address"] or current_user.platform_admin:
service_api_client.update_reply_to_email_address(
current_service.id,
reply_to_email_id=reply_to_email_id,

View File

@@ -2443,6 +2443,39 @@ def test_add_reply_to_email_address_sends_test_notification(
mock_verify.assert_called_once_with(SERVICE_ONE_ID, "test@example.com")
def test_service_add_reply_to_email_address_without_verification_for_platform_admin(
mocker,
client_request,
platform_admin_user
):
client_request.login(platform_admin_user)
mock_update = mocker.patch(
'app.service_api_client.add_reply_to_email_address'
)
mocker.patch(
'app.service_api_client.get_reply_to_email_addresses',
return_value=[create_reply_to_email_address(is_default=True)]
)
data = {"is_default": "y", "email_address": "test@example.gov.uk"}
client_request.post(
'main.service_add_email_reply_to',
service_id=SERVICE_ONE_ID,
_data=data,
_expected_status=302,
_expected_redirect=url_for(
'main.service_email_reply_to',
service_id=SERVICE_ONE_ID,
_external=True,
)
)
mock_update.assert_called_once_with(
SERVICE_ONE_ID,
email_address='test@example.gov.uk',
is_default=True)
@pytest.mark.parametrize("is_default,replace,expected_header", [(True, "&replace=123", "Change"), (False, "", "Add")])
@pytest.mark.parametrize("status,expected_failure,expected_success", [
("delivered", 0, 1),
@@ -2708,6 +2741,42 @@ def test_edit_reply_to_email_address_sends_verification_notification_if_address_
mock_verify.assert_called_once_with(SERVICE_ONE_ID, "test@example.gov.uk")
def test_service_edit_email_reply_to_updates_email_address_without_verification_for_platform_admin(
mocker,
fake_uuid,
client_request,
platform_admin_user
):
client_request.login(platform_admin_user)
mock_update = mocker.patch(
'app.service_api_client.update_reply_to_email_address'
)
mocker.patch(
'app.service_api_client.get_reply_to_email_address',
return_value=create_reply_to_email_address(is_default=True)
)
data = {"is_default": "y", "email_address": "test@example.gov.uk"}
client_request.post(
'main.service_edit_email_reply_to',
service_id=SERVICE_ONE_ID,
reply_to_email_id=fake_uuid,
_data=data,
_expected_status=302,
_expected_redirect=url_for(
'main.service_email_reply_to',
service_id=SERVICE_ONE_ID,
_external=True,
)
)
mock_update.assert_called_once_with(
SERVICE_ONE_ID,
reply_to_email_id=fake_uuid,
email_address='test@example.gov.uk',
is_default=True)
@pytest.mark.parametrize('reply_to_address, data, api_default_args', [
(create_reply_to_email_address(), {"is_default": "y"}, True),
(create_reply_to_email_address(), {}, True),