Commit Graph

11796 Commits

Author SHA1 Message Date
Chris Hill-Scott
f05e13edf3 Remove grid column from edit user page
We don’t restrict the column width on the invite user page. Having it
restricted makes the hint text wrap awkwardly when editing users on an
Emergency Alerts service.

By removing the grid column the hint text looks better.
2021-07-23 10:07:03 +01:00
Chris Hill-Scott
8d9e415539 Merge pull request #3978 from alphagov/pin-eventlet
Add Pyup comment to requirements.txt
2021-07-23 10:06:42 +01:00
Chris Hill-Scott
fab44e016a Add Pyup comment to requirements.txt
This matches what’s in requirements.in, but the Pyup comments don’t
automatically get copied when generating requirements.txt. This causes
Pyup’s safety CI to complain we’re using a version with a known
vulnerability (which doesn’t affect us since we don’t use websockets).
2021-07-23 09:01:53 +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
6232858490 Merge pull request #3970 from alphagov/audit-perm-changes-178770155
Audit permissions when they change for a user
2021-07-22 09:37:23 +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
2241b119b0 Split (has_)permissions_for_service method
This avoids duplicating the code to get user permissions ("admin
roles") for a service, which we'll need in the next commit.
2021-07-21 15:32:02 +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
d414e6d345 Merge pull request #3936 from alphagov/bcast-permissions
Use the new broadcast permissions
2021-07-20 11:21:28 +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
0249f1602d Change hint text for the broadcast form 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
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
Ben Thorner
078ac10c8d Merge pull request #3971 from alphagov/bump-python-client-178770155
Bump Python client version to 6.2.1
2021-07-19 13:27:29 +01:00
Ben Thorner
63926235cc Bump Python client version to 6.2.1
This is a prerequisite for [1]. I'd like to deploy it as a separate
change so it's easy to roll back if we need to.

[1]: https://github.com/alphagov/notifications-admin/pull/3970
2021-07-19 10:19:43 +01:00
Chris Hill-Scott
13745d812f Merge pull request #3965 from alphagov/refactor-org-invite-form
Refactor organisation invite form for reuse
2021-07-16 09:32:19 +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
Rebecca Law
54787689c9 Merge pull request #3953 from alphagov/show_exceeded_daily_limit_on_page
Show status when job has exceeded the daily sending limit
2021-07-15 16:03:19 +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
Rebecca Law
cca94e956b Update content 2021-07-14 09:55:20 +01:00
Rebecca Law
af7882e5a4 Show status when job has exceeded the daily sending limit
If a job exceeds the daily sending limit, show that on the job page. The job is only created if the sending limit has been reached when the delivery app is processing the job, usually this error is caught at the time the CSV is uploaded and the job is not created.
2021-07-14 09:55:20 +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
1fb529c448 Improve coverage of resume service tests
This makes the tests consistent with those for suspend / archive,
logging in with different users to make it clearer who can/not do
this action in the backend.

Note that we think this functionality may be too permissive [1],
so we may restrict it in a future PR.

[1]: https://github.com/alphagov/notifications-admin/pull/3959#issuecomment-878291295
2021-07-13 10:57:22 +01:00
Ben Thorner
d37c2abb9e DRY-up arg assertions in event handler tests
This will make it easier to add another handler in the next commit.
2021-07-13 10:57:21 +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
cfe022bc7f Merge pull request #3959 from alphagov/audit-service-suspend-delete
Audit when services are suspended or archived
2021-07-12 14:50:07 +01:00
Pea Tyczynska
61e52faaee Merge pull request #3962 from alphagov/fix-bug-conditional-multiline
Bump utils to revert a bug to conditional multiline placeholders
2021-07-09 14:05:46 +01:00
Pea Tyczynska
7f08ae7c29 Bump utils to revert a bug to conditional multiline placeholders 2021-07-09 13:51:39 +01:00
Ben Thorner
9b62b7ccb0 DRY up mock event dict with a factory function 2021-07-08 17:17:25 +01:00
Ben Thorner
7e8b5d36be Remove redundant context for event handler tests
Just like the new tests for suspending and archiving services, we
can use the 'client' fixture instead of a context, which avoids
the extra nesting. Note that the first event handler doesn't use
its first argument, which I've tried to indicate with a string.
2021-07-08 17:17:24 +01:00
Ben Thorner
cd1fe0640c Improve coverage of suspend service tests
Previously these only tested with a Platform Admin user, but service
admins can suspend a service too. I've rewritten the tests to match
the 'archive_service' ones, which use the client_request fixture to
make changing the user easier.

Note that the return value of the service API client wasn't used for
anything, so it's safe to remove it from the mock.
2021-07-08 17:17:23 +01:00