Commit Graph

299 Commits

Author SHA1 Message Date
Chris Hill-Scott
e2e04b51fc Sort broadcasts by start time
For emails and text messages we sort by the time the user (or API) sent
them.

This makes sense for broadcasts too, since most users will receive the
alert within seconds of it being broadcast.

For alerts that haven’t started yet we can sort by `updated_at`, which
is when the user preparing the broadcast submitted it for approval.
2020-10-27 13:12:46 +00:00
Chris Hill-Scott
57fc209f44 Merge pull request #3690 from alphagov/set-message-limit
Remove the `upload_letters` permission
2020-10-23 12:27:28 +01:00
Chris Hill-Scott
43b4acf1f9 Allow platform admins to change rate limit
One less thing we have to go into the database to do, and remember to
manually clear the cache for after.
2020-10-23 12:05:45 +01:00
Chris Hill-Scott
f549168b5e Remove the upload_letters permission
Every service has it now, and we haven’t had any services ask to toggle
it off again.
2020-10-20 11:30:08 +01:00
Chris Hill-Scott
e2f16e414d Style areas on dashboard the same as alert preview
Our style for areas is pale blue background with black keylines or bold
black text.

This commit makes the display of area names on the dashboard consistent
with that visual style.

This also means that we’re not truncating the list of areas, which is
appropriate because no one area is more important than any of the
others.
2020-10-14 13:22:00 +01:00
Chris Hill-Scott
5c9a886edc Preview content as hint for broadcast templates
Broadcast services only have broadcast templates. But we show the
template type under the name of the template. This is redundant. It
would be better to preview the content of the template instead.

This then makes the templates page consistent with the dashboard.

Depends on:
- [ ] https://github.com/alphagov/notifications-api/pull/2996
2020-10-14 13:21:19 +01:00
Chris Hill-Scott
850571cb8c Recognise that broadcast messages include content
The content attribute needs to be added to the model so we can use it
later.
2020-10-09 15:41:38 +01:00
Chris Hill-Scott
fad63117d6 Merge pull request #3658 from alphagov/use-scheduled-job-stats
Use new API endpoint for scheduled job stats
2020-10-06 12:00:38 +01:00
Chris Hill-Scott
5c2469b24e Refactor to use shared date comparison function
This means we don’t have to repeatedly do timezone conversions or string
to datetime conversions in our business logic.
2020-09-29 13:38:00 +01:00
Chris Hill-Scott
86ec9430a2 Fix incorrect processing started time on jobs
We were doing the UTC to BST conversion twice, meaning the job was shown
as being started 2 hours later than UTC, and 1 hour later than actual
BST.
2020-09-28 14:53:42 +01:00
Chris Hill-Scott
ef6681b69b Use new API endpoint for scheduled job stats
Depends on:
- [ ] https://github.com/alphagov/notifications-api/pull/2984
2020-09-28 14:28:23 +01:00
Leo Hemsted
626b1c4211 enable broadcast org in all environments
This organisation is defined in the config file. It's hard coded to a
UUID as defined in the api db migration 0331_add_broadcast_org.
2020-09-25 13:42:13 +01:00
Chris Hill-Scott
eb4a7907a4 Make estimated phone count clearer
We’ve had some feedback from user research that difference between
‘will get alert’ and ‘likely to get alert’ is not clear, and it’s hard
to tell if the latter is inclusive of the former. This leads people to
question the validity of these numbers, which is important, because an
the estimate should give you some idea of the impact of what you’re
about to do.

This commit reformats the number as a range, for example 1,000 to 2,000
phones.

If the range is small, eg 40,000,000 to 40,800,000 then this suggests
a false level of accuracy. So instead we just give one number and say
it’s an estimate, eg ‘40,000,000 phones estimated’
2020-09-24 15:53:07 +01:00
Leo Hemsted
c7ef7d5083 Merge pull request #3643 from alphagov/broadcast-org
move service to broadcast org when broadcasting is enabled
2020-09-24 13:13:34 +01:00
Leo Hemsted
93d1137474 move service to broadcast org when broadcasting is enabled
we want to keep track of all broadcast services across govt easily. As
such, when broadcasting is enabled for a service, we've decided we're
going to add the service to a special broadcasting organisation.

This organisation is defined in the config file. It's hard coded for
production, if you want to test locally, you should set
BROADCAST_ORGANISATION_ID in your local environment.
2020-09-22 18:18:00 +01:00
Chris Hill-Scott
f50ef84c0d Suggest previously-used areas when adding new area
If you’re adding another area to your broadcast it’s likely to be close
to one of the areas you’ve already added.

But we make you start by choosing a library, then you have to find the
local authority again from the long list. This is clunky, and it
interrupts the task the user is trying to complete.

We thought about redirecting you somewhere deep into the hierarchy,
perhaps by sending you to either:
- the parent of the last area you’d chosen
- the common ancestor of all the areas you’d chosen

This approach would however mean you’d need a way to navigate back up
the hierarchy if we’d dropped you in the wrong place. And we don’t have
a pattern for that at the moment.

So instead this commit adds some ‘shortcuts’ to the chose library page,
giving you a choice of all the parents of the areas you’ve currently
selected. In most cases this will be one (unitary authority) or two
(county and district) choices, but it will scale to adding areas from
multiple different authorities.

It does mean an extra click compared to the redirect approach, but this
is still fewer, easier clicks compared to now.

This meant a couple of under-the-hood changes:
- making `BroadcastArea`s hashable so it’s possible to do
  `set([BroadcastArea(…), BroadcastArea(…), BroadcastArea(…)])`
- making `BroadcastArea`s aware of which library they live in, so we can
  link to the correct _Choose area_ page
2020-09-22 17:33:04 +01:00
Chris Hill-Scott
ba9f786971 Move round_to_significant_figures into utils 2020-09-17 11:03:14 +01:00
Chris Hill-Scott
76244d8c07 Handle areas with missing data
At the moment there are some areas which have:
- a `count_of_phones` value of `None`
- no sub-areas

This is wrong, but until we fix the data the phone counting code needs
to handle this.

This commit:
- adds the `or 0` in the right place (where it will catch these areas
  with missing data)
- adds a test which checks these areas, and compares them to other kinds
  of areas
2020-09-17 11:02:22 +01:00
Chris Hill-Scott
6b7908fecb Don’t use single letter variable names
Better to call the variables what they are.

Also re-orders the statement to avoid adding to a negative number.
2020-09-16 08:46:59 +01:00
Chris Hill-Scott
8ea3f0141c Give estimates of the number of phones in a broadcast area
We need to give people a better feel for the consequences of
broadcasting an alert. We’ve seen in research that some users will
assume it is subscription based, or opt-in, rather than going to every
phone in the area.

I reckon that the most effective way to communicate this is to put some
numbers next to the areas, to give people an idea of how many people
will get alerted.

We can estimate how many phones are in an area by:
- taking the population of all electoral wards in that area
- multiplying it by the percentage of people who own an internet
  connected phone[1]

The Office for National Statistics publish both these datasets.

The number of people who own an intenet connected phone varies a lot by
age. Since the population data for each ward is broken down by age we
can factor this in. Simplified, the calculation looks like this:
- take the _Abbey_ ward of _Barking and Dagenham_
- in this ward there are 26 people aged 80
- 40% of people over 65 have an internet-connected phone
- therefore 10 of these 80-year-olds would be likely to receive a
  broadcast
- (repeat for all other ages)

These numbers won’t be exact, but should be enough to give people a feel
for the severity of what they’re about to do. We can see if they acheive
this aim in user research.

1. This is a proxy for the number of people who are likely to have a 4G
   capable phone, because only 4G capable phones will be receiving
   broadcasts to begin with
2020-09-14 16:26:09 +01:00
Pea Tyczynska
3bfe3a2bf7 Send simple polygons to API along with areas
When creating broadcast message, or updating it.
We want to send simple polygons to API so we can
later relay them to the broadcast provider.

Test that update broadcast message sends polygons correctly
2020-09-04 16:55:02 +01:00
Chris Hill-Scott
3d9d663b27 Refactor coordinate processing into Polygons class
We have a bunch of stuff for doing lat/long transformation in the
`BroadcastMessage` class. This is not a good separation of concerns, now
that we have a separate class for dealing with polygons and coordinates.
2020-08-26 09:17:03 +01:00
Chris Hill-Scott
c49a6338af Store simplifed polygons in the SQLite database
This commit does two things:
- uses our new polygon-simplifying library to process the polygons
  before storing them, rather than processing them in real time
- stores only the polygons in the database, rather than the whole
  GeoJSON feature, because we don’t need any of the other information
  about the feature
2020-08-26 09:09:45 +01:00
Chris Hill-Scott
3470c5bb31 Make simplification of polygons more sophisticated
Simplifying polygons means reducing the number of points used to render
them. This commit implements simplification such that, for any given
input polygons, the combined point count of the simplified polygons is
less than 100.

When simplifying the polygons we are trying to get the smallest number
of points while meeting these two rules:
1. No part of the area the user has chosen can be cut off
2. The area of the simplified polygon should be as small as possible

This commit introduces two techniques we weren’t using before:
1. Dilating and eroding the area to fill in concave details of the
   shape, like inlets and harbours[1]
2. Making the simplification threshold proportionate to the perimeter of
   all polygons, so bigger and crinklier polygons get more
   simplification applied

It also shows the estimated bleed as a separate polygon. This lets us
make it bigger (so it’s more closer the the approximate bleed) without
having to send a bigger area to the CBC and compounding the amount of
actual bleed.

1. Inspired by this blog post about ‘removing the crinkley bits’ from
   Vancouver Island:
   http://blog.cleverelephant.ca/2010/11/removing-complexities.html
2020-08-26 09:04:54 +01:00
Chris Hill-Scott
283393024d Fix pages which assume broadcasts have a finish time
They no longer have a finish time until they have been approved.
Previously it was the person preparing the broadcast who chose when it
should finish.
2020-08-19 15:10:44 +01:00
Chris Hill-Scott
1acc3b55eb Merge pull request #3581 from alphagov/remove-end-time
Remove choice of ‘End time’ from broadcast journey
2020-08-19 14:30:22 +01:00
Chris Hill-Scott
da8321863d Remove choice of ‘End time’ from broadcast journey
Since we added the end time picker:
- we have discovered that broadcasts can’t be longer than 24h
- we have observed that most users confuse picking the end time for
  scheduling the message, or don’t understand exactly what it means for
  the broadcast to ‘end’
- we’ve developed the concept of ‘training mode’, which you should be
  going through before sending a real broadcast

We also think that, for most scenarios, you won’t necessarily know when
a broadcast should end at the time of starting it because the cause of
the danger is not within your control. So giving you control of the
end time before the broadcast has even been approved is a confusing
distraction.

Having to pick a time at all also makes the whole process feel more
planned and less immediate. Whereas in reality all the phones in the
area will be getting the message in seconds. It’s only people coming
into the area later to whom the ‘ongoing’ aspect of the broadcast
applies.

The best place to explain what’s happening with the phones is at the
approval stage and once you’ve sent your first (training mode)
broadcast. It’s easier to explain what’s happened if it’s in direct
response to something you’ve just done.

Later on we should add some kind of email reminder after 12 hours to
make sure you still want the broadcast live, again after 18 hours, etc.

We could let you schedule an end time once the broadcast is live, but
don’t think there’s a strong need. Knowing enough that you want to
cancel is one thing, but knowing enough to want to cancel but wanting to
wait a bit… nah.
2020-08-19 11:05:13 +01:00
Katie Smith
895a9df55a Add confirmation banner when cancelling user invites
This shows the green banner with a tick when cancelling a user's
invitation to a service or organisation. The accessibility audit noted
that 'When cancelling an invite a new page loads, however, there is no
immediate indication that the invite has been cancelled.'

In order to display the invited user's email address as part of the
flash message, this adds new methods to the api clients for invites to get
a single invite.
2020-08-19 09:05:41 +01:00
Chris Hill-Scott
969e7a6dbd Show how a broadcast will overspill selected area
Broadcasting is not a precise technology, because:
- cell towers are directional
- their range varies depending on whether they are 2, 3, 4, or 5G
  (the higher the bandwidth the shorter the range)
- in urban areas the towers are more densely packed, so a phone is
  likely to have a greater choice of tower to connect to, and will
  favour a closer one (which has a stronger signal)
- topography and even weather can affect the range of a tower

So it’s good for us to visually indicate that the broadcast is not as
precise as the boundaries of the area, because it gives the person
sending the message an indication of how the technology works.

At the same time we have a restriction on the number of polygons we
think and area can have, so we’ve done some work to make versions of
polygons which are simplified and buffered (see
https://github.com/alphagov/notifications-utils/pull/769 for context).

Serendipitously, the simplified and buffered polygons are larger and
smoother than the detailed polygons we’ve got from the GeoJSON files. So
they naturally give the impression of covering an area which is wider
and less precise.

So this commit takes those simple polygons and uses them to render the
blue fill. This makes the blue fill extend outside the black stroke,
which is still using the detailed polygons direct from the GeoJSON.
2020-08-13 11:20:49 +01:00
Toby Lorne
698e9816ec models: use broadcast areas from admin package
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:22 +01:00
Chris Hill-Scott
479406c02d Don’t let users self-approve broadcasts
At the moment they will get a ‘technical difficulties’ error if they
try.

We probably want to do something around letting people self-approve
broadcasts in trial mode, but for now just telling them they can’t is a
better experience than ‘technical difficulties’ (and will probably be
close to what they should see on a live service as well).
2020-08-05 16:01:21 +01:00
Chris Hill-Scott
4f859a69a6 Merge pull request #3527 from alphagov/broadcast-end-time
Let users choose when to end a broadcast
2020-07-17 10:43:10 +01:00
Chris Hill-Scott
2d7d800c64 Merge pull request #3528 from alphagov/fix-set-broadcast-permission
Fix setting of broadcast permission
2020-07-17 10:40:26 +01:00
Chris Hill-Scott
83156bd16e Let users choose when to end a broadcast
Different emergencies will need broadcasts to last for a variable amount
of time. We give users some control over this by letting them stop a
broadcast early. But we should also let them set a maximum broadcast
time, for:
- when the duration of the danger is known
- when the broadcast has been live long enough to alert everyone who
  needs to know about it

This code re-uses the pattern for scheduling jobs, which has some
constraints that are probably OK for now:
- end time is limited to an hour
- longest duration is 3 whole days (eg if you start broadcasting Friday
  you have the choice of Saturday, Sunday and all of Monday, up to
  midnight)
2020-07-17 08:23:10 +01:00
Chris Hill-Scott
03b4aabf5f Add a link to reject a broadcast
If a broadcast definitely shouldn’t go out (for example because it has a
spelling mistake or is going to the wrong areas) then we should have a
way of removing it. Once it’s removed no-one else can approve it, and it
isn’t cluttering up the dashboard.

This is a link (because it’s a secondary action) and red (because it’s
destructive, in that it’s throwing away someone’s work).
2020-07-17 08:07:44 +01:00
Chris Hill-Scott
a99b40304b Add button to approve broadcast
Since new broadcasts will go into `pending-approval`, we now need a way
of approving them.

This commit adds a button to this page to start (or approve) the
broadcast. This button is wrapped in a bordered box, to emphasise that
it’s something consequential.
2020-07-17 08:07:44 +01:00
Chris Hill-Scott
5b83db9768 Don’t start broadcasts immediately
We don’t want one person going full yolo and start broadcasting without
any oversight. This commit changes the flow so that the button on the
‘preview’ page puts the broadcast into `pending-approval`, rather than
directly into `broadcasting`.
2020-07-17 08:07:43 +01:00
Chris Hill-Scott
4b1e3ec504 Refactor broadcast message model
There was a lot of duplicate code here for updating the status and other
properties of a broadcast.

This commit abstracts them into reusable methods. They’re named with an
underscore to suggest that they shouldn’t be used externally.
2020-07-17 08:07:42 +01:00
Chris Hill-Scott
e29a477eb1 Fix setting of broadcast permission
This was broken because current_service doesn’t update itself after
calling the `update` method of the API. So we thought we were changing
the permissions like this:
```
{'email', 'sms', 'letter'}
{'email', 'sms', 'letter', 'broadcast'}
{'sms', 'letter', 'broadcast'}
{'letter', 'broadcast'}
{'broadcast'}
```

But actually we were doing this:
```
{'email', 'sms', 'letter'}
{'email', 'sms', 'letter', 'broadcast'}
{'sms', 'letter'}
{'email', 'letter'}
{'email', 'sms'}
```

This commit changes the code to update the permissions like this:
```
{'email', 'sms', 'letter'}
{'broadcast'}
```

It does so by adding a new method to the service model which changes all
the permissions in one API call, and updates the tests to mock the
underlying API call, not the method on the model.
2020-07-16 19:44:20 +01:00
Chris Hill-Scott
414e4b5834 Merge pull request #3520 from alphagov/broadcast-user-permissions
Make user permissions make sense for services with the broadcast permission
2020-07-16 14:59:57 +01:00
Chris Hill-Scott
72c1b3d8a1 Only show relevant user permissions for broadcast services
For services with the broadcast permission this hides:
- the ‘View dashboard’ permission (and defaults it to _checked_) because
  all users of broadcast services will need to see the dashboard
- the ‘Manage API keys’ permission (and defaults it to _not checked_)
  because we don’t offer an API integration for broadcast services yet
  – if we do we won’t want existing users to automatically get the
  permission

It relabels:
- the ‘Send’ permission to ‘Prepare and approve’ to match the current,
  slightly clunky language on the templates page
- the ‘Manage settings’ label to not refer to ‘usage’ because broadcast
  services won’t incur cost
2020-07-14 09:45:42 +01:00
Chris Hill-Scott
7d6dffc098 Add a page to view a single broadcast
This commit adds a page to view a single broadcast. This is important
for two reasons:
- users need an audit of what happened when, and who else was involved
  in approving or cancelling a broadcast
- we need a place to put actions (approving, cancelling) on a broadcast
  so that you can confirm details of the message and the areas before
  performing the action
2020-07-10 15:55:05 +01:00
Chris Hill-Scott
3136d1a33b Implement sorting
Shows the broadcasts with the longest time still to live at the top. At
the moment this will be the same as the newest broadcasts, so we may
want to revisit this sort order when we have broadcasts of variable
duration.

For no-longer-live broadcasts we show the most-recently-finished at the
top, whether it finished naturally or was cancelled.
2020-07-10 09:57:06 +01:00
Chris Hill-Scott
44e177b402 Allow broadcasts to be cancelled
Currently this is a `get` request from the dashboard. Once we have a page
for viewing an individual broadcast it should probably show there
instead and be a `get`/confirm/`post` loop like for deleting a template.
2020-07-10 09:57:06 +01:00
Chris Hill-Scott
6b822f9fde Add broadcasts to the dashboard
Shows current and previous broadcasts. Does not add a page for viewing
an individual broadcast.

Broadcasts are split into live and previous.

Draft broadcasts are excluded from the dashboard.
2020-07-09 16:32:15 +01:00
Chris Hill-Scott
effe24893e Make the broadcast flow talk to the API
This commit removes the code the puts areas into the session and instead
creates and then updates a draft broadcast in the database.

This is so we can avoid session-related bugs, and potentially having a
large session when we start adding personalisation etc.

Once a broadcast is ready to go it is set to `broadcasting` straight
away with no approval. We’ll revisit this as we learn more about how
users might want to manage who can create and approve broadcasts.

The tests are a bit light in terms of checking what’s on the page, but
clicking through the pages is probably good enough for now.
2020-07-09 14:31:12 +01:00
Chris Hill-Scott
c4458efa21 Bump utils to 40.2.1
Brings in:
- re-usable `SerialisedModel`
- speed improvements to processing CSVs against email templates

I chose not to rename `JSONModel` or `ModelList` to keep the diff nice
and small.
2020-07-06 09:39:54 +01:00
Chris Hill-Scott
01ec2ad9c7 Add template type hint on choose page 2020-07-03 15:47:29 +01:00
Chris Hill-Scott
154d4bdb85 Allow adding broadcast templates
At the moment the page is the same as for text message templates,
except:
- different H1
- no guidance about personalisation, links, etc (until we decide how
  these should work)

For now you won’t be able to really create a broadcast template, because
the API doesn’t support it (the API will respond with a 400). But that’s
OK because no real services have the broadcast permission yet.

This required a bit of refactoring of how we check which template types
a service can use, because there were some hard-coded assumptions about
emails and text messages.
2020-07-01 17:17:46 +01:00
Leo Hemsted
8b3aa43101 add broadcast service permission 2020-06-30 13:06:26 +01:00