Commit Graph

3374 Commits

Author SHA1 Message Date
Chris Hill-Scott
04c0c6422f Merge pull request #3568 from alphagov/fix-live-search-broadcast
Fix live search when selecting broadcast sub areas
2020-08-14 10:25:34 +01:00
Chris Hill-Scott
1c74d0798a Add singular descriptions for libraries
This lets us write nice interface copy like ‘Choose a local authority
from the local authorities library’.
2020-08-13 17:54:46 +01:00
Chris Hill-Scott
72f5dcb91f Remove the counties and unitary authorities library
It’s been superceded by the ‘Local’ library (formerly ‘Electoral wards
in the United Kingdom’).

The latter is better because:
- it’s covers all 4 nations, not just England and Wales
- it has electoral wards as well as local authorities which group them,
  so there’s more flexibility when choosing an area to broadcast to
2020-08-13 17:54:37 +01:00
Chris Hill-Scott
be16c0187f Rename electoral wards to local areas
We’ve observed people using ‘national’ and ‘local’ during user research.
It has less tongue-twisting ambiguity than county vs country.

But we think that maybe just getting rid of ‘counties’ is enough to
disambiguate them. So this commit just takes the ‘local’ concept.

This commit also gives the libraries and areas new IDs, which means if
we want to rename them in the future it won’t be a breaking change.
2020-08-13 17:54:28 +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
Chris Hill-Scott
8ef1e98745 Remove ‘Regions of England’ library
It made for a good early demo to show how we could have different
libraries, but we’d don’t think there’s a strong user need for being
able to broadcast to a region of England.

Regions also have the problem that:
- they are ambiguous – both England and Scotland have a region called
  ‘South east’
- Northern Ireland doesn’t have formal regions

This commit removes the regions library.
2020-08-12 18:03:50 +01:00
Chris Hill-Scott
4242078885 Always show 4 items in the example list
If a library has lots of items then the first 3 should be shown, with
a count of how many more there are, for a total of 4 list items:
> a, b, c, and 23 more

If the library only has 4 items then all 4 should be shown, with
consistent use of conjunction and Oxford comma[1]:
> a, b, c, and d

This keeps the lengths of the examples nice and consistent.

1. We use an Oxford comma because it helps disambiguate when an area
itself has a comma or ‘and’ in it, for example ‘Armagh City, Banbridge
and Craigavon’
2020-08-12 16:34:17 +01:00
Chris Hill-Scott
dfa2ae0ced Order areas by name in examples
When you click through to the page for a library you see the available
areas in alphabetical order. The examples given for each library should
match this.
2020-08-12 16:34:17 +01:00
Chris Hill-Scott
53fd5b8869 Exclude grouped areas from examples
The given examples should match the choices offered when you visit the
next page. The choices offered on the next page are either the areas
(when a library is not grouped) or the groups (when a library is
grouped).

This commit makes the examples match the choices by excluding sub-areas,
ie those that have a grouping ID.
2020-08-12 16:34:17 +01:00
Chris Hill-Scott
40dacdeac9 Fix live search when selecting broadcast sub areas
It was targeting the wrong element because it hadn’t been updated to
reflect that we’re now using the Design System checkboxes.
2020-08-12 16:33:00 +01:00
Chris Hill-Scott
781847d32c Merge pull request #3557 from alphagov/view-only-broadcast-page
Let users without `send_messages` view broadcasts
2020-08-12 15:16:39 +01:00
Chris Hill-Scott
e47dbc0caa Add tests to check permission-restricted broadcast pages
Some pages should only be shown to users who have permission to send or
approve broadcasts. This commit adds a test to ensure that this is true,
and that we don’t accidentally regress the checks for this permission.
2020-08-12 08:19:51 +01:00
Chris Hill-Scott
78c88530b5 Let users without send_messages view broadcasts
At the moment viewing a broadcast is limited to those users who have
the `send_messages` permission.

This doesn’t match how we describe the permissions on the team members
page

This commit makes it so that any team member can see a broadcast that’s
in any state other than `draft`.
2020-08-12 08:19:49 +01:00
Chris Hill-Scott
8570901731 Let users select electoral wards of local authorities
If a library has groups, we should show a link instead of selecting the
group directly.

Then we can give the user the choice of selecting the whole of that
group, or specific areas within the group.

For now the only libraries we have with groups are local authorities,
which group electoral wards.
2020-08-11 17:38:15 +01:00
Chris Hill-Scott
0ce64bcfde Merge pull request #3553 from alphagov/move-broadcast-areas-into-admin
Move broadcast areas into admin
2020-08-11 13:25:21 +01:00
Toby Lorne
b0ff2d41c5 broadcast-areas: examples are deterministic
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-11 12:04:02 +01:00
Chris Hill-Scott
b0fc1cd271 Make test name more explicit 2020-08-11 11:22:59 +01:00
Toby Lorne
73e68c355b broadcast-areas: include electoral wards
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 18:09:15 +01:00
Toby Lorne
6649d0ac70 broadcast-areas: use area ids in tests
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 18:09:15 +01:00
Chris Hill-Scott
834b0fc3d5 Put hidden email field on register from invite page
Password managers will try to guess what they should save as a username
by looking at the fields on the page where you set up your password.

When registering from an invite the email address (what we use as a
username) is predefined, and only shown on the page as text, not an
input.

This commit also adds a hidden input field for password managers to pick
up.

Adapted from: https://github.com/UKGovernmentBEIS/beis-opss-psd/blob/master/app/views/users/complete_registration.html.erb#L29-L36
2020-08-10 15:59:27 +01:00
Toby Lorne
8c3a8ecd04 broadcast-areas: view test does not assert order
the descriptions are liable to change esp for wards

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 13:04:03 +01:00
Toby Lorne
7a1b80e533 broadcast-areas: sort imports
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:22 +01:00
Toby Lorne
488a5440cd broadcast-areas: move broadcast areas into app
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:20 +01:00
Toby Lorne
b7e6b94e87 broadcast-areas: and in get_examples
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:18 +01:00
Toby Lorne
01ffc815e7 broadcast-areas: do not use group table
do not need it

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:18 +01:00
Toby Lorne
8ecbfe5996 broadcast-areas: package works with groups
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:18 +01:00
Toby Lorne
7074655b84 broadcast-areas: BroadcastAreaLibraries uses sql
sqlite

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:18 +01:00
Toby Lorne
15d4d3c0a1 broadcast-areas: initial repository class
repository to represent the sqlite broadcast areas db

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-08-10 12:50:18 +01:00
Leo Hemsted
b3ed21252d ensure you can get broadcast_areas from a list as well as from *args 2020-08-10 12:50:17 +01:00
Chris Hill-Scott
078f1dd8d3 Add broadcast area model, loading from GeoJSON
This commit adds a new model class which can be used by any app to
interact with a broadcast area. A broadcast area is one or more polygons
representing geographical areas.

It also adds some models that make browsing collections of these areas
more straightforward. So the hierarchy looks like:

> **BroadcastAreaLibraries*
> Contains multiple libraries of broadcast area
> > **BroadcastAreaLibrary**
> > A collection of geographic areas, all of the same type, for example
> > counties or electoral wards
> > **BroadcastArea**
> > Contains one or more shapes that make up an area, for example
> > England
> > > **BroadcastArea.polygons[n]**
> > > A single shape, for example the Isle of Wight or Lindisfarne
> > > > **BroadcastArea.polygons[n][o]**
> > > > A single coordinate along a polygons

The classes support iteration, so all the areas in a library can be
looped over, for example if `countries` is an instance of
`BroadcastAreaLibrary` you can do:
```python
for country in countries:
    print(country.name)
```

The `BroadcastAreaLibraries` class also provides some useful methods for
quickly getting the polygons for an area or areas, for example to
render them on a map. So if `libraries` is an instance of
`BroadcastAreaLibraries` you can do:
```python
libraries.get_polygons_for_areas_long_lat('england', 'wales')
```

This will give polygons for the Welsh mainland, the Isle of Wight,
Anglesey, etc.

The models load data from GeoJSON files, which is an open standard for
serialising geographic data. I’ve added a few example files taken from
http://geoportal.statistics.gov.uk to show how it works.
2020-08-10 12:50:17 +01:00
Chris Hill-Scott
3573ce1437 Merge pull request #3550 from alphagov/fix-html-escaping-email-subject-preview
Fix HTML being escaped in preview of email subject
2020-08-10 08:59:44 +01:00
Chris Hill-Scott
0e99bede68 Merge pull request #3552 from alphagov/cant-self-approve
Don’t let users self-approve broadcasts
2020-08-06 14:04:07 +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
Tom Byers
cd398ab55c Merge pull request #3543 from alphagov/remove-code-supporting-old-permissions-form_fields
Revert support for old user permissions params
2020-08-05 15:51:28 +01:00
Chris Hill-Scott
b31fb7de66 Merge pull request #3546 from alphagov/redis-cache-broadcast-message
Cache broadcast messages in Redis
2020-08-04 16:17:21 +01:00
Chris Hill-Scott
4d65b94c77 Fix HTML being escaped in preview of email subject
`EmailPreviewTemplate.subject` returns a string of HTML, with any
user-submitted HTML already escaped:
b5a61bfb7b/notifications_utils/template.py (L672)

What won’t be escaped is the HTML needed to redact the placeholders. We
generate this HTML so we know its safe, and doesn’t need to be escaped.
However when we pass it to Jinja, Jinja doesn’t know this, so will try
to escape it. This means users will see the raw HTML.

We can get around this by using Flask’s `Markup` class to tell Jinja
that the string is already sanitised and doesn’t need escaping again.

Text message templates don’t have this problem because they already
return `Markup`: b5a61bfb7b/notifications_utils/template.py (L288)

Letter templates don’t suffer from this problem (because they don’t
support redaction) but without making the same change they would still
double-escape ampersands, greater-than symbols, and so on.
2020-08-04 15:16:18 +01:00
Tom Byers
a74501f1d8 Merge pull request #3535 from alphagov/try-introducing-govuk-checkboxes-again
Try introducing govuk checkboxes again
2020-08-04 14:39:54 +01:00
Chris Hill-Scott
63095f7a6c Merge pull request #3536 from alphagov/guest-list-endpoint
Use new guest list API URLs
2020-08-04 11:40:42 +01:00
Chris Hill-Scott
3faf92bfef Go to broadcast, not dashboard after submitting
Once you’ve created a broadcast you’re taken back to the dashboard. This
feels too passive, and you might miss that the broadcast still needs
approval.

We should be much more explicit that you now need to find someone to
approve your broadcast. Taking someone directly to the page for a
broadcast lets us give more information about the status of the
broadcast and what the next steps should be.
2020-08-03 15:46:23 +01:00
Chris Hill-Scott
47a5c2abba Merge pull request #3540 from alphagov/search-whole-postal-address
Tell users that they can search whole postal address
2020-08-03 14:47:58 +01:00
Chris Hill-Scott
19b42e3331 Add a tour for users new to broadcast services
This is an initial, prototype-quality attempt at introducing some kind
of tour for users new to broadcasting. A lot of the users we’re speaking
to don’t have a good concept of what broadcasting means, which is
causing usability problems down the line.

We did a similar thing in the early days of Notify to explain the
concept of message templates and personalisation.
2020-08-03 14:13:48 +01:00
Chris Hill-Scott
058553b6ee Cache broadcast messages in Redis
This should make the pages slightly quicker to load, because Redis will
return the JSON string faster than the API.

The only change that can happen to a broadcast which doesn’t go through
the admin app is a broadcast ending at its scheduled time. So this could
result in a cached broadcast having a status of `broadcasting` when it
had in fact finished. We already account for this here though:
b2b58ec044/app/models/broadcast_message.py (L89-L94)
2020-08-03 11:38:10 +01:00
Tom Byers
468a43bd68 Revert support for old user permissions params
The fields used for user permissions on
permissions forms were changed as part of the work
converting the checkboxes to GOVUK Frontend.

This removes code added to protect against a
situation where the server-side app was running
this updated code but clients were POSTing from
pages that were not, and so sending the old HTTP
params.
2020-07-31 15:40:12 +01:00
Tom Byers
e3c434bb8f Change permissions tests to support old API
User permissions were handled by a group of
BooleanFields but introducing the new checkboxes
changed this to just one field that stores its
data in a list.

It was mentioned in a comment that there could be
a situation, when the instances roll, where clients
are using the old fields but POSTing to a server
running the new code.

https://github.com/alphagov/notifications-admin/pull/3535#discussion_r460872903

This introduces tests for that situation.
2020-07-31 15:15:26 +01:00
Tom Byers
f322229614 Change tests to check permissions_field name
A comment on this group of changes mentioned the
'name' attribute of checkboxes for the
permissions_field should be checked as well as the
'value' attribute:

https://github.com/alphagov/notifications-admin/pull/3535#discussion_r460869797

This adds checks to support that point.
2020-07-31 15:15:16 +01:00
Tom Byers
e266b11ee2 Fix tests for pages using govukCheckboxField
These fields used to use govukCheckboxesField and
so stored their data in a list. They were since
migrated to govukCheckboxField, which extends
BooleanField and so keeps its data as a boolean
value.
2020-07-31 10:20:44 +01:00
Katie Smith
ba5f7d7c36 Check for invalid chars in letter addresses
This now adds validation for invalid characters on the
LetterAddressForm for one off letters. It also adds a validation failed
message for uploaded letters, precompiled letters sent through the API,
and CSV rows with errors.
2020-07-31 08:51:07 +01:00
Chris Hill-Scott
3fbf966719 Display full address on the notifications page
This is what we do on the uploads page now. It makes it more obvious
why your search term has returned a certain result if you can see most
of the address, not just the first line.
2020-07-30 16:40:25 +01:00
Chris Hill-Scott
2789b6a596 Tell users that they can search whole postal address
We’re now normalising and storing the whole address in the
`normalised_to` field. Previously we were only storing the first line
of the address.

Enough time should now have passed that the field will have been
populated for all letters in the database.

Thus we can now tell users that it’s not just the first line they can
search by.
2020-07-30 16:20:19 +01:00
Chris Hill-Scott
e0cb487093 Use new guest list API URLs
The API now[1] accepts requests on `…/guest-list` as well as
`…/whitelist`. This commit starts using the former, which means:
- the use of ‘whitelist’ is fully gone from the admin app
- the API can stop using it, at least in URLs

1. As of https://github.com/alphagov/notifications-api/pull/2928
2020-07-27 13:24:37 +01:00