Commit Graph

4060 Commits

Author SHA1 Message Date
Ben Thorner
cfdd244325 Complete migration to new "areas" API format
Depends on: https://github.com/alphagov/notifications-api/pull/3314

Previously:

- We introduced a new "areas_2" API field that's can
populate the "areas" column in the same way.

- We updated the Admin app to use the new field, so that
the old "areas" and "simple_polygons" API fields are unused.

- We repurposed the unused "areas" API field to use
the new "areas_2" format.

This PR:

- We can switch the Admin app back to the "areas" field,
but in the new format.

Future PRs:

- Remove support for the unused "areas_2" field (migration complete)
2021-08-27 14:34:49 +01:00
Ben Thorner
7dbe3afa19 Include area names in data we send to API
These will be used as a fallback for display in gov.uk/alerts. It
also helps to have them in the DB to aid in quickly identifying
where an alert was sent, which is hard from the IDs.

We will look at backfilling names for past alerts in future work.
2021-08-26 12:49:54 +01:00
Ben Thorner
11cbee5843 Switch to using temporary "areas_2" API field
Depends on: https://github.com/alphagov/notifications-api/pull/3312

This is part of a multi-stage migration where we want to repurpose
the "areas" field in the existing API to something like "areas_2".
2021-08-26 11:01:56 +01:00
Ben Thorner
de9d1f991b Stop saying "areas" when we mean "area_ids"
"areas" normally means an instance of BroadcastArea or similar, so
we should be more accurate to avoid confusion.
2021-08-26 11:01:35 +01:00
Ben Thorner
427ac0c8c1 Fix misleading name for overlap method
Resolves: https://github.com/alphagov/notifications-admin/pull/3980#discussion_r692919874

Previously it was unclear what kinds of areas this method returned,
and whether there would be any duplicates (due to the hierarchy of
areas we work with). This clarifies that.

In addition, the areas returned may not overlap with the custom one
[1], so we should reword to avoid falsely implying that. We could do
the overlap check as part of the method as an alternative, but that
would create extra work when calculating the ratio of intersection.
We could always add "overlapping areas" as a complementary method to
this one in future.

[1]: https://github.com/alphagov/notifications-admin/pull/3980#discussion_r692919874
2021-08-23 16:56:47 +01:00
Chris Hill-Scott
5c1920fc20 Remove old method of updating email_access_validated_at
Previously we were passing a flag to the API which handled this. Now
we are doing it at the time of clicking the link, not at the time of
storing the new password. We don’t need to update the timestamp twice,
so this commit removes the code which tells the API to do it.
2021-08-19 11:14:47 +01:00
Chris Hill-Scott
8355abeaf2 Update email_access_validated_at on invite
Accepting an invite means that you’ve just clicked a link in your email
inbox. This shows that you have access to your email.

We can make a record of this, thereby extending the time before we ask
you to revalidate your email address.
2021-08-19 11:14:47 +01:00
Chris Hill-Scott
cb59413581 Update email_access_validated_at on link click
When someone uses a fresh password reset link they have proved that they
have access to their inbox.

At the moment, when revalidating a user’s email address we wait until
after they’ve put in the 2FA code before updating the timestamp which
records when they last validated their email address[1].

We can’t think of a good reason that we need the extra assurance of a
valid 2FA code to assert that the user has access to their email –
they’ve done that just by clicking the link. When the user clicks the
link we already update their failed login count before they 2fa. Think
it makes sense to handle `email_access_validated_at` then too.

As a bonus, the functional tests never go as far as getting a 2FA code
after a password reset[2], so the functional test user never gets its
timestamp updated. This causes the functional tests start failing after
90 days. By moving the update to this point we ensure that the
functional tests will keep passing indefinitely.

1. This code in the API (91542ad33e/app/dao/users_dao.py (L131))
   which is called by this code in the admin app (9ba37249a4/app/utils/login.py (L26))
2. 5837eb01dc/tests/functional/preview_and_dev/test_email_auth.py (L43-L46)
2021-08-19 11:14:47 +01:00
Chris Hill-Scott
ff12ba689d Merge pull request #3993 from alphagov/4-hours-expiry-test-channels
Expire test and operator alerts after 4 hours
2021-08-18 10:12:26 +01:00
Leo Hemsted
71d3aa13d7 follow sign_in redirect even if you're already signed in 2021-08-17 14:44:09 +01:00
Chris Hill-Scott
db0738ac39 Format 1000s properly on returned letters pages
Our style is to comma-separate numbers in the 1000s for easier reading.
2021-08-12 15:51:22 +01:00
Chris Hill-Scott
196da2b1b7 Reduce expiry time to 22 hours 30 minutes
Theoretically the maximum expiry time of a broadcast should be 24 hours.
If it goes over 24 hours there can be problems.

However we want to make it more conservative to mitigate two potential
issues:

1. The CBC has a repetition period (eg 60 seconds) and a count (eg
   1,440). If these were slightly innaccurate or generous it could take
   us over 24 hours. For this reason we should give ourselves half an
   hour of buffer.
2. It’s possibly that the CBC could interpret a UTC time as BST or vice
   versa. Until we’re sure that it’s using UTC everywhere, we need to
   remove another whole hour as buffer.

In total this means we remove 1 hour 30 minutes from 24 hours, giving an
expiry time of 22 hours 30 minutes.
2021-08-10 13:41:03 +01:00
Chris Hill-Scott
8ff7fecf40 Expire test and operator alerts after 4 hours
While testing alerts on these channels the MNOs sometimes need to
restart their CBCs to make sure everything is failing over properly.

If the CBC does not come back up, for whatever reason, then we are left
in a state where the alert can’t be cancelled.

To minimise the impact to the public in this scenario we should keep the
expiry time at 4 hours for alerts sent on test channels. We recently
increased it back up to 24 hours for all channels, so this in effect is
reverting that change for channels that won’t be used in a real
emergency.
2021-08-09 15:15:58 +01:00
Ben Thorner
bb414ee3b9 Merge pull request #3991 from alphagov/update-thanks-page-content
Update content
2021-08-06 16:50:38 +01:00
Chris Hill-Scott
d20bf0aeb4 Merge pull request #3957 from alphagov/make-calculating-overlaps-faster
Make calculating overlapping areas faster
2021-08-06 16:00:00 +01:00
Chris Hill-Scott
5e1b96a3a7 Remove argument unpacking from get_areas
Making it only callable in one way is just less stuff to understand.
2021-08-06 13:28:40 +01:00
Chris Hill-Scott
e7ec77c5bb Make calculating overlapping areas faster
By using the simplified polygons instead of the full resolutions ones
we:
- query less data from SQLite
- pass less data around
- give Shapely a less complicated shape to do its calculations on

This makes it faster to calculate how much of each electoral ward a
custom area overlaps.

For the two areas in our tests:

Place represented by custom area | Before | After
---------------------------------|--------|--------
Bristol                          | 0.07s  | 0.02s
Skye                             | 0.02s  | 0.01s
2021-08-06 13:28:40 +01:00
Ben Thorner
2f2be65465 Fix tests to match content updates 2021-08-06 13:10:31 +01:00
Tom Byers
90fc55a28d Merge pull request #3990 from alphagov/fix-profile-links
Give user profile change links more context
2021-08-06 11:28:19 +01:00
Tom Byers
5e6c1cac38 Fix tests broken by changes 2021-08-05 15:45:57 +01:00
Katie Smith
0f0b8b8ae4 Move back link outside of main where it was used in the page header
The page_header macro includes an optional back link. Since the
page_header is always used inside `<main>`, where the back link should
not be, this stops setting the back link in the page header and instead
sets it in the new `backLink` block.
2021-08-03 11:28:15 +01:00
Pea Tyczynska
af6b1d38b5 Merge pull request #3984 from alphagov/handle-cancel-letter-errors-from-api
Catch cancel_letter errors from API
2021-08-03 11:05:46 +01:00
Chris Hill-Scott
2446e97753 Revert "Reduce default broadcast expiry time" 2021-07-30 09:39:08 +01:00
Pea Tyczynska
e1420e7ff7 Catch cancel_letter errors from API
When we catch such error, if the message is recognised,
show the message and redirect user to view_notification page.
2021-07-28 12:55:06 +01:00
Ben Thorner
dcfff87cc0 Continue to remove "roles" terminology
This renames the two functions we have to translate between UI and
DB permissions, as well as some of their associated variables to
make it clearer which kind of permission they contain.
2021-07-28 12:37:17 +01:00
Ben Thorner
f5580b87dc Move tests to match where the code is located
These tests are unrelated to the others in test_permissions.py. We
should try and structure our tests the same as the code under test
so that it's clear where new tests should go.
2021-07-28 12:36:43 +01:00
Ben Thorner
1127a03c32 Move and rename roles_and_permissions.py
This file does not represent a model, but rather a set of utilities
that are specific to user permissions (vs. service permissions).
2021-07-28 12:36:40 +01:00
David McDonald
2dd48de1a7 Merge pull request #3981 from alphagov/single-quote-sms-sender
Add support for single quote in SMS sender name
2021-07-27 09:43:33 +01:00
David McDonald
a6cac27957 Allow straight single quote in sms sender names
This is so we can allow the sender name 'UC' for DWP.

Note, this is specifically only straight single quotes and not curly
quotes or double quotes. Curly quotes are not supported in the GSM
character set (https://en.wikipedia.org/wiki/GSM_03.38). There is
currently no defined user ask to support double quotes in sms sender
names.

I have tested this by sending a message through both Firetext and MMG to
make sure they both support the single quote character in SMS sender
names.

DWP also have had no particular issues using the SMS sender name with
their existing system in the past either.
2021-07-27 09:26:16 +01:00
David McDonald
65bdc7f5a4 Refactor of test cases into parametrized tests
No reason this shouldn't be parametrized. It will be neater, more
extendable and give better error messages

No functionality change, however I did slightly adapt one or two of the
test cases (for example to change the 11 characters or fewer test to
test on the boundary with 12 characters rather than many more).
2021-07-26 14:33:54 +01:00
Katie Smith
5277f734d9 Test the POST .approve_broadcast_message explicitly in the code
Previously, to get the the `.approve_broadcast_message` endpoint, we
were issuing a POST request to `.view_current_broadcast`. The
`.view_current_broadcast` only has a GET endpoint defined for the
`/services/<uuid:service_id>/current-alerts/<uuid:broadcast_message_id>`
route, so the request would end up at the `.approve_broadcast_message`
which defines the POST endpoint for that path.

This changes the tests to POST directly to `.approve_broadcast_message`
to avoid confusion.
2021-07-26 13:59:36 +01:00
Katie Smith
a7a1172e22 Split out the tests for 'New alert' button on broadcast dashboards
The 'New alert' button was being tested in the same tests as the tests
for the page content for the broadcast dashboards. Now that you only see
the button if you have the `create_broadcasts` permission, this adds a
new test just for the button so that the test for the page content can
be used for both broadcast permissions.
2021-07-26 13:59:36 +01:00
Katie Smith
bb4cd1ca07 Remove unused fixtures and freeze_time from test_broadcast.py 2021-07-26 13:59:36 +01:00
Katie Smith
761af69a00 Remove active_user_broadcast_permissions fixture
This wasn't adding anything now that we have two new and more specific
fixtures, `active_user_create_broadcasts_permission` and
`active_user_approve_broadcasts_permission`, that can be used instead.

`manage_templates` has now been removed from the `create_broadcasts`
permission, so this also adjusts the fixture for a user who can create
broadcasts.
2021-07-26 13:58:39 +01:00
Katie Smith
93ce0d4977 Remove send_messages permission from broadcast template page
This permission can be removed from the check to see whether the "Get
ready to send" link displays for broadcasts.
2021-07-26 13:58:23 +01:00
Katie Smith
8b08661902 Remove check for send_messages permission from broadcast pages
The `send_messages` permission has been deprecated for use with
broadcast services, so we can drop support for it in the code. We
were supporting both the old permissions and new permissions
(`create_broadcasts` and `approve_broadcasts`) while we switched people
over.

This removes `send_messages` from the `user_has_permissions` decorator
around the broadcast routes and from the page to view a broadcast and
broadcast dashboards. We can now git rid of a lot of the parameterization
that was temporarily added to the tests.
2021-07-26 10:58:16 +01:00
Chris Hill-Scott
b71f0c6795 Disambiguate sent and created
At the moment we say that you either ‘add’ an alert or ‘send’ it.

This is confusing because:
- an alert isn’t received on people’s phones until it’s approved, so
  this is really when it is ‘sent’ conceptually
- an alert can be rejected before anyone receives it, so the UI can say
  an alert that no-one ever received was sent

This commit re-labels things so that the the first part of the process
is ‘creating’ the alert.

This makes all the permissions nice and distinct from each other. Adding
templates and adding alerts feel conceptually quite different things
(what are you adding the alert to?).
2021-07-23 10:07:05 +01:00
Chris Hill-Scott
694d7cc2ff Split the templates permission out again
It will likely be the same people who have permission to create alerts
and edit templates (maybe someone in a comms role).

But combining the two permissions makes the options presented in the
form feel clunky because ‘alerts’ and ‘templates’ are conceptually quite
different.

So I think it makes sense to keep the templates permission the same as
it is for regular Notify services.
2021-07-23 10:07:04 +01:00
Leo Hemsted
80cfbacd84 Merge pull request #3974 from alphagov/deleted-template
dont let people get into one-off flow for deleted templates
2021-07-22 13:14:08 +01:00
Leo Hemsted
5da69dd495 dont let people get into one-off flow for deleted templates
previously we'd skip the template page entirely if someone didnt have
manage templates/api keys permission. however, if the template is
deleted you'd then go through the flow entering placeholders and stuff
before it would then crash when trying to send.

instead, just bounce the user to the template page. It has the content
and says when the template was deleted.
2021-07-22 11:47:07 +01:00
Ben Thorner
832422fc66 Replace "admin roles" with "ui permissions"
In response to: [1].

While this does introduce a new term ("admin roles" is still used
elsewhere in the code), I plan to fix this in a follow-up PR (it
turned out to be quite a big change to do on this branch).

[1]: https://github.com/alphagov/notifications-admin/pull/3970#discussion_r673292339
2021-07-21 16:19:56 +01:00
Ben Thorner
9fafc092f7 Audit permissions when adding a user to a service
This is useful information to store for the event, which would be
lost if someone subsequently changed them.

Rather than updating lots of mock assertions, I've replaced them
with a single test / assert at a lower level, which is consistent
with auditing being a non-critical function.
2021-07-21 15:32:04 +01:00
Ben Thorner
171f911237 Audit when user permissions are changed
I've used the term "admin_roles" in the event data to try and show
that these are not the permissions we store in the DB. This is the
name we use for the abstracted form of permissions in the Admin app.
While we could store the DB permissions, that would be a bit more
effort and arguably it's clearer to keep the event data consistent
with the options the user actually saw / chose.
2021-07-21 15:32:03 +01:00
Ben Thorner
0f87ffe093 Move inline import to top of file
Usually we have imports at the top. It looks like the reason for
them being inline was to avoid a circular import, but we can also
avoid this by not importing everything from the app module.

Since we're about to add more imports from event_handlers, now is
a good time to refactor them. Note this matches how we import the
event handlers in every other module.
2021-07-21 15:32:01 +01:00
Katie Smith
6a29361071 Re-name and re-order some view broadcast tests
This tries to make the naming slightly more consistent and groups
together tests for the same thing.
2021-07-19 14:40:14 +01:00
Katie Smith
103cf4890b Add paragraph to broadcast settings form
The form is going to change to remove all existing permissions when it
is submitted, so this adds a paragraph to explain that.
2021-07-19 14:40:14 +01:00
Katie Smith
7e8c638865 Change /broadcast/view-message.html page to work with both permissions
The buttons and links on this page now work with the original
permissions and the two new broadcast permissions. Since the new
broadcast permissions have the effect of splitting the `send_messages`
permission this means that additional sections of if/else logic were
required.
2021-07-19 14:40:14 +01:00
Katie Smith
7572a97436 Use new permissions for 'Prepare broadcast' button on templates page 2021-07-19 14:40:14 +01:00
Katie Smith
b6905c435b Use new permissions for the button on the broadcast dashboard
The broadcast dashboards contain a button to create a new broadcast.
This adds the new `create_broadcasts` permission as one of the
permissions needed to see the button.
2021-07-19 14:40:14 +01:00
Katie Smith
a84705f834 Update the broadcast roles
We've added new broadcast roles in the database (`create_broadcasts` and
`approve_broadcasts`).

Adding these has meant we've needed to do a bit of a rewrite of the roles and
permissions code since this had been based on the assumption that each
database permission only belongs to one admin role - this is no longer true.
This means that flipping the roles dict round to create a dict which
contains database permissions as the keys is no longer possible. We can't
necessarily tell which admin role someone has given a database permission.

To check if a user has an admin role given a list of database permissions,
the user must now have ALL the database permissions mapped to that role
(instead of just one). This works because no one has the `manage_users`
permission without also having the `manage_settings` (and similar for
the other admin roles which map to multiple database permissions).

Some test data was changed because it was using admin roles where
database permissions are actually used when the app is running. I've kept
the functionality of the `translate_permissions_from_db_to_admin_roles`
function passing through any unknown roles it is passed as an argument.
This is not necessary, so can be changed later if we decide it will not
ever be used. However, removing it would require updating a lot of
tests since the tests rely on this behaviour.
2021-07-19 14:40:13 +01:00