Commit Graph

8564 Commits

Author SHA1 Message Date
Ben Thorner
1e8eda0d15 Avoid failover when running link tests
We want to get the point where we're running link tests for each
lambda independently. The tests weren't checking for the failover
mechanism for link tests, so we can just remove it.
2021-07-19 15:45:42 +01:00
Ben Thorner
b6774bf0f7 Generate Vodafone link test sequence nos in proxy
Previously the Celery task to trigger a link test had to know about
the special case of a sequence number for Vodafone. Since we're about
to change the client to perform multiple tests it makes sense to give
it the knowledge of how to generate number itself.

Note that we have to import the db inline to avoid a circular import,
since this module is itself imported by app/__init__.py.

Other invocations of the Vodafone client use stored sequence numbers
from the DB, which are called "message numbers" in that context. Since
the two use cases are very different (even the names are different!),
having them in two places shouldn't cause any confusion.
2021-07-19 15:43:36 +01:00
Katie Smith
d708b64dd4 Remove original permissions from broadcast users
The broadcast user permissions are changing, so to avoid confusion and
permissions which exist in the database but don't display on the
frontend we are going to remove all existing permissions for users of
broadcast services. This also updates the permissions of invited users
who are still pending.

The exception to this is the `view_activity` permission, which we always
add for broadcast users even if they have no other permissions.
(aad017a184/app/main/forms.py (L1043))
2021-07-19 14:38:48 +01:00
Sakis
e166156fad Merge pull request #3292 from alphagov/revert-werkzeug
Revert werkzeug to the last non-2.0.0 version
2021-07-19 16:14:26 +03:00
sakisv
7ff43939bc Revert werkzeug to the last non-2.0.0 version
We observe high memory usage since we bumped it (along with other
things) and because it only appears on the API and not on the workers
the hypothesis is that Werkzeug is responsible for it.
2021-07-19 16:06:56 +03:00
Katie Smith
0c7982fd84 Always keep view_activity permissions for broadcast users
We made a change to remove all permissions from users and invited users
when the broadcast service settings form is submitted
(https://github.com/alphagov/notifications-api/pull/3284). However, when the
form is submitted, notifications-admin always adds the `view_activity`
permission even if no permission boxes are ticked, so we don't want to
remove that one permission
(256c840b46/app/main/forms.py (L1042))
2021-07-14 16:39:38 +01:00
Rebecca Law
d781da2981 Merge pull request #3261 from alphagov/remove-scheduled_notifications
Remove scheduled_notifications
2021-07-14 10:56:42 +01:00
Leo Hemsted
1975f3664a Merge pull request #3289 from alphagov/retry-429-callback
retry service callbacks on 429
2021-07-13 17:04:45 +01:00
Leo Hemsted
2ad9a3a380 retry service callbacks on 429
if we're served a 429, put the item on the retry queue and retry the
same as if the service returned a 5xx. 429 is commonly returned for rate
limit exceeding, and retrying on a delay is a typical response to that.
2021-07-13 16:09:17 +01:00
Pea Tyczynska
719ba698e2 Merge pull request #3288 from alphagov/bump-utils-to-revert-changes
Bump utils to revert changes to placeholders that introduced a bug
2021-07-09 14:58:02 +01:00
Pea Tyczynska
e82b8bc33c Bump utils to revert changes to placeholders that introduced
a bug.
2021-07-09 14:45:41 +01:00
Pea Tyczynska
96f34bbd45 Merge pull request #3286 from alphagov/bump-utils-fix-placeholder-bug
Bump utils to bring in fix for optional placeholder bug
2021-07-09 11:24:42 +01:00
Katie Smith
18bb1c2ac4 Merge pull request #3277 from alphagov/bcast-service-permissions
Remove user permissions if service becomes a broadcast service
2021-07-09 09:12:45 +01:00
Pea Tyczynska
c28e9451d4 Bump moto version to try solve dependencies version conflict
Also update mock import statements in some test files as they
stopped working with this dependency update.
2021-07-08 15:37:19 +01:00
Pea Tyczynska
9e8682ac29 Bump utils to bring in fix for optional placeholder bug
See https://github.com/alphagov/notifications-utils/pull/878 for
details.

Changes we had to make for our app and tests to work correctly
after the dependency updates:

1. Update emergency alerts polygons test because we changed
how exact we are with locations of the points on the map.

2. Use Flask's g object to set additional request attributes

So far we have been storing them in _request_ctx_stack which is
an innard for Flask's request context.

Because of major update to Werkzeug dependency, which Flask relies
on, the way we were using it stopped working, so we had a new
way to set those values.
The way we set those values now, by using g object, seems to also
be favoured in Flask documentation:
https://flask.palletsprojects.com/en/1.1.x/reqcontext/#how-the-context-works
2021-07-08 12:18:09 +01:00
Rebecca Law
5fcf65422c Fix version conflicts. 2021-07-08 08:14:03 +01:00
Rebecca Law
bcd8d85569 Fix merge conflicts 2021-07-08 08:12:18 +01:00
Rebecca Law
ae29ae28e5 Adding CONCURRENTLY to the drop index statement.
Drop index concurrently will drop the index without locking out concurrent selects, inserts, updates, and deletes on the index's table namely on notifications.
2021-07-08 08:12:18 +01:00
Rebecca Law
94c4a8f238 Remove scheduled_notifications
All code has been removed for ScheduledNotifications. This PR just
removes the table, it has never been used.
2021-07-08 08:12:18 +01:00
Katie Smith
fc0b9736eb Remove user permissions if service becomes a broadcast service
The "normal" service permissions and broadcast service permissions are
going to be different with no overlap. This means that if you were
viewing the team members page, there might be permissions in the
database that are not visible on the frontend if a service has changed
type. For example, someone could have the 'manage_api_keys' permission,
which would not show up on the team members page of a broadcast service.
To avoid people having permissions which aren't visible in admin, we now
remove all permissions from users when their service is converted to a
broadcast service.

Permisions for invited users are also removed.

It's not possible to convert a broadcast service to a normal service, so
we don't need to cover for this scenario.
2021-07-07 16:13:35 +01:00
Katie Smith
29a13a8fae Merge pull request #3274 from alphagov/new-permissions
Add new broadcast related permissions
2021-07-07 15:31:21 +01:00
Katie Smith
e5fdd8ee1f Add new broadcast related permissions
We want to have new permissions which will be used specifically for
broadcasts:
- `create_broadcasts`
- `approve_broadcasts`
- `reject_broadcasts`
- `cancel_broadcasts`

Cancel and reject will always go together, but having separate database
permissions makes things easier to change in the future.

The permission column of the permissions table is an enum. We can add values
in the alembic upgrade script, but removing individual values from an
enum is not supported by Postgres. To remove values, we have to recreate
the enum with the old values.
2021-07-07 14:54:13 +01:00
Ben Thorner
273d14fbe4 Merge pull request #3280 from alphagov/webauthn-user-flag
Add flag to say if user is eligible for WebAuthn
2021-07-01 11:10:06 +01:00
Ben Thorner
6cf24899dd Let existing WebAuthn users continue using it
It's not a big deal if a user is no longer eligible to register a
security key, so we may as well let them continue using it. This
avoids putting them in a limbo state if we don't immediately change
their auth type when they're no longer eligible to use the feature.
2021-06-30 15:41:43 +01:00
Rebecca Law
f4c0f1f1df Merge pull request #3282 from alphagov/fix-bug-check_service_over_daily_limit
Convert value from redis to an int.
2021-06-29 14:11:28 +01:00
Rebecca Law
c501c92bf3 Convert value from redis to an int.
This has been properly tested locally with redis enabled.
2021-06-29 14:00:25 +01:00
Rebecca Law
864554f125 Merge pull request #3281 from alphagov/fix-bug-check_service_over_daily_limit
Fix bug in check_service_over_daily_limit
2021-06-29 13:20:14 +01:00
Rebecca Law
ed788cb0bd Fix bug in check_service_over_daily_limit
I forgot to return service_stats if the cache exists. And fixed the tests to check service_stats value.
2021-06-29 12:59:20 +01:00
Rebecca Law
310e1cb4e2 Merge pull request #3276 from alphagov/daily-limit-redis-cache
Correct the daily limits cache.
2021-06-29 12:06:35 +01:00
Ben Thorner
2fa6327efb Add flag to say if user is eligible for WebAuthn
Currently we have some data-driven roles to say who can use this
feature. Adding a flag in the API means we can avoid API calls in
the Admin app to determine the same.

Allowing members of the GOV.UK Notify service to use the feature
is a workaround, so we can avoid making someone a Platform Admin
before they've protected their account with it.
2021-06-28 13:35:24 +01:00
Rebecca Law
18dd9050a4 - make sure when processing a job that we check the total_sent + job.notification_count against the service.message_limit. 2021-06-28 13:07:48 +01:00
Ben Thorner
2b292ebd16 Refactor "notify_service" function into a fixture
This means we can use it in the next commit. Also, it was surprising
for the function to be returning a tuple of values, instead of just
the service object. Since the consumers of the function only needed
the user as auditing data, it's fine to use the first team member.
2021-06-25 17:46:07 +01:00
Rebecca Law
fd7486d751 - Merge daily limit functions into one, refactor call for daily limit check from process_job
- refactor tests to standardise test names
- refactor some tests to be more clear
- remove unnecessary tests
- include missing test
2021-06-24 11:05:22 +01:00
Katie Smith
5c7b0d1dfb Merge pull request #3279 from alphagov/report-fix
Fix the endpoint for the monthly status report
2021-06-24 08:57:26 +01:00
Katie Smith
0f42b4dbec Fix the endpoint for the monthly status report
This wasn't working - the error given when trying to access it was
`TypeError: Object of type 'Row' is not JSON serializable` when we tried
to serialize a SQLAlchemy Row.

I haven't looked too far into what has changed to stop this from
working, but have just changed the endpoint to return a nested list instead.
2021-06-23 16:03:58 +01:00
Rebecca Law
57fb9da414 - change the condition so that we don't reset the cache if it's zero
- set the cache if it doesn't exist so there is an expiry of 24 hours.
2021-06-23 15:09:09 +01:00
Chris Hill-Scott
1c1023a877 Merge pull request #3257 from alphagov/refactor-high-volume-check
Refactor high volume into serialised service model
2021-06-23 09:01:27 +01:00
Rebecca Law
35b20ba363 Correct the daily limits cache.
Last year we had an issue with the daily limit cache and the query that was populating it. As a result we have not been checking the daily limit properly. This PR should correct all that.

The daily limit cache is not being incremented in app.notifications.process_notifications.persist_notification, this method is and should always be the only method used to create a notification.
We increment the daily limit cache is redis is enabled (and it is always enabled for production) and the key type for the notification is team or normal.

We check if the daily limit is exceed in many places:
 - app.celery.tasks.process_job
 -  app.v2.notifications.post_notifications.post_notification
 - app.v2.notifications.post_notifications.post_precompiled_letter_notification
 - app.service.send_notification.send_one_off_notification
 - app.service.send_notification.send_pdf_letter_notification

If the daily limits cache is not found, set the cache to 0 with an expiry of 24 hours. The daily limit cache key is service_id-yyy-mm-dd-count, so each day a new cache is created.

The best thing about this PR is that the app.service_dao.fetch_todays_total_message_count query has been removed. This query was not performant and had been wrong for ages.
2021-06-22 16:15:36 +01:00
Rebecca Law
c44ec57c17 Merge pull request #3266 from alphagov/update-notifications-model-with-indexes
Tidy up models
2021-06-21 12:43:08 +01:00
Rebecca Law
ff79c65cab Move the indexes to be inline with the table. 2021-06-21 12:06:38 +01:00
Ben Thorner
916a1b55c5 Merge pull request #3272 from alphagov/remove-test-script
Run tests directly from the Makefile
2021-06-16 17:32:06 +01:00
David McDonald
69212827eb Merge pull request #3270 from alphagov/broadcast-status-transition-tests
Broadcast status transition tests
2021-06-16 16:04:15 +01:00
Ben Thorner
149976bfab Run tests directly from the Makefile
Contributes to: https://github.com/alphagov/notifications-manuals/issues/9

Precedent: https://github.com/alphagov/notifications-admin/pull/3897
2021-06-16 13:05:55 +01:00
Ben Thorner
47b1e280bb Merge pull request #3271 from alphagov/dont-upgrade-ci
Don't try to upgrade DB on CI
2021-06-16 11:49:57 +01:00
Chris Hill-Scott
57249b43c8 Refactor high volume into serialised service model
Just looks a bit tidier and less repetitive.

I’ve only done this for the serialised service because:
- we’re only checking this in places where we’re already using the
  serialised service
- if we want to check this elsewhere there’s a good chance that new code
  should be using the serialised service, since it’ll itself be doing
  some kind of performance optimisation
2021-06-16 10:46:18 +01:00
Rebecca Law
467794c212 Merge pull request #3269 from alphagov/permanent-failure-for-letters
Add permanent-failure for letters.
2021-06-16 10:42:08 +01:00
Rebecca Law
d4a42471cb Merge pull request #3267 from alphagov/fix-daily-totals-query
Improve the query to get today's totals for a service.
2021-06-16 07:34:01 +01:00
Ben Thorner
d98ea6a8bc Don't try to upgrade DB on CI
This was added by mistake - the Concourse pipeline never did this
previously, and errors if we try (the necessary environment vars
aren't present, even if we wanted to).
2021-06-15 17:33:19 +01:00
David McDonald
5b409bd3c3 Add test coverage for broadcast status transition
This was mentioned in an old pen test report that you could send a
request twice to set a broadcast message as broadcasting which would
trigger us to send two alerts.

It looks like this is now fixed and this test coverage backs that up.

Note, it's unlikely that it would have been an issue anyway as the CBC
would likely have rejected the message as it would notice it is a
duplicate.

Note, this test coverage is not supposed to be exhaustive of all the
potential transitions but covers the vast majority of ones that we care
about.

See `BroadcastStatusType.ALLOWED_STATUS_TRANSITIONS` for allowed
transitions.
2021-06-15 17:27:21 +01:00
David McDonald
54fe8ee68d Remove old todo for support of draft to broadcasting transition
It looks like we were allowing broadcasts to transition from draft to
broadcasting in one go. This isn't valid now. It should go draft,
pending approval and then broadcasting.

It looks like this was a leftover bit of support in our code for when we
were building stuff out and is no longer needed.
2021-06-15 17:18:54 +01:00