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)
This commit is contained in:
Ben Thorner
2021-06-22 12:28:46 +01:00
parent 7930a53a58
commit b3f48c1a84
5 changed files with 60 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ from app.main import main
from app.main.forms import CsvUploadForm, LetterUploadPostageForm, PDFUploadForm
from app.models.contact_list import ContactList
from app.s3_client.s3_letter_upload_client import (
backup_original_letter_to_s3,
get_letter_metadata,
get_letter_pdf_and_metadata,
get_transient_letter_file_location,
@@ -216,6 +217,11 @@ def upload_letter(service_id):
filename=original_filename,
recipient=recipient)
backup_original_letter_to_s3(
pdf_file_bytes,
upload_id=upload_id,
)
return redirect(
url_for(
'main.uploaded_letter_preview',