Allow sending sms to be disabled

Platform admins can now disable sending sms for a service. If sending
sms is disabled, this will also hide all the other sms options in the
Settings table.
This commit is contained in:
Katie Smith
2017-06-26 16:22:48 +01:00
parent 5986dfd415
commit 95f9d26e91
4 changed files with 128 additions and 60 deletions

View File

@@ -247,6 +247,14 @@ def service_switch_can_send_email(service_id):
return redirect(url_for('.service_settings', service_id=service_id)) return redirect(url_for('.service_settings', service_id=service_id))
@main.route("/services/<service_id>/service-settings/can-send-sms")
@login_required
@user_has_permissions(admin_override=True)
def service_switch_can_send_sms(service_id):
switch_service_permissions(service_id, 'sms')
return redirect(url_for('.service_settings', service_id=service_id))
@main.route("/services/<service_id>/service-settings/archive", methods=['GET', 'POST']) @main.route("/services/<service_id>/service-settings/archive", methods=['GET', 'POST'])
@login_required @login_required
@user_has_permissions('manage_settings', admin_override=True) @user_has_permissions('manage_settings', admin_override=True)
@@ -335,6 +343,15 @@ def service_set_sms_sender(service_id):
form=form) form=form)
@main.route("/services/<service_id>/service-settings/set-sms", methods=['GET'])
@login_required
@user_has_permissions('manage_settings', admin_override=True)
def service_set_sms(service_id):
return render_template(
'views/service-settings/set-sms.html',
)
@main.route("/services/<service_id>/service-settings/set-international-sms", methods=['GET']) @main.route("/services/<service_id>/service-settings/set-international-sms", methods=['GET'])
@login_required @login_required
@user_has_permissions('manage_settings', admin_override=True) @user_has_permissions('manage_settings', admin_override=True)

View File

@@ -45,37 +45,47 @@
{% endif %} {% endif %}
{% call row() %} {% call row() %}
{{ text_field('Text message sender') }} {{ text_field('Send text messages') }}
{{ text_field(current_service.sms_sender) }} {{ boolean_field('sms' in current_service.permissions) }}
{% if current_user.has_permissions([], admin_override=True) or not can_receive_inbound %} {{ edit_field('Change', url_for('.service_set_sms', service_id=current_service.id)) }}
{{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=False)) }} {% endcall %}
{% else %}
{{ text_field('') }} {% if 'sms' in current_service.permissions %}
{% call row() %}
{{ text_field('Text message sender') }}
{{ text_field(current_service.sms_sender) }}
{% if current_user.has_permissions([], admin_override=True) or not can_receive_inbound %}
{{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=False)) }}
{% else %}
{{ text_field('') }}
{% endif %}
{% endcall %}
{% call row() %}
{{ text_field('International text messages') }}
{{ boolean_field('international_sms' in current_service.permissions) }}
{{ edit_field('Change', url_for('.service_set_international_sms', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Receive text messages') }}
{{ boolean_field('inbound_sms' in current_service.permissions) }}
{{ edit_field('Change', url_for('.service_set_inbound_sms', service_id=current_service.id)) }}
{% endcall %}
{% if can_receive_inbound %}
{% call row() %}
{{ text_field('API endpoint for received text messages') }}
{{ text_field(
'None' if not inbound_api_url else inbound_api_url,
status='' if inbound_api_url else 'default'
) }}
{{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }}
{% endcall %}
{% endif %} {% endif %}
{% endcall %}
{% call row() %}
{{ text_field('International text messages') }}
{{ boolean_field('international_sms' in current_service.permissions) }}
{{ edit_field('Change', url_for('.service_set_international_sms', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Receive text messages') }}
{{ boolean_field('inbound_sms' in current_service.permissions) }}
{{ edit_field('Change', url_for('.service_set_inbound_sms', service_id=current_service.id)) }}
{% endcall %}
{% if can_receive_inbound %}
{% call row() %}
{{ text_field('API endpoint for received text messages') }}
{{ text_field(
'None' if not inbound_api_url else inbound_api_url,
status='' if inbound_api_url else 'default'
) }}
{{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }}
{% endcall %}
{% endif %} {% endif %}
{% call row() %} {% call row() %}
@@ -177,10 +187,22 @@
</a> </a>
</li> </li>
<li class="bottom-gutter"> <li class="bottom-gutter">
<a href="{{ url_for('.service_switch_can_send_international_sms', service_id=current_service.id) }}" class="button"> <a href="{{ url_for('.service_switch_can_send_sms', service_id=current_service.id) }}" class="button">
{{ 'Stop sending international sms' if 'international_sms' in current_service.permissions else 'Allow international sms' }} {{ 'Stop sending sms' if 'sms' in current_service.permissions else 'Allow to send sms' }}
</a> </a>
</li> </li>
{% if 'sms' in current_service.permissions %}
<li class="bottom-gutter">
<a href="{{ url_for('.service_switch_can_send_international_sms', service_id=current_service.id) }}" class="button">
{{ 'Stop sending international sms' if 'international_sms' in current_service.permissions else 'Allow to send international sms' }}
</a>
</li>
<li class="bottom-gutter">
<a href="{{ url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=True) }}" class="button">
{{ 'Stop inbound sms' if can_receive_inbound else 'Allow inbound sms' }}
</a>
</li>
{% endif %}
{% if current_service.active %} {% if current_service.active %}
<li class="bottom-gutter"> <li class="bottom-gutter">
<a href="{{ url_for('.archive_service', service_id=current_service.id) }}" class="button"> <a href="{{ url_for('.archive_service', service_id=current_service.id) }}" class="button">
@@ -200,11 +222,6 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
<li class="bottom-gutter">
<a href="{{ url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=True) }}" class="button">
{{ 'Stop inbound sms' if can_receive_inbound else 'Allow inbound sms' }}
</a>
</li>
</ul> </ul>
{% endif %} {% endif %}

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 %}
Text messages
{% endblock %}
{% block maincolumn_content %}
<div class="grid-row">
<div class="column-five-sixths">
<h1 class="heading-large">Text messages</h1>
{% if 'sms' in current_service.permissions %}
<p>
Your service can send text messages.
</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 text messages 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

@@ -21,6 +21,7 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
'Service name service one Change', 'Service name service one Change',
'Send emails On Change', 'Send emails On Change',
'Email reply to address None Change', 'Email reply to address None Change',
'Send text messages On Change',
'Text message sender GOVUK Change', 'Text message sender GOVUK Change',
'International text messages Off Change', 'International text messages Off Change',
'Receive text messages Off Change', 'Receive text messages Off Change',
@@ -31,6 +32,7 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
'Service name service one Change', 'Service name service one Change',
'Send emails On Change', 'Send emails On Change',
'Email reply to address None Change', 'Email reply to address None Change',
'Send text messages On Change',
'Text message sender GOVUK Change', 'Text message sender GOVUK Change',
'International text messages Off Change', 'International text messages Off Change',
'Receive text messages Off Change', 'Receive text messages Off Change',
@@ -70,6 +72,7 @@ def test_should_show_overview(
'Service name service one Change', 'Service name service one Change',
'Send emails On Change', 'Send emails On Change',
'Email reply to address test@example.com Change', 'Email reply to address test@example.com Change',
'Send text messages On Change',
'Text message sender elevenchars', 'Text message sender elevenchars',
'International text messages On Change', 'International text messages On Change',
'Receive text messages On Change', 'Receive text messages On Change',
@@ -80,6 +83,7 @@ def test_should_show_overview(
'Service name service one Change', 'Service name service one Change',
'Send emails On Change', 'Send emails On Change',
'Email reply to address test@example.com Change', 'Email reply to address test@example.com Change',
'Send text messages On Change',
'Text message sender elevenchars Change', 'Text message sender elevenchars Change',
'International text messages Off Change', 'International text messages Off Change',
'Receive text messages Off Change', 'Receive text messages Off Change',
@@ -158,7 +162,7 @@ def test_if_can_receive_inbound_then_cant_change_sms_sender(
service_one, service_one,
mock_get_letter_organisations, mock_get_letter_organisations,
): ):
service_one['permissions'] = ['email', 'sms','inbound_sms'] service_one['permissions'] = ['email', 'sms', 'inbound_sms']
service_one['sms_sender'] = 'SomeNumber' service_one['sms_sender'] = 'SomeNumber'
response = logged_in_client.get(url_for( response = logged_in_client.get(url_for(
'main.service_settings', service_id=service_one['id'] 'main.service_settings', service_id=service_one['id']
@@ -183,7 +187,7 @@ def test_letter_contact_block_shows_none_if_not_set(
)) ))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
div = page.find_all('tr')[7].find_all('td')[1].div div = page.find_all('tr')[5].find_all('td')[1].div
assert div.text.strip() == 'None' assert div.text.strip() == 'None'
assert 'default' in div.attrs['class'][0] assert 'default' in div.attrs['class'][0]
@@ -201,7 +205,7 @@ def test_escapes_letter_contact_block(
)) ))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
div = str(page.find_all('tr')[7].find_all('td')[1].div) div = str(page.find_all('tr')[5].find_all('td')[1].div)
assert 'foo<br>bar' in div assert 'foo<br>bar' in div
assert '<script>' not in div assert '<script>' not in div
@@ -576,38 +580,30 @@ def test_route_for_platform_admin_update_service(
service_one) service_one)
def test_switch_service_enable_email( @pytest.mark.parametrize('notification_type, permissions_before_switch, permissions_after_switch', [
('email', [], ['email']),
('email', ['email'], []),
('sms', [], ['sms']),
('sms', ['sms'], [])
])
def test_enabling_and_disabling_email_and_sms(
logged_in_platform_admin_client, logged_in_platform_admin_client,
service_one, service_one,
mocker, mocker,
notification_type,
permissions_before_switch,
permissions_after_switch,
): ):
service_one['permissions'] = [] service_one['permissions'] = permissions_before_switch
mocked_fn = mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one) mocked_fn = mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one)
response = logged_in_platform_admin_client.get( response = logged_in_platform_admin_client.get(
url_for('main.service_switch_can_send_email', service_id=service_one['id']) url_for('main.service_switch_can_send_{}'.format(notification_type), service_id=service_one['id'])
) )
assert response.status_code == 302 assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True) 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']}) assert mocked_fn.call_args == call(service_one['id'], {'permissions': permissions_after_switch})
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( def test_set_reply_to_email_address(