Commit Graph

3182 Commits

Author SHA1 Message Date
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
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
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
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
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
354cd8bb16 Replace remaining uses of the term "role"
In one case I did this by refactoring the code to avoid the need
for the "role" variable in the first place.
2021-07-28 12:37:18 +01:00
Ben Thorner
ba9865e62e Start to remove use of the term "roles"
We don't use this term consistently and it's not defined anywhere.
Since most of the Admin app deals with user-facing permssions, it's
OK to just use the term "permissions". Where both types of permission
are present in the same file, we can more clearly distinguish them
as "UI permissions" and "DB permissions".
2021-07-28 12:37:16 +01:00
Ben Thorner
a38baa0bd8 Rename unclear "permissions" attributes
These are more than a list of permissions: each item includes the
label to use when displaying it as an option on a form. Switching
to a name that reflects how the attributes are used will help to
avoid confusion when we rename some of the other attributes in the
same file in later commits.
2021-07-28 12:37:15 +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
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
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
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
Katie Smith
0249f1602d Change hint text for the broadcast form 2021-07-19 14:40:14 +01:00
Katie Smith
a66a31c944 Allow users with new broadcast permissions access to routes
Added two new permissions - `create_broadcasts` and
`approve_broadcasts`. These new permissions get added to the
`has_permissions` decorator of the broadcast routes to allow the routes
to be accessed with either the old permissions on the new ones while we
switch over.

We were using the `send_messages` permission for the broadcast routes.
By having two new permissions we can allow a more granular control of
these routes.
2021-07-19 14:40:13 +01:00
Chris Hill-Scott
f8d4617672 Refactor organisation invite form for reuse
It’s exactly the same code as `BaseInviteUserForm` so there’s really no
need to duplicate it (and means that changes we make to
`BaseInviteUserForm` in the future will get inherited).
2021-07-16 09:20:06 +01:00
Chris Hill-Scott
f84f05191e Merge pull request #3968 from alphagov/forgotten-password-govuk-link
Style link in wrong password error
2021-07-16 09:16:53 +01:00
Chris Hill-Scott
93fbd1319c Merge pull request #3966 from alphagov/block-plus-addressing
Be strict about similar email addresses when inviting a user to an emergency alerts service
2021-07-16 09:16:47 +01:00
Chris Hill-Scott
d749ee5cea Rename confusing variable
The reason the email address is considered invalid is because it is the
address of the person doing the inviting.

This commit renames the variable to be more specific and avoid confusion
with the email address of the person being invited.
2021-07-15 14:21:58 +01:00
Chris Hill-Scott
c3091223a9 Be strict about similar email addresses for alerts
We don’t want a single person to have two accounts on an emergency
alerts service because it would let them circumvent the two eyes
approval process.

We can go some way to mitigating against this by stopping people using
common methods that email providers use to alias email addresses. These
are:
- being case insensitive
- being insensitive to the position or number of dots in the local part
  of an email address
- using ‘plus addressing’

We already prevent the first one, this commit adds normalisation which
strip out the second two before doing the comparision with the current
user’s email address.
2021-07-15 13:55:50 +01:00
Ben Thorner
9170c0b175 Merge pull request #3969 from alphagov/fix-suspend-archive-perm-178770416
Fix backend permissions for stopping services
2021-07-15 09:29:20 +01:00
Katie Smith
9d4095074d Merge pull request #3967 from alphagov/broadcast-form-cache-clear
Clear user cache when broadcast service settings form is submitted
2021-07-14 16:02:14 +01:00
Ben Thorner
96a87e7cf2 Fix and test archive service permissions
Previously the backend would never validate permissions because the
"not service.active" part would (usually) fail. I've updated it to
match the (inverse of the) conditional we have in the HTML [1].

[1]: 6ac593aa5f/app/templates/views/service-settings.html (L455)
2021-07-14 14:51:33 +01:00
Ben Thorner
cd95a891a7 Enforce only Platform Admin can suspend / resume
This was previously out-of-sync with the superficial restriction in
the HTML [1][2].

[1]: 6ac593aa5f/app/templates/views/service-settings.html (L462-L468)
[2]: 6ac593aa5f/app/templates/views/service-settings.html (L471)
2021-07-14 14:51:32 +01:00
Chris Hill-Scott
db15e3ebb0 Style link in wrong password error
It was missing the class which gives it the correct colour and underline styles.

Also adds a little bit of spacing to make it look better.
2021-07-14 09:42:56 +01:00
Katie Smith
5b52b6f9bf Clear user cache when broadcast service settings form is submitted
When the broadcast service settings form is submitted it now removes all
permissions for users in notifications-api. This means it should be
clearing the user cache.
2021-07-13 17:06:35 +01:00
Chris Hill-Scott
9dd5c89252 Move two calls to str.lower next to each other
This means that we can rewrite `validate_email_address` to do a
different comparison without having to also change `__init__`

I’ve moved the platform admin check into its own conditional to keep the
line length manageable.
2021-07-13 15:38:13 +01:00
Ben Thorner
6ac593aa5f Merge pull request #3963 from alphagov/audit-service-resume-178770416
Audit when a service is resumed
2021-07-13 12:09:54 +01:00
Ben Thorner
1cde6ac686 Audit when a service is resumed
This could also be an issue if the service can send broadcasts, so
it's worth auditing who performed this action.
2021-07-13 10:57:23 +01:00
Ben Thorner
22ac1bfcae DRY-up and enforce kwargs for most events
For most events this makes the purpose of each argument clearer at
the point the event is called. It's still worth having a function
for each event type, as this abstracts knowledge of the event label.
Using a schema approach will make adding new events easier.

In the next commit we'll DRY-up the duplication in the tests as well.
2021-07-13 10:57:19 +01:00
Chris Hill-Scott
aefbe7709b Merge pull request #3951 from alphagov/hide-go-live-ticket-content
Hide details of go live request ticket from the user
2021-07-13 08:49:43 +01:00
Ben Thorner
301908460a Audit when a service is archived ("deleted")
This is similar to the previous commit. I've used the term 'archive'
to match the rest of the code - services aren't ever truly deleted.
2021-07-08 17:17:22 +01:00
Ben Thorner
bb4c86008a Add audit event for suspending a service
This is particularly important for broadcast services, where a rogue
service or platform admin could launch a DoS attack by suspending a
service at a critical moment when it needs to send alerts.
2021-07-08 15:29:52 +01:00
Ben Thorner
e72a260e13 Merge pull request #3947 from alphagov/allow-ccs
Allow other users to use security keys
2021-07-08 11:53:03 +01:00
Chris Hill-Scott
ceca92c84e Merge pull request #3952 from alphagov/emergency-alerts-content-review
Emergency alerts content review
2021-07-08 09:33:54 +01:00
Ben Thorner
4c2915ce86 Use API flag to give users access to WebAuthn
This allows us to roll out the feature to other users. Note that
the flag is also "True" if the user has "webauthn_auth" as their
auth type, so this is compatible with the more fine-grained check
we have on the authentication parts of the feature. We could do a
more explicit "can_use_webauthn or webauthn_auth" check here, but
the idea is that we'll be able to get rid of this flag eventually,
so I've optimised for brevity instead.

I've modified a couple of the unhappy-path tests to make it more
explicit that the flag is false, since it can be true for Platform
Admins and "normal users" alike.
2021-07-07 15:04:48 +01:00
Ben Thorner
a1b4ccc246 Prevent auth type changing for any WebAuthn user
Previously we applied this restriction to Platform Admins, on the
assumption that all of them use a security key to log in. Rather
than making that assumption, we can explicitly check their login
method, which also supports rolling out the feature to more users.
2021-07-07 15:04:43 +01:00
Chris Hill-Scott
cc4cc78d8c Hide details of go live request ticket from the user
We put some content in the go live ticket which is for our benefit, for
example notes about the organisation.

It’s hard for us to be able to say what we want here if we know that the
person making a go live request is going to see those notes.

This commit changes go live requests so that the initial content of the
ticket is hidden from the person raising it (in Zendesk it will appear
as an ‘internal note’, rather than a ‘public reply’).

---

Depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/877/files
2021-07-06 17:30:17 +01:00
Leo Hemsted
416b5c3e26 Merge pull request #3926 from alphagov/sign-in-bug
ensure user details are always in the session after entering password
2021-07-06 11:56:24 +01:00
Chris Hill-Scott
2cfd22b20c Remove empty state step before choosing areas
We had some kind of idea that having this empty page would introduce the
idea of choosing areas and reinforce that you are building up a list of
areas.

But since the journey is now so simple with the button to create an
alert directly on the dashboard page, maybe people don’t need this extra
orientation.
2021-07-05 14:33:02 +01:00
karlchillmaid
dcc38b5619 Change previous to past 2021-07-05 13:46:04 +01:00
Ben Thorner
1f33924ceb Send upload_id to Template Preview for logging
This means we can include the anonymous ID for the file in the log
we have about Type3 fonts [1]. Currently, we have no way of tracing
manually uploaded files with this potential defect.

[1]: https://github.com/alphagov/notifications-template-preview/pull/557
2021-07-01 12:09:47 +01:00
Ben Thorner
43afcd1064 Remove redundant restrictions for WebAuthn feature
Since the register and authentication APIs work in pairs, we can
just put the restrictions on the "begin" API. We weren't testing
the restrictions on the "complete" API anyway.

For authentication, it's also enough to check if the user has
WebAuthn as their auth type, as it's not a big deal if a user
continues to login with a security key indefinitely.
2021-06-30 16:19:12 +01:00
Ben Thorner
7fafc18fb3 Remove unnecessary restriction for 2FA WebAuthn
It should be enough to check the user has it set as their auth type.
Even if a user is no longer eligible to register a security key, it
should still be OK for them to continue using the feature.
2021-06-30 14:54:20 +01:00