Commit Graph

8053 Commits

Author SHA1 Message Date
Ben Thorner
ff7eebc90a Simplify deleting old letters
Previously we made a call to S3 to list objects for a letter, even
though we already had the precise key of the single object to hand.
This removes the one usage of "get_s3_bucket_objects" and uses the
filename directly in the call to remove the object.
2021-03-15 17:18:20 +00:00
Leo Hemsted
6784ae62a6 Raise Exception if letter PDF not in S3
Previously, the function would just return a presumed filename. Now that
it actually checks s3, if the file doesn't exist it'll raise an
exception. By default that's a StopIteration at the end of the bucket
iterator, which isn't ideal as this will get supressed if the function
is called within a generator loop further up or anything.

There are a couple of places where we expect the file may not exist, so
we define a custom exception to rescue specifically here. I did consider
subclassing boto's ClientError, but this wasn't straightforward as the
constructor expects to know the operation that failed, which for me is a
signal that it's not an appropriate (re-)use of the class.
2021-03-15 17:18:11 +00:00
Ben Thorner
b43a367d5f Relax lookup of letter PDFs in S3 buckets
Previously we generated the filename we expected a letter PDF to be
stored at in S3, and used that to retrieve it. However, the generated
filename can change over the course of a notification's lifetime e.g.
if the service changes from crown ('.C.') to non-crown ('.N.').

The prefix of the filename is stable: it's based on properties of the
notification - reference and creation - that don't change. This commit
changes the way we interact with letter PDFs in S3:

- Uploading uses the original method to generate the full file name.
The method is renamed to 'generate_' to distinguish it from the new one.

- Downloading uses a new 'find_' method to get the filename using just
its prefix, which makes it agnostic to changes in the filename suffix.

Making this change helps to decouple our code from the requirements DVLA
have on the filenames. While it means more traffic to S3, we rely on S3
in any case to download the files. From experience, we know S3 is highly
reliable and performant, so don't anticipate any issues.

In the tests we favour using moto to mock S3, so that the behaviour is
realistic. There are a couple of places where we just mock the method,
since what it returns isn't important for the test.

Note that, since the new method requires a notification object, we need
to change a query in one place, the columns of which were only selected
to appease the original method to generate a filename.
2021-03-15 13:55:44 +00:00
David McDonald
15b9cbf7ae Merge pull request #3177 from alphagov/stop-posting-to-pp
Remove performance platform code
2021-03-15 12:17:45 +00:00
David McDonald
41d95378ea Remove everything for the performance platform
We no longer will send them any stats so therefore don't need the code
- the code to work out the nightly stats
- the performance platform client
- any configuration for the client
- any nightly tasks that kick off the sending off the stats

We will require a change in cronitor as we no longer will have this task
run meaning we need to delete the cronitor check.
2021-03-15 12:04:53 +00:00
David McDonald
8325431462 Move saving of processing time into separate task
We current do this as part of send-daily-performance-platform-stats but
now this moves it into its own separate task. This is for two reasons
- we will shortly get rid of the send-daily-performance-platform-stats
  task as we no longer will need to send anything to performance
  platform
- even if we did decide to keep the task
  send-daily-performance-platform-stats and remove the specific bits
  that relate to the performance platform, it's probably nicer to
  rewrite the new task from scratch to make sure it's all clear and easy
  to understand
2021-03-15 11:44:01 +00:00
Leo Hemsted
99cd312b0e Merge pull request #3171 from alphagov/new-invite-endpoints
New invite endpoints
2021-03-12 14:16:19 +00:00
Leo Hemsted
ebd4eda8bd remove duplicate dao invite fns and improve naming 2021-03-12 13:56:05 +00:00
Leo Hemsted
58896e194d add new invite/<token_type>/check/<token> endpoint
having `/invite/service/<token>` and `/invite/service/<id>` as two
separate routes (the first to validate an invite token, the second to
retrieve invite metadata) technically works. Routes are matched from
first to last until a match is found. The metadata endpoint only accepts
UUIDs, so requests with a UUID will be picked up by the correct
endpoint, while requests that don't look like a UUID will carry on
searching for an endpoint, and will find the token validation endpoint.

So while this works correctly for our normal expected input, it only
does so _because the UUID endpoint is first in the file_. This isn't
great, and it makes it harder to reason about the URLs when looking at
them.

To solve this, create the new `invite/service/check/<token>` endpoint.
For backwards compatibility, assign this in parallel with the existing
route - once the admin uses the new route we can remove the old route
and make better guarantees about what endpoint is being hit.
2021-03-12 13:56:01 +00:00
Leo Hemsted
eab4a75e29 remove the global_invite (accept_invite) endpoint
move the endpoints into service_invite/rest.py and
organisation/invite_rest.py respectively. Remove the prefix from all the
blueprints to allow this.
2021-03-12 13:55:55 +00:00
Leo Hemsted
4471189b87 add endpoints to fetch a user based on their ID only
this functions the same as `validate_invitation_token`, but without
having the signed token, instead just the ID. This is so later endpoints
within the invite flow can also fetch the invited user
2021-03-12 13:55:44 +00:00
Leo Hemsted
d94d0bc8d7 rename invite blueprints
nb: the routes are not changing as part of this, only file paths and
blueprint names.

invite -> service_invite

this blueprint handles fetching invites for a service, creating invites,
etc.

accept_invite -> global_invite

this blueprint handles accepting invites for now, but will also involve
retrieving service/org user invite data without knowing the service/org
id associated. i'm not in love with this name and open to suggestions,
but i wanted to contrast it from service_invite and
organisation/invite_rest.py.
2021-03-12 13:55:43 +00:00
Ben Thorner
6dc73dbc41 Merge pull request #3178 from alphagov/add-missing-task-statsd
Add missing statsd timers to celery tasks
2021-03-12 13:06:03 +00:00
Ben Thorner
0379d721e5 Add missing statsd timers to celery tasks
All other tasks in app/celery/*_tasks.py have timers on them. Some
of these timers will be useful to check before/after performance as
a way to reassure ourselves about the impact of [1].

[1]: https://github.com/alphagov/notifications-api/pull/3172
2021-03-12 12:32:22 +00:00
Ben Thorner
b0c531f5cb Merge pull request #3175 from alphagov/add-isort
Add isort to build and fix issues
2021-03-12 11:54:21 +00:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Ben Thorner
321b4913ed Enforce consistency in imports as part of build
This copies the config we use in the admin app, with a few changes
as discussed in the PR [1]. We'll apply these to our other apps.

[1]: https://github.com/alphagov/notifications-api/pull/3175#issuecomment-795530323
2021-03-12 11:45:21 +00:00
David McDonald
a2cc0df5a7 Merge pull request #3167 from alphagov/broadcast_services_history
Add service versioning to broadcast account type change
2021-03-11 17:07:24 +00:00
Rebecca Law
2fabd59cf4 Merge pull request #3176 from alphagov/fix-update-notification-method
Refactor method for deciding the failure type
2021-03-11 14:34:50 +00:00
Rebecca Law
19f7a6ce38 Refactor method for deciding the failure type 2021-03-10 14:39:55 +00:00
Rebecca Law
a7a504a599 Merge pull request #3173 from alphagov/performance-platform-endpoints
Add an endpoint to return all the data required for the performance platform page
2021-03-10 13:27:08 +00:00
Rebecca Law
11d10d5293 Rename to performance_dashboard
Fix totals to return totals for all time rather than for date range.
Added more test data
2021-03-10 13:16:25 +00:00
Ben Thorner
6db9a7a2f2 Merge pull request #3170 from alphagov/quiet-pytest
Quieten output for pytest
2021-03-09 08:51:16 +00:00
Ben Thorner
94718c1d29 Quieten output for pytest
This avoids being verbose by default, which is consistent with how
we configure pytest for the admin app [1].

[1]: https://github.com/alphagov/notifications-admin/blob/master/pytest.ini#L16
2021-03-08 17:44:48 +00:00
David McDonald
ff11f39ce4 Merge pull request #3165 from alphagov/pyup-scheduled-update-2021-03-03
Scheduled weekly dependency update for week 09
2021-03-08 17:02:27 +00:00
David McDonald
289c0ea0c6 Make freeze requirements 2021-03-08 15:56:42 +00:00
David McDonald
8cf32d6f22 Add service versioning to broadcast account type change
We are using the `set_broadcast_service_type` route to make changes to
service objects. However, we had forgotten to add the `version_class`
decorator to it which will mean the changing of a service going from
training to live mode will also be recorded in the services_history
table for free. Whilst not essential, this easy change makes things more
consistent for how we update other services.
2021-03-08 14:09:24 +00:00
Leo Hemsted
dabdc2c4ac Merge pull request #3169 from alphagov/remove-old-user-email-endpoint
add POST get user by email endpoint
2021-03-05 14:06:57 +00:00
Leo Hemsted
e0234fecba add POST get user by email endpoint
the existing endpoint is a GET, and so leaves email addresses in log
files.

we've got an existing POST find_users_by_partial_email, but not one that
matches on a whole email address.
2021-03-05 12:58:45 +00:00
David McDonald
6b535fe946 Merge pull request #3166 from alphagov/email-auth-broadcast-bug
Email auth broadcast bug
2021-03-05 09:59:59 +00:00
Rebecca Law
b06850e611 Add an endpoint to return all the data required for the performance
platform page.
2021-03-05 09:59:03 +00:00
David McDonald
fcf667f09c Add test coverage for setting service permission
Spotted that we aren't testing all our permission types here so added
this one in.

It includes the TODO for allowing the API to give a service the
broadcast permission. We don't want this to happen, we want them to use
the `set_as_broadcast_service` route instead. We will probably get away
with it for the moment for it would be tighter validation we should add
to reduce the risk of letting a service get in a dodgy state.
2021-03-03 18:49:40 +00:00
David McDonald
0ce539704e Fix bug with removing email auth for broadcast service
We accidently were removing the ability for a service to do email auth
if it was a broadcast service with email auth. This fixes it.

Note, it might be up for debate later whether we let broadcast services
use email auth (I think we should) so this might change in time, but we
will fix this bug regardless.

Note, worth glancing at `SERVICE_PERMISSION_TYPES` which contains a list
of permissions that a service might have to make sure I haven't missed
any others. The one that looks potentially dodgy is the
`EDIT_FOLDER_PERMISSIONS` permission but I can't see this being used
anywhere in the API or the admin app so think it is likely now defunct
and a user level permission so we don't need to worry about it.
2021-03-03 18:34:24 +00:00
pyup-bot
9f39118991 Update notifications-python-client from 5.7.1 to 6.0.2 2021-03-03 13:00:06 +00:00
pyup-bot
b5f5114c59 Pin cryptography to latest version 3.4.6 2021-03-03 13:00:06 +00:00
pyup-bot
80891199f8 Update cachetools from 4.2.0 to 4.2.1 2021-03-03 13:00:05 +00:00
pyup-bot
8067ebdca5 Update sqlalchemy from 1.3.22 to 1.3.23 2021-03-03 13:00:05 +00:00
pyup-bot
49dac21739 Update pyjwt from 2.0.0 to 2.0.1 2021-03-03 13:00:05 +00:00
pyup-bot
b615f7192f Update marshmallow-sqlalchemy from 0.23.1 to 0.24.0 2021-03-03 13:00:04 +00:00
pyup-bot
e05ae8f413 Update iso8601 from 0.1.13 to 0.1.14 2021-03-03 13:00:04 +00:00
pyup-bot
6371975981 Update eventlet from 0.30.0 to 0.30.1 2021-03-03 13:00:03 +00:00
pyup-bot
d56430b3a8 Update flask-migrate from 2.5.3 to 2.7.0 2021-03-03 13:00:03 +00:00
pyup-bot
83c5a4f67c Update cffi from 1.14.4 to 1.14.5 2021-03-03 13:00:03 +00:00
Richard Baker
30eb98c140 Merge pull request #3164 from alphagov/cell_broadcast_ee_prod
Enable EE Cell Broadcasts in production environment
2021-03-02 09:46:23 +00:00
Richard Baker
2e4ac1f09c Enable EE Cell Broadcasts in production environment
Removes the configuration override for Live, so the base configuration is
used, enabling cell broadcasting for all MNOs.

Signed-off-by: Richard Baker <richard.baker@digital.cabinet-office.gov.uk>
2021-03-02 09:34:35 +00:00
Rebecca Law
08b157df87 Merge pull request #3162 from alphagov/change-dvla-addres-to-list
Change DVLA_EMAIL_ADDRESS to a list
2021-02-26 13:38:06 +00:00
Rebecca Law
3df334d099 Simplify config and add json loads 2021-02-26 12:19:03 +00:00
Rebecca Law
acfb759cb9 Change DVLA_EMAIL_ADDRESS to a list 2021-02-26 11:21:16 +00:00
Rebecca Law
b120b83cc7 Merge pull request #3157 from alphagov/persist-performance-data
Persist the processing time statistics to the database.
2021-02-26 09:09:41 +00:00
Rebecca Law
e105257925 Fix db migration merge conflicts 2021-02-26 08:38:36 +00:00