Commit Graph

30 Commits

Author SHA1 Message Date
Ryan Ahearn
aa3043e8df Remove direct use of aws creds from deployed environments 2023-02-01 11:57:59 -05:00
stvnrlly
40368fe819 Merge branch 'main' into stvnrlly-paperless 2022-12-09 12:33:16 -05:00
stvnrlly
b6bc02eb6b us → u.s. 2022-12-06 11:03:47 -05:00
stvnrlly
944715ac46 big commit with letters removal 2022-12-05 15:33:44 -05:00
Ryan Ahearn
921c872bd1 Refactor method of retrieving credentials out of VCAP_SERVICES 2022-10-20 08:36:30 -04:00
Ryan Ahearn
5f1a1f083a Proactively specify aws region for s3 operations 2022-09-26 10:25:03 -04:00
Ryan Ahearn
a90dcc918b Provide s3 credentials for each individual bucket 2022-09-23 12:59:55 -04:00
James Moffet
68365f8b08 comments and logs 2022-07-26 11:45:27 -07:00
James Moffet
1a204ae872 remove extra logs 2022-07-26 11:39:00 -07:00
James Moffet
4c25a81004 disable cache until we can fix on cloud deployment 2022-07-26 11:17:43 -07:00
James Moffet
e53d12733a branding 2022-07-20 15:23:54 -07:00
Chris Hill-Scott
2a62586799 Reflect change in argument name
`filename_or_fp` was changed to `path_or_file` here:
https://github.com/pallets/flask/pull/3828/files#diff-1f51c8ded4d4ff7e13badab599ef22436c529c2b5f9c25dc6250c1f9fd985440R479
2022-06-06 12:12:52 +01:00
Ben Thorner
4fef2861c6 Catch error if letter does not exist on send
This repeats the pattern we already have for previewing a letter,
where we assume the error is because the notification has already
been sent and redirect the user to see it.

I've improved the original pattern a bit:

- I've DRYed-up the low-level boto code and moved the error handler
there so it can be reused.

- I've introduced a custom exception, which the calling code can
choose to log.

- I've introduced the moto library, which we use elsewhere, to make
it easier to test S3 code.

I've used an error level log when sending a notification - now that
we have a more descriptive log, we can verify the assumption is true
and then make an informed decision to downgrade the log.

In future we may want to merge this handler with the similar code
in utils [1], but we'll need to be careful as the utils handler is
superficial - it doesn't check the reason for the error.

[1]: bce0f4e596/notifications_utils/s3.py (L52)
2022-02-18 14:52:27 +00:00
Ben Thorner
b3f48c1a84 Backup original precompiled uploads to S3
This continues the work from Template Preview [1], so that we have
a complete store of original PDFs to use for testing changes to it.

Previously we did store some originals, but these were only invalid
PDFs that had failed sanitisation; for valid PDFs, the "transient"
bucket only contains the sanitised versions, which the API deletes
/ moves when the notification is sent [2].

Since the notification is only created at a later stage [3], there's
no easy way to get the final name of the PDF we send to DVLA. Instead,
we use the "upload_id", which eventually becomes the notification ID
[4]. This should be enough to trace the file for specific debugging.

Note that we only want to store original PDFs if they're valid (and
virus free!), since there's no point testing changes with bad data.

[1]: https://github.com/alphagov/notifications-template-preview/pull/545
[2]: c44ec57c17/app/service/send_notification.py (L212)
[3]: 7930a53a58/app/main/views/uploads.py (L362)
[4]: 7930a53a58/app/main/views/uploads.py (L373)
2021-06-24 12:21:05 +01:00
Katie Smith
e074fb0631 Delete unused function 2020-10-29 13:53:50 +00:00
David McDonald
387fcfda3f Move recipient decoding into LetterMetadata class
This is for consistency with how we do it for filenames in the previous
commit and moves the decoding into the `LetterMetadata` class for
abstracting this behaviour.

Small refactor of the LetterMetadata class needed to handle None case as
recipient can be None.
2020-05-18 16:13:31 +01:00
David McDonald
7923760345 Ensure pdf letter filename is ascii encoded and decoded
S3 can only handle ascii characters, therefore for filename which could
include non ascii characters, for example a filename with the character
'£' in it, we must encode these using urllib before saving it as s3
metadata. We then also make sure that it comes back decoded when
presenting it to the user.
2020-05-18 16:13:31 +01:00
David McDonald
ba80d5b7cd Introduce abstraction for s3 metadata
S3 metadata only supports ascii characters. Whenever we save data to it
we need to make sure we encode it to save it and then decode it to
display it again to users. This abstraction will act as the place for
that decoding to happen so the rest of the code in our views doesn't
need to care about the encoding abstraction.
2020-05-18 16:13:31 +01:00
Chris Hill-Scott
03f2368deb Use the correct bucket for storing contact lists
We don’t want to muddy them up with the normal CSV uploads.

I’ve tried to reuse the existing S3 code where possible because it’s
well tested.

Buckets have already been created.
2020-03-16 13:07:39 +00:00
Chris Hill-Scott
1c02476ee7 Let users upload a contact list to use later
We increasingly have teams wanting to do business-continuity type
messaging. They might be without access to their normal systems, which
is where they would otherwise go to get the list of email addresses or
phone numbers.

So we want to give them a place in Notify where they can store their
spreadsheets and use them at a later date.

For the initial pass we’re going to scope this to only allowing
spreadsheets with one column, ie just phone numbers/email addresses.
This is because:
- it minimises the amount of personal info we’re storing
- it reduces the chance of getting a placeholder error when you go to
  send the message, which is probably a high-stress situation where you
  might not be able to re-generate the file

The code for this is mostly copied from the existing upload CSV journey.
It’s quite duplicative, but that’s what I needed to do to get this out
quickly. There are opportunities for refactoring later.

Similarly, I would have liked to split this up into better commit
messages, but it really was a case of just bashing code out until it
worked 😳

This commit does not:
- implement the ‘view a contact list page’ (it just has a placeholder
  because the API isn’t ready at the moment)
- link to this page (because it’s not ready to use yet)
2020-03-16 13:07:28 +00:00
Leo Hemsted
a3ccd9660b don't convert letter logo svgs to pngs
https://github.com/alphagov/notifications-template-preview/pull/371
stops using png logos when rendering png previews of templated letters.

when that is merged we no longer need to convert to pngs when we upload
a new letter logo.
2020-03-02 18:00:26 +00:00
Rebecca Law
f8e7635a1d Show the first line of the address from the to field.
Now persisting the address to the "to" field of the Notification, after the notification has been validated.
If the letter is pending validation, then "Checking..." will appear as the identifier for the letter.
If the letter has passed validation, then the first line of the address (now persisted in the "to" field) will be displayed, with the client reference underneath.
If the letter has failed validation the "Provided as PDF" will show be displayed, which is now the initial value of the "to" field.
2020-01-10 16:00:40 +00:00
Katie Smith
a542047581 Show recipient when about to send uploaded letter
The recipient of the letter now displays at the bottom of the page when
previewing a valid letter. The template preview `/precompiled/sanitise`
endpoint returns the address, but we format it to display on a single
line with commas between each line. We also need to convert the
recipient address to ASCII so that it can be stored as S3 metadata.
2019-11-08 10:17:11 +00:00
Katie Smith
3223956ba2 Allow extra metadata fields when uploading letter to S3 2019-10-21 08:37:55 +01:00
Katie Smith
11543e15be Store all data about uploaded letters in the S3 metadata
We had been storing whether or not a file was valid in the S3 metadata,
but using the query string of the URL to store the original filename
and the page count. This meant that if you tried to view the preview
letter page without the query string you would see a `500`. It was
possible for this to happen if you were signed out of Notify while on
the preview page - you would be redirected back to the preview page but
without the query string, causing an error.
2019-10-08 15:34:00 +01:00
Katie Smith
7368245c9a Show letter preview once file is uploaded
This shows the sanitised letter preview if the file had no validation
errors or the preview with the overlay if it failed validation.
2019-09-12 09:54:36 +01:00
Katie Smith
8a322b844b Sanitise uploaded letters and store in S3
This sanitises uploaded letters and stores the sanitised result in S3
with if it passes validation or the original PDF in S3 if validation
fails. A metadata value of 'status' is set to either 'valid' or
'invalid'.
2019-09-12 09:54:36 +01:00
Katie Smith
529d7df5f5 Add page to create new letter branding
This has a form with 3 fields - the file upload field, logo name, and an
optional logo domain. Logos need to be uploaded in `.svg` format and we
then convert this to `.png` format and upload both file types to S3 as
well as saving the letter branding details in the database.
2019-02-06 17:26:58 +00:00
Katie Smith
d654a87f5c Rename the current s3 logo client functions
We will be adding methods to deal with letter logos, so this adds 'email' to
the method names for email logos to avoid confusion later.
2019-02-06 17:26:58 +00:00
Katie Smith
f005d7a569 Refactor to split s3_client.py into multiple files
Separated s3_client.py into 3 files - for logos, CSV files and the MOU.
This helps to keep things clearer now that we need to add lots more logo
functions for letters.
2019-02-06 17:26:58 +00:00