Merge pull request #3879 from alphagov/add-government-channel

Add an option to set a service to the government channel for emergency alerts
This commit is contained in:
Chris Hill-Scott
2021-05-13 15:10:15 +01:00
committed by GitHub
13 changed files with 654 additions and 73 deletions

View File

@@ -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 not value or isinstance(value, str):
return super().process_data(value)
(live, broadcast_channel, allowed_broadcast_provider) = value
account_type = None
if broadcast_channel:
@@ -2330,13 +2332,61 @@ class ServiceBroadcastAccountTypeField(GovukRadiosField):
# broadcast_channel and provider_restriction to be used by the flask route to send to the
# API
def post_validate(self, form, validation_stopped):
if not validation_stopped:
if not validation_stopped and self.data:
split_values = self.data.split("-")
self.service_mode = split_values[0]
self.broadcast_channel = split_values[1]
self.provider_restriction = split_values[2] if len(split_values) == 3 else 'all'
class OptionalServiceBroadcastAccountTypeField(ServiceBroadcastAccountTypeField):
def pre_validate(self, form):
if self.data is None:
return
super().pre_validate(form)
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_variant = ServiceBroadcastAccountTypeField(
'Choose a mobile network',
thing='a mobile network',
choices=[
('live-test', 'All networks'),
('', 'A single network'),
]
)
network = OptionalServiceBroadcastAccountTypeField(
'Choose a mobile network',
thing='a mobile network',
choices=[
('live-test-ee', 'EE'),
('live-test-o2', 'O2'),
('live-test-vodafone', 'Vodafone'),
('live-test-three', 'Three'),
],
)
def validate_network(self, field):
if not self.network_variant.data and not field.data:
raise ValidationError('Select a mobile network')
if self.network_variant.data == 'all':
field.data = ''
class ServiceBroadcastAccountTypeForm(StripWhitespaceForm):
account_type = ServiceBroadcastAccountTypeField(
'Change cell broadcast service type',
@@ -2349,6 +2399,7 @@ class ServiceBroadcastAccountTypeForm(StripWhitespaceForm):
("live-test-vodafone", "Test channel (Vodafone)"),
("live-test", "Test channel (all networks)"),
("live-severe", "Live (all networks)"),
("live-government", "Government channel (all networks)"),
],
validators=[DataRequired()]
)

View File

@@ -46,6 +46,8 @@ from app.main.forms import (
RenameServiceForm,
SearchByNameForm,
ServiceBroadcastAccountTypeForm,
ServiceBroadcastChannelForm,
ServiceBroadcastNetworkForm,
ServiceContactDetailsForm,
ServiceDataRetentionEditForm,
ServiceDataRetentionForm,
@@ -318,15 +320,79 @@ def service_set_permission(service_id, permission):
@main.route("/services/<uuid:service_id>/service-settings/broadcasts", methods=["GET", "POST"])
@user_is_platform_admin
def service_set_broadcast_account_type(service_id):
form = ServiceBroadcastAccountTypeForm(
account_type=(
def service_set_broadcast_channel(service_id):
form = ServiceBroadcastChannelForm(
channel=(
current_service.live,
current_service.broadcast_channel,
current_service.allowed_broadcast_provider
'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):
if current_service.allowed_broadcast_provider == 'all':
form = ServiceBroadcastNetworkForm(
network_variant=(
current_service.live,
current_service.broadcast_channel,
current_service.allowed_broadcast_provider,
),
)
else:
form = ServiceBroadcastNetworkForm(
network_variant='',
network=(
current_service.live,
current_service.broadcast_channel,
current_service.allowed_broadcast_provider
)
)
if form.validate_on_submit():
return redirect(url_for(
'.service_confirm_broadcast_account_type',
service_id=current_service.id,
account_type=form.network_variant.data or form.network.data,
))
return render_template(
'views/service-settings/service-set-broadcast-network.html',
form=form,
)
@main.route(
"/services/<uuid:service_id>/service-settings/broadcasts/<account_type>",
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 +407,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,
)