diff --git a/app/main/forms.py b/app/main/forms.py index e9a11b538..f2cf33f04 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -2316,6 +2316,8 @@ class ServiceBroadcastAccountTypeField(GovukRadiosField): # (service_mode, broadcast_channel, allowed_broadcast_provider) # to a value to be used in our form such as "live-severe-ee" def process_data(self, value): + if isinstance(value, str): + return super().process_data(value) (live, broadcast_channel, allowed_broadcast_provider) = value account_type = None if broadcast_channel: diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 29387c35e..8473a9e99 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -327,6 +327,31 @@ def service_set_broadcast_account_type(service_id): ) ) + if form.validate_on_submit(): + return redirect(url_for( + '.service_confirm_broadcast_account_type', + service_id=current_service.id, + account_type=form.account_type.data, + )) + + return render_template( + 'views/service-settings/service-set-broadcast-account-type.html', + form=form, + ) + + +@main.route( + "/services//service-settings/broadcasts/", + methods=["GET", "POST"] +) +@user_is_platform_admin +def service_confirm_broadcast_account_type(service_id, account_type): + form = ServiceBroadcastAccountTypeForm(account_type=account_type) + form.validate() + + if form.account_type.errors: + abort(404) + if form.validate_on_submit(): service_api_client.set_service_broadcast_settings( current_service.id, @@ -341,11 +366,10 @@ def service_set_broadcast_account_type(service_id): broadcast_channel=form.account_type.broadcast_channel, provider_restriction=form.account_type.provider_restriction, ) - return redirect(url_for(".service_settings", service_id=service_id)) return render_template( - 'views/service-settings/service-set-broadcast-account-type.html', + 'views/service-settings/service-confirm-broadcast-account-type.html', form=form, ) diff --git a/app/navigation.py b/app/navigation.py index 81fdf53cd..ce0ffe8bb 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -244,6 +244,7 @@ class MainNavigation(Navigation): 'service_set_channel', 'send_files_by_email_contact_details', 'service_set_broadcast_account_type', + 'service_confirm_broadcast_account_type', 'service_set_email_branding', 'service_set_inbound_number', 'service_set_inbound_sms', diff --git a/app/templates/views/service-settings/service-confirm-broadcast-account-type.html b/app/templates/views/service-settings/service-confirm-broadcast-account-type.html new file mode 100644 index 000000000..986ff5afc --- /dev/null +++ b/app/templates/views/service-settings/service-confirm-broadcast-account-type.html @@ -0,0 +1,53 @@ +{% extends "withnav_template.html" %} +{% from "components/page-header.html" import page_header %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/form.html" import form_wrapper %} + +{% block service_page_title %} + Confirm emergency alert settings +{% endblock %} + +{% block maincolumn_content %} + +
+
+ {{ page_header( + 'Confirm emergency alert settings', + back_link=url_for('.service_set_broadcast_account_type', service_id=current_service.id) + ) }} + {% if form.account_type.service_mode == 'training' %} +

+ Training +

+

+ No phones will receive alerts sent from this service. +

+ {% else %} +

+ + {% if form.account_type.broadcast_channel == 'severe' %} + Live + {% elif form.account_type.broadcast_channel == 'test' %} + Test + {% endif %} + {% if form.account_type.provider_restriction != 'all' %} + ({{ form.account_type.provider_restriction|format_mobile_network }}) + {% endif %} + +

+

+ Members of the public + {% if form.account_type.broadcast_channel == 'test' %} + who have switched on the test channel on their phones + {% endif %} + will receive alerts sent from this service. +

+ {% endif %} + + {% call form_wrapper() %} + {{ page_footer('Confirm') }} + {% endcall %} +
+
+ +{% endblock %} diff --git a/app/templates/views/service-settings/service-set-broadcast-account-type.html b/app/templates/views/service-settings/service-set-broadcast-account-type.html index 83b739d16..78d64c049 100644 --- a/app/templates/views/service-settings/service-set-broadcast-account-type.html +++ b/app/templates/views/service-settings/service-set-broadcast-account-type.html @@ -6,7 +6,7 @@ {% block service_page_title %} Send cell broadcasts {% endblock %} - + {% block maincolumn_content %}
@@ -24,7 +24,7 @@ } } }) }} - {{ page_footer('Save') }} + {{ page_footer('Continue') }} {% endcall %}
diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 596fa0987..94fbbe129 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -5521,6 +5521,103 @@ def test_get_service_set_broadcast_account_type_has_radio_selected_for_broadcast assert selected_label.text.strip() == expected_text +@pytest.mark.parametrize( + 'value', + ( + 'training-test', + 'live-test-ee', + 'live-test-o2', + 'live-test-three', + 'live-test-vodafone', + 'live-test', + 'live-severe', + pytest.param('foo', marks=pytest.mark.xfail), + ), +) +def test_post_service_set_broadcast_account_type_confirms( + client_request, + platform_admin_user, + mocker, + value, +): + client_request.login(platform_admin_user) + client_request.post( + 'main.service_set_broadcast_account_type', + service_id=SERVICE_ONE_ID, + _data={ + 'account_type': value, + }, + _expected_status=302, + _expected_redirect=url_for( + 'main.service_confirm_broadcast_account_type', + service_id=SERVICE_ONE_ID, + account_type=value, + _external=True, + ) + ) + + +@pytest.mark.parametrize( + 'value, expected_paragraphs', + [ + ('training-test', [ + 'Training', + 'No phones will receive alerts sent from this service.', + ]), + ('live-test-ee', [ + 'Test (EE)', + 'Members of the public who have switched on the test ' + 'channel on their phones will receive alerts sent from ' + 'this service.', + ]), + ('live-test-o2', [ + 'Test (O2)', + 'Members of the public who have switched on the test ' + 'channel on their phones will receive alerts sent from ' + 'this service.', + ]), + ('live-test-three', [ + 'Test (Three)', + 'Members of the public who have switched on the test ' + 'channel on their phones will receive alerts sent from ' + 'this service.', + ]), + ('live-test-vodafone', [ + 'Test (Vodafone)', + 'Members of the public who have switched on the test ' + 'channel on their phones will receive alerts sent from ' + 'this service.', + ]), + ('live-test', [ + 'Test', + 'Members of the public who have switched on the test ' + 'channel on their phones will receive alerts sent from ' + 'this service.', + ]), + ('live-severe', [ + 'Live', + 'Members of the public will receive alerts sent from this ' + 'service.', + ]), + ] +) +def test_post_service_set_broadcast_account_type_confirmation_page( + client_request, + platform_admin_user, + value, + expected_paragraphs, +): + client_request.login(platform_admin_user) + page = client_request.get( + 'main.service_confirm_broadcast_account_type', + service_id=SERVICE_ONE_ID, + account_type=value, + ) + assert [ + normalize_spaces(p.text) for p in page.select('main p') + ] == expected_paragraphs + + @pytest.mark.parametrize( 'value,service_mode,broadcast_channel,allowed_broadcast_provider', [ @@ -5543,12 +5640,10 @@ def test_post_service_set_broadcast_account_type_posts_data_to_api_and_redirects response = platform_admin_client.post( url_for( - 'main.service_set_broadcast_account_type', + 'main.service_confirm_broadcast_account_type', service_id=SERVICE_ONE_ID, - ), - data={ - 'account_type': value - } + account_type=value, + ) ) assert response.status_code == 302 assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True) diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 15b25c089..6df041e79 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -246,6 +246,7 @@ EXCLUDED_ENDPOINTS = tuple(map(Navigation.get_endpoint_with_blueprint, { 'service_preview_letter_branding', 'service_set_auth_type', 'service_set_broadcast_account_type', + 'service_confirm_broadcast_account_type', 'service_set_channel', 'service_set_email_branding', 'service_set_inbound_number',