Add a second step for choosing networks

Only the test channel has the option to isolate messages to one network.

This commits makes the choices less confusing by only showing the
network choice to those who have selected the test channel.
This commit is contained in:
Chris Hill-Scott
2021-05-11 11:07:30 +01:00
parent f640767f3d
commit a0f54539cc
9 changed files with 284 additions and 31 deletions

View File

@@ -2316,7 +2316,7 @@ class ServiceBroadcastAccountTypeField(GovukRadiosField):
# (service_mode, broadcast_channel, allowed_broadcast_provider) # (service_mode, broadcast_channel, allowed_broadcast_provider)
# to a value to be used in our form such as "live-severe-ee" # to a value to be used in our form such as "live-severe-ee"
def process_data(self, value): def process_data(self, value):
if isinstance(value, str): if not value or isinstance(value, str):
return super().process_data(value) return super().process_data(value)
(live, broadcast_channel, allowed_broadcast_provider) = value (live, broadcast_channel, allowed_broadcast_provider) = value
account_type = None account_type = None
@@ -2332,13 +2332,40 @@ class ServiceBroadcastAccountTypeField(GovukRadiosField):
# broadcast_channel and provider_restriction to be used by the flask route to send to the # broadcast_channel and provider_restriction to be used by the flask route to send to the
# API # API
def post_validate(self, form, validation_stopped): def post_validate(self, form, validation_stopped):
if not validation_stopped: if not validation_stopped and self.data:
split_values = self.data.split("-") split_values = self.data.split("-")
self.service_mode = split_values[0] self.service_mode = split_values[0]
self.broadcast_channel = split_values[1] self.broadcast_channel = split_values[1]
self.provider_restriction = split_values[2] if len(split_values) == 3 else 'all' self.provider_restriction = split_values[2] if len(split_values) == 3 else 'all'
class ServiceBroadcastChannelForm(StripWhitespaceForm):
channel = ServiceBroadcastAccountTypeField(
'Emergency alerts settings',
thing='mode or channel',
choices=[
("training-test", "Training mode"),
("live-test", "Test channel"),
("live-severe", "Live channel"),
("live-government", "Government channel"),
],
)
class ServiceBroadcastNetworkForm(StripWhitespaceForm):
network = ServiceBroadcastAccountTypeField(
'Choose a mobile network',
thing='mobile network',
choices=[
("live-test", "All networks"),
("live-test-ee", "EE only"),
("live-test-o2", "O2 only"),
("live-test-vodafone", "Vodafone only"),
("live-test-three", "Three only"),
],
)
class ServiceBroadcastAccountTypeForm(StripWhitespaceForm): class ServiceBroadcastAccountTypeForm(StripWhitespaceForm):
account_type = ServiceBroadcastAccountTypeField( account_type = ServiceBroadcastAccountTypeField(
'Change cell broadcast service type', 'Change cell broadcast service type',

View File

@@ -46,6 +46,8 @@ from app.main.forms import (
RenameServiceForm, RenameServiceForm,
SearchByNameForm, SearchByNameForm,
ServiceBroadcastAccountTypeForm, ServiceBroadcastAccountTypeForm,
ServiceBroadcastChannelForm,
ServiceBroadcastNetworkForm,
ServiceContactDetailsForm, ServiceContactDetailsForm,
ServiceDataRetentionEditForm, ServiceDataRetentionEditForm,
ServiceDataRetentionForm, ServiceDataRetentionForm,
@@ -318,9 +320,38 @@ def service_set_permission(service_id, permission):
@main.route("/services/<uuid:service_id>/service-settings/broadcasts", methods=["GET", "POST"]) @main.route("/services/<uuid:service_id>/service-settings/broadcasts", methods=["GET", "POST"])
@user_is_platform_admin @user_is_platform_admin
def service_set_broadcast_account_type(service_id): def service_set_broadcast_channel(service_id):
form = ServiceBroadcastAccountTypeForm( form = ServiceBroadcastChannelForm(
account_type=( channel=(
current_service.live,
current_service.broadcast_channel,
'all',
)
)
if form.validate_on_submit():
if form.channel.data == 'live-test':
return redirect(url_for(
'.service_set_broadcast_network',
service_id=current_service.id,
))
return redirect(url_for(
'.service_confirm_broadcast_account_type',
service_id=current_service.id,
account_type=form.channel.data,
))
return render_template(
'views/service-settings/service-set-broadcast-channel.html',
form=form,
)
@main.route("/services/<uuid:service_id>/service-settings/broadcasts/network", methods=["GET", "POST"])
@user_is_platform_admin
def service_set_broadcast_network(service_id):
form = ServiceBroadcastNetworkForm(
network=(
current_service.live, current_service.live,
current_service.broadcast_channel, current_service.broadcast_channel,
current_service.allowed_broadcast_provider current_service.allowed_broadcast_provider
@@ -331,11 +362,11 @@ def service_set_broadcast_account_type(service_id):
return redirect(url_for( return redirect(url_for(
'.service_confirm_broadcast_account_type', '.service_confirm_broadcast_account_type',
service_id=current_service.id, service_id=current_service.id,
account_type=form.account_type.data, account_type=form.network.data,
)) ))
return render_template( return render_template(
'views/service-settings/service-set-broadcast-account-type.html', 'views/service-settings/service-set-broadcast-network.html',
form=form, form=form,
) )

View File

@@ -243,8 +243,9 @@ class MainNavigation(Navigation):
'service_set_auth_type', 'service_set_auth_type',
'service_set_channel', 'service_set_channel',
'send_files_by_email_contact_details', 'send_files_by_email_contact_details',
'service_set_broadcast_account_type',
'service_confirm_broadcast_account_type', 'service_confirm_broadcast_account_type',
'service_set_broadcast_channel',
'service_set_broadcast_network',
'service_set_email_branding', 'service_set_email_branding',
'service_set_inbound_number', 'service_set_inbound_number',
'service_set_inbound_sms', 'service_set_inbound_sms',

View File

@@ -442,7 +442,7 @@
{% endcall %} {% endcall %}
{{ edit_field( {{ edit_field(
'Change', 'Change',
url_for('.service_set_broadcast_account_type', service_id=current_service.id), url_for('.service_set_broadcast_channel', service_id=current_service.id),
suffix='your settings for Send cell broadcasts' suffix='your settings for Send cell broadcasts'
) )
}} }}

View File

@@ -13,7 +13,7 @@
<div class="govuk-grid-column-five-sixths"> <div class="govuk-grid-column-five-sixths">
{{ page_header( {{ page_header(
'Confirm emergency alert settings', 'Confirm emergency alert settings',
back_link=url_for('.service_set_broadcast_account_type', service_id=current_service.id) back_link=url_for('.service_set_broadcast_channel', service_id=current_service.id)
) }} ) }}
{% if form.account_type.service_mode == 'training' %} {% if form.account_type.service_mode == 'training' %}
<p class="govuk-body"> <p class="govuk-body">

View File

@@ -0,0 +1,32 @@
{% extends "withnav_template.html" %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/form.html" import form_wrapper %}
{% from "components/back-link/macro.njk" import govukBackLink %}
{% block service_page_title %}
Emergency alerts settings
{% endblock %}
{% block maincolumn_content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-five-sixths">
{{ govukBackLink({
"text": "Back",
"href": url_for('.service_settings', service_id=current_service.id)
}) }}
{% call form_wrapper() %}
{{ form.channel(param_extensions={
'fieldset': {
'legend': {
'isPageHeading': True,
'classes': 'govuk-fieldset__legend--l'
}
}
}) }}
{{ page_footer('Continue') }}
{% endcall %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,32 @@
{% extends "withnav_template.html" %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/form.html" import form_wrapper %}
{% from "components/back-link/macro.njk" import govukBackLink %}
{% block service_page_title %}
Choose a mobile network
{% endblock %}
{% block maincolumn_content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-five-sixths">
{{ govukBackLink({
"text": "Back",
"href": url_for('.service_set_broadcast_channel', service_id=current_service.id)
}) }}
{% call form_wrapper() %}
{{ form.network(param_extensions={
'fieldset': {
'legend': {
'isPageHeading': True,
'classes': 'govuk-fieldset__legend--l'
}
}
}) }}
{{ page_footer('Continue') }}
{% endcall %}
</div>
</div>
{% endblock %}

View File

@@ -5418,24 +5418,20 @@ def test_get_service_set_broadcast_account_type(
): ):
response = platform_admin_client.get( response = platform_admin_client.get(
url_for( url_for(
'main.service_set_broadcast_account_type', 'main.service_set_broadcast_channel',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
) )
assert response.status_code == 200 assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.select_one('h1').text.strip() == "Change cell broadcast service type" assert page.select_one('h1').text.strip() == 'Emergency alerts settings'
expected_labels = [ expected_labels = [
"Training mode", "Training mode",
"Test channel (EE)", "Test channel",
"Test channel (O2)", "Live channel",
"Test channel (Three)", "Government channel",
"Test channel (Vodafone)",
"Test channel (all networks)",
"Live (all networks)",
"Government channel (all networks)",
] ]
labels = page.find_all('label', class_="govuk-radios__label") labels = page.find_all('label', class_="govuk-radios__label")
assert len(labels) == len(expected_labels) assert len(labels) == len(expected_labels)
@@ -5452,7 +5448,7 @@ def test_get_service_set_broadcast_account_type_has_no_radio_selected_for_non_br
): ):
response = platform_admin_client.get( response = platform_admin_client.get(
url_for( url_for(
'main.service_set_broadcast_account_type', 'main.service_set_broadcast_channel',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
) )
@@ -5475,16 +5471,23 @@ def test_get_service_set_broadcast_account_type_has_no_radio_selected_for_non_br
"live", "live",
"test", "test",
"vodafone", "vodafone",
"Test channel (Vodafone)", "Test channel",
"live-test-vodafone", "live-test",
), ),
( (
"live", "live",
"severe", "severe",
"all", "all",
"Live (all networks)", "Live channel",
"live-severe", "live-severe",
), ),
(
"live",
"government",
"all",
"Government channel",
"live-government",
),
] ]
) )
def test_get_service_set_broadcast_account_type_has_radio_selected_for_broadcast_service( def test_get_service_set_broadcast_account_type_has_radio_selected_for_broadcast_service(
@@ -5507,7 +5510,7 @@ def test_get_service_set_broadcast_account_type_has_radio_selected_for_broadcast
response = platform_admin_client.get( response = platform_admin_client.get(
url_for( url_for(
'main.service_set_broadcast_account_type', 'main.service_set_broadcast_channel',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
) )
@@ -5522,16 +5525,136 @@ def test_get_service_set_broadcast_account_type_has_radio_selected_for_broadcast
assert selected_label.text.strip() == expected_text assert selected_label.text.strip() == expected_text
@pytest.mark.parametrize(
'account_type,expected_redirect_endpoint,extra_args',
[
(
'training-test',
'.service_confirm_broadcast_account_type',
{'account_type': 'training-test'},
),
(
'live-test',
'.service_set_broadcast_network',
{},
),
(
'live-severe',
'.service_confirm_broadcast_account_type',
{'account_type': 'live-severe'},
),
(
'live-government',
'.service_confirm_broadcast_account_type',
{'account_type': 'live-government'},
),
]
)
def test_get_service_set_broadcast_channel_redirects(
client_request,
platform_admin_user,
mocker,
account_type,
expected_redirect_endpoint,
extra_args,
):
client_request.login(platform_admin_user)
client_request.post(
'main.service_set_broadcast_channel',
service_id=SERVICE_ONE_ID,
_data={
'channel': account_type,
},
_expected_redirect=url_for(
expected_redirect_endpoint,
service_id=SERVICE_ONE_ID,
_external=True,
**extra_args,
)
)
@pytest.mark.parametrize(
'service_mode,broadcast_channel,allowed_broadcast_provider,expected_text,expected_value',
[
(
"training",
"test",
"all",
"All networks",
"live-test",
),
(
"live",
"test",
"ee",
"EE only",
"live-test-ee",
),
(
"live",
"test",
"o2",
"O2 only",
"live-test-o2",
),
(
"live",
"test",
"three",
"Three only",
"live-test-three",
),
(
"live",
"test",
"vodafone",
"Vodafone only",
"live-test-vodafone",
),
]
)
def test_get_service_set_broadcast_network_has_radio_selected(
client_request,
platform_admin_user,
mocker,
service_mode,
broadcast_channel,
allowed_broadcast_provider,
expected_text,
expected_value
):
client_request.login(platform_admin_user)
service_one = service_json(
SERVICE_ONE_ID,
permissions=['broadcast'],
restricted=False,
broadcast_channel=broadcast_channel,
allowed_broadcast_provider=allowed_broadcast_provider,
)
mocker.patch('app.service_api_client.get_service', return_value={'data': service_one})
page = client_request.get(
'main.service_set_broadcast_network',
service_id=SERVICE_ONE_ID,
)
selected_radios = page.select('input[checked]')
assert len(selected_radios) == 1
selected_radio = selected_radios[0]
assert selected_radio.get('value') == expected_value
selected_label = selected_radio.find_next_sibling('label')
assert normalize_spaces(selected_label.text) == expected_text
@pytest.mark.parametrize( @pytest.mark.parametrize(
'value', 'value',
( (
'training-test',
'live-test-ee', 'live-test-ee',
'live-test-o2', 'live-test-o2',
'live-test-three', 'live-test-three',
'live-test-vodafone', 'live-test-vodafone',
'live-test', 'live-test',
'live-severe',
pytest.param('foo', marks=pytest.mark.xfail), pytest.param('foo', marks=pytest.mark.xfail),
), ),
) )
@@ -5543,10 +5666,10 @@ def test_post_service_set_broadcast_account_type_confirms(
): ):
client_request.login(platform_admin_user) client_request.login(platform_admin_user)
client_request.post( client_request.post(
'main.service_set_broadcast_account_type', 'main.service_set_broadcast_network',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
_data={ _data={
'account_type': value, 'network': value,
}, },
_expected_status=302, _expected_status=302,
_expected_redirect=url_for( _expected_redirect=url_for(
@@ -5669,21 +5792,27 @@ def test_post_service_set_broadcast_account_type_posts_data_to_api_and_redirects
) )
@pytest.mark.parametrize('endpoint, expected_error', (
('main.service_set_broadcast_channel', 'Error: Select mode or channel'),
('main.service_set_broadcast_network', 'Error: Select mobile network'),
))
def test_post_service_set_broadcast_account_type_shows_errors_if_no_radio_selected( def test_post_service_set_broadcast_account_type_shows_errors_if_no_radio_selected(
platform_admin_client, platform_admin_client,
mocker, mocker,
endpoint,
expected_error,
): ):
set_service_broadcast_settings_mock = mocker.patch('app.service_api_client.set_service_broadcast_settings') set_service_broadcast_settings_mock = mocker.patch('app.service_api_client.set_service_broadcast_settings')
mock_event_handler = mocker.patch('app.main.views.service_settings.create_broadcast_account_type_change_event') mock_event_handler = mocker.patch('app.main.views.service_settings.create_broadcast_account_type_change_event')
response = platform_admin_client.post( response = platform_admin_client.post(
url_for( url_for(
'main.service_set_broadcast_account_type', endpoint,
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
) )
assert response.status_code == 200 assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert "This field is required" in page.find("span", {"class": "govuk-error-message"}).text assert expected_error in page.find("span", {"class": "govuk-error-message"}).text
assert not set_service_broadcast_settings_mock.called assert not set_service_broadcast_settings_mock.called
assert not mock_event_handler.called assert not mock_event_handler.called

View File

@@ -245,8 +245,9 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, {
'service_preview_email_branding', 'service_preview_email_branding',
'service_preview_letter_branding', 'service_preview_letter_branding',
'service_set_auth_type', 'service_set_auth_type',
'service_set_broadcast_account_type',
'service_confirm_broadcast_account_type', 'service_confirm_broadcast_account_type',
'service_set_broadcast_channel',
'service_set_broadcast_network',
'service_set_channel', 'service_set_channel',
'service_set_email_branding', 'service_set_email_branding',
'service_set_inbound_number', 'service_set_inbound_number',