Add a confirmation checkbox for live broadcasts

We want people to be really sure before sending a live broadcast, not
just clicking through the green buttons.

This commit adds a checkbox which explains exactly the consequences of
what they’re about to do, tailored to the channel they’re on, and the
area chosen by the person creating the alert.
This commit is contained in:
Chris Hill-Scott
2021-05-12 13:26:13 +01:00
parent 773a51dec1
commit 7d66dadcd7
4 changed files with 196 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import math
import weakref
from datetime import datetime, timedelta
from itertools import chain
@@ -1288,6 +1289,50 @@ class NewBroadcastForm(StripWhitespaceForm):
return self.content.data == 'template'
class ConfirmBroadcastForm(StripWhitespaceForm):
def __init__(self, *args, service_is_live, channel, max_phones, **kwargs):
super().__init__(*args, **kwargs)
self.confirm.label.text = self.generate_label(channel, max_phones)
if service_is_live:
self.confirm.validators += (DataRequired(),)
confirm = GovukCheckboxField("Confirm")
@staticmethod
def generate_label(channel, max_phones):
if channel == 'test':
return (
'I understand this will alert anyone who has switched '
'on the test channel'
)
if channel == 'severe':
return (
f'I understand this will alert {ConfirmBroadcastForm.format_number_generic(max_phones)} '
'of people'
)
if channel == 'government':
return (
f'I understand this will alert {ConfirmBroadcastForm.format_number_generic(max_phones)} '
'of people, even if theyve opted out'
)
@staticmethod
def format_number_generic(count):
for threshold, message in (
(1_000_000, 'millions'),
(100_000, 'hundreds of thousands'),
(10_000, 'tens of thousands'),
(1_000, 'thousands'),
(100, 'hundreds'),
(-math.inf, 'an unknown number')
):
if count >= threshold:
return message
class BaseTemplateForm(StripWhitespaceForm):
name = GovukTextInputField(
"Template name",

View File

@@ -14,6 +14,7 @@ from app.main.forms import (
BroadcastAreaForm,
BroadcastAreaFormWithSelectAll,
BroadcastTemplateForm,
ConfirmBroadcastForm,
NewBroadcastForm,
SearchByNameForm,
)
@@ -401,6 +402,11 @@ def view_broadcast(service_id, broadcast_message_id):
back_link_endpoint,
service_id=current_service.id,
),
form=ConfirmBroadcastForm(
service_is_live=current_service.live,
channel=current_service.broadcast_channel,
max_phones=broadcast_message.count_of_phones_likely,
),
)
@@ -414,6 +420,12 @@ def approve_broadcast_message(service_id, broadcast_message_id):
service_id=current_service.id,
)
form = ConfirmBroadcastForm(
service_is_live=current_service.live,
channel=current_service.broadcast_channel,
max_phones=broadcast_message.count_of_phones_likely,
)
if broadcast_message.status != 'pending-approval':
return redirect(url_for(
'.view_current_broadcast',
@@ -421,14 +433,15 @@ def approve_broadcast_message(service_id, broadcast_message_id):
broadcast_message_id=broadcast_message.id,
))
broadcast_message.approve_broadcast()
if current_service.trial_mode:
broadcast_message.approve_broadcast()
return redirect(url_for(
'.broadcast_tour',
service_id=current_service.id,
step_index=6,
))
elif form.validate_on_submit():
broadcast_message.approve_broadcast()
return redirect(url_for(
'.view_current_broadcast',