Allow sending emails to be disabled

Platform admins can now disable sending of emails for a service. If
sending emails is disabled, this will also hide the option to change the
Email reply to address.
This commit is contained in:
Katie Smith
2017-06-26 15:22:06 +01:00
parent 11adf17330
commit 5986dfd415
4 changed files with 120 additions and 8 deletions

View File

@@ -239,6 +239,14 @@ def service_switch_can_send_international_sms(service_id):
return redirect(url_for('.service_settings', service_id=service_id))
@main.route("/services/<service_id>/service-settings/can-send-email")
@login_required
@user_has_permissions(admin_override=True)
def service_switch_can_send_email(service_id):
switch_service_permissions(service_id, 'email')
return redirect(url_for('.service_settings', service_id=service_id))
@main.route("/services/<service_id>/service-settings/archive", methods=['GET', 'POST'])
@login_required
@user_has_permissions('manage_settings', admin_override=True)
@@ -276,6 +284,15 @@ def resume_service(service_id):
return service_settings(service_id)
@main.route("/services/<service_id>/service-settings/set-email", methods=['GET'])
@login_required
@user_has_permissions('manage_settings', admin_override=True)
def service_set_email(service_id):
return render_template(
'views/service-settings/set-email.html',
)
@main.route("/services/<service_id>/service-settings/set-reply-to-email", methods=['GET', 'POST'])
@login_required
@user_has_permissions('manage_settings', admin_override=True)

View File

@@ -26,14 +26,24 @@
{% endcall %}
{% call row() %}
{{ text_field('Email reply to address') }}
{{ text_field(
current_service.reply_to_email_address,
status='' if current_service.reply_to_email_address else 'default'
) }}
{{ edit_field('Change', url_for('.service_set_reply_to_email', service_id=current_service.id)) }}
{{ text_field('Send emails') }}
{{ boolean_field('email' in current_service.permissions) }}
{{ edit_field('Change', url_for('.service_set_email', service_id=current_service.id)) }}
{% endcall %}
{% if 'email' in current_service.permissions %}
{% call row() %}
{{ text_field('Email reply to address') }}
{{ text_field(
current_service.reply_to_email_address,
status='' if current_service.reply_to_email_address else 'default'
) }}
{{ edit_field('Change', url_for('.service_set_reply_to_email', service_id=current_service.id)) }}
{% endcall %}
{% endif %}
{% call row() %}
{{ text_field('Text message sender') }}
{{ text_field(current_service.sms_sender) }}
@@ -156,6 +166,11 @@
{{ 'Take service out of research mode' if current_service.research_mode else 'Put into research mode' }}
</a>
</li>
<li class="bottom-gutter">
<a href="{{ url_for('.service_switch_can_send_email', service_id=current_service.id) }}" class="button">
{{ 'Stop sending emails' if 'email' in current_service.permissions else 'Allow to send emails' }}
</a>
</li>
<li class="bottom-gutter">
<a href="{{ url_for('.service_switch_can_send_letters', service_id=current_service.id) }}" class="button">
{{ 'Stop sending letters' if 'letter' in current_service.permissions else 'Allow to send letters' }}

View File

@@ -0,0 +1,38 @@
{% extends "withnav_template.html" %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Emails
{% endblock %}
{% block maincolumn_content %}
<div class="grid-row">
<div class="column-five-sixths">
<h1 class="heading-large">Emails</h1>
{% if 'email' in current_service.permissions %}
<p>
Your service can send emails.
</p>
<p>
If you want to turn it off,
<a href="{{ url_for('.support') }}">get in touch with the GOV.UK Notify team</a>.
</p>
{% else %}
<p>
Sending emails is an invitation&#8209;only feature.
</p>
<p>
If you want to try it out,
<a href="{{ url_for('.support') }}">get in touch with the GOV.UK Notify team</a>.
</p>
{% endif %}
{{ page_footer(
back_link=url_for('.service_settings', service_id=current_service.id),
back_link_text='Back to settings'
) }}
</div>
</div>
{% endblock %}

View File

@@ -19,6 +19,7 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
(active_user_with_permissions, [
'Label Value Action',
'Service name service one Change',
'Send emails On Change',
'Email reply to address None Change',
'Text message sender GOVUK Change',
'International text messages Off Change',
@@ -28,6 +29,7 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
(platform_admin_user, [
'Label Value Action',
'Service name service one Change',
'Send emails On Change',
'Email reply to address None Change',
'Text message sender GOVUK Change',
'International text messages Off Change',
@@ -47,6 +49,8 @@ def test_should_show_overview(
user,
expected_rows,
):
service_one['permissions'] = ['sms', 'email']
client.login(user(fake_uuid), mocker, service_one)
response = client.get(url_for(
'main.service_settings', service_id=service_one['id']
@@ -64,6 +68,7 @@ def test_should_show_overview(
@pytest.mark.parametrize('permissions, expected_rows', [
(['email', 'sms', 'inbound_sms', 'international_sms'], [
'Service name service one Change',
'Send emails On Change',
'Email reply to address test@example.com Change',
'Text message sender elevenchars',
'International text messages On Change',
@@ -73,6 +78,7 @@ def test_should_show_overview(
]),
(['email', 'sms'], [
'Service name service one Change',
'Send emails On Change',
'Email reply to address test@example.com Change',
'Text message sender elevenchars Change',
'International text messages Off Change',
@@ -114,7 +120,7 @@ def test_service_settings_show_elided_api_url_if_needed(
url,
elided_url
):
service_one['permissions'] = ['inbound_sms']
service_one['permissions'] = ['sms', 'email', 'inbound_sms']
service_one['inbound_api'] = [fake_uuid]
mocked_get_fn = mocker.patch(
@@ -152,7 +158,7 @@ def test_if_can_receive_inbound_then_cant_change_sms_sender(
service_one,
mock_get_letter_organisations,
):
service_one['permissions'] = ['inbound_sms']
service_one['permissions'] = ['email', 'sms','inbound_sms']
service_one['sms_sender'] = 'SomeNumber'
response = logged_in_client.get(url_for(
'main.service_settings', service_id=service_one['id']
@@ -570,12 +576,47 @@ def test_route_for_platform_admin_update_service(
service_one)
def test_switch_service_enable_email(
logged_in_platform_admin_client,
service_one,
mocker,
):
service_one['permissions'] = []
mocked_fn = mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one)
response = logged_in_platform_admin_client.get(
url_for('main.service_switch_can_send_email', service_id=service_one['id'])
)
assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True)
assert mocked_fn.call_args == call(service_one['id'], {'permissions': ['email']})
def test_switch_service_disable_email(
logged_in_platform_admin_client,
service_one,
mocker,
):
service_one['permissions'] = ['email']
mocked_fn = mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one)
response = logged_in_platform_admin_client.get(
url_for('main.service_switch_can_send_email', service_id=service_one['id'])
)
assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True)
assert mocked_fn.call_args == call(service_one['id'], {'permissions': []})
def test_set_reply_to_email_address(
logged_in_client,
mock_update_service,
service_one,
mock_get_letter_organisations,
):
service_one['permissions'] = ['email']
data = {"email_address": "test@someservice.gov.uk"}
response = logged_in_client.post(url_for('main.service_set_reply_to_email', service_id=service_one['id']),
data=data,
@@ -591,6 +632,7 @@ def test_if_reply_to_email_address_set_then_form_populated(
logged_in_client,
service_one,
):
service_one['permissions'] = ['email']
service_one['reply_to_email_address'] = 'test@service.gov.uk'
response = logged_in_client.get(url_for('main.service_set_reply_to_email', service_id=service_one['id']))