Commit Graph

63 Commits

Author SHA1 Message Date
Rebecca Law
ad14f96b8d A small change to make the code just a little bit clearer. 2019-10-17 15:17:43 +01:00
Pea Tyczynska
6ee7ac6cac Refactor and harmonise metadata for invalid letters with those sent from admin app 2019-10-16 14:11:50 +01:00
Pea Tyczynska
0a617379c4 Put pdf letter validation failed message in S3 metadata
So it can be used to tell the user why the letter has failed validation
2019-10-11 17:24:48 +01:00
Rebecca Law
a1863fa419 Update all calls to get_folder_name to include the parameter name.
Use created_at date of the notification for precompiled letters.
2019-09-25 14:40:09 +01:00
Pea Tyczynska
1279a46b8b Don't log address redaction failure when letter sent with test key 2019-09-17 15:55:26 +01:00
Leo Hemsted
99eb17fc29 Merge pull request #2610 from alphagov/get-pdf-contents-via-api
add api endpoint to get pdf for letter
2019-09-17 14:55:34 +01:00
Katie Smith
081543a2a9 Refactor out function to get page count
This has been moved to the letters utils file since it will be used in
more than one place. The notification parameter has been removed so that
the function can be used when we don't have a notification id.
2019-09-12 14:58:51 +01:00
Leo Hemsted
52f7620772 create pdfs for test templated letters
previously, we didn't create templated letters, and just marked them as
delivered straight away. However, we may need to return PDFs for these
letters, so we should create them the same as live letters. Then update
the functions so that they know where to look for these letters.
2019-09-11 15:02:12 +01:00
Pea Tyczynska
fecd7b5728 Copy original file tp redaction_failure folder when redaction fails 2019-09-10 15:10:18 +01:00
Pea Tyczynska
8460147dfa Handle both new and old response type from template preview's
sanitise endpoint

Fix tests so they accept new response handling
2019-09-06 13:18:21 +01:00
Katie Smith
3d01276ce2 Log exception and set precompiled letter to tech-failure if S3 errors
The `process_virus_scan_passed` task now catches S3 errors - if these
occur, it logs an exception and puts the letter in a `technical-failure`
state. We don't retry the task, because the most common reason for
failure would be the letter not being in the expected S3 bucket, in
which case retrying would make no difference.
2019-06-18 10:58:58 +01:00
Leo Hemsted
09888f7479 ensure cronitor decorator is inside the notify_task wrapper
the celery decorator should always be on the outside so that all other
decorators will be captured within the celery task. We had problems
with cronitor not reporting, and only for this task.
2019-06-03 11:46:07 +01:00
Toby Lorne
0022923bd0 Add Cronitor decorator collate-letter-pdfs-for-day
This celery task was not decorated with the cronitor decorator so never
checked in with cronitor.

Adding the decorator will ensure this task is monitored.

The requisite cronitor key is in the credentials repository already.

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2019-04-05 10:26:18 +01:00
Leo Hemsted
b288031adb add a hash of letter filenames to the dvla zip file name
if we partially retry a day, we would create new zip files, containing
different letters (if some were processed succesfully). We need these
files to have different filenames to earlier zip files so that we can
avoid overwriting log data in zips_sent.

Hashing the filename means that we'll only overwrite if it was the same
file containing the same content.
2019-03-21 15:40:24 +00:00
Leo Hemsted
334eb473ed separate batch num from date
DVLA don't care about the naming conventions of zip files, other than
it must start with `NOTIFY.` and end with `.ZIP`. So lets format the
date in a more readable way, and separate it from the batch number
2019-03-20 12:15:25 +00:00
Leo Hemsted
1a4baf4283 pass upload filename to notify-ftp
previously ftp would name the files itself by giving them a timestamp
when uploading. we ran into issues with tasks being picked up multiple
times and as such, uploading duplicate files. By naming the file before
creating the task, we can avoid this issue.

Files are now named `NOTIFY.YYYYMMDD######.ZIP` where the number is a
counter that increments with each task we've issued in that run of
collate-letter-pdfs-for-day
2019-03-19 13:48:17 +00:00
Leo Hemsted
653f1ab6b9 stub out antivirus in dev
antivirus is sometimes tough to get running locally - now in dev
antivirus is skipped unless `ANTIVIRUS_ENABLED=1` is set on the command
line. on all other environments it is always enabled.
2019-02-27 10:59:31 +00:00
Leo Hemsted
afc5c96927 Don't fallback to dvla_organisation if letter branding unset
The template preview app now accepts a null value for the `filename` 
parameter. If a service doesn't have a letter branding option set, 
previously we defaulted to their dvla_organisation (probably HM 
Government). Now, we pass through None, so that we generate letters 
without any logo or branding.
2019-02-13 11:58:54 +00:00
Rebecca Law
e4ea208d06 Use the letter_branding logo if it exists otherwise fall back to the dvla_organisation logo. 2019-01-23 12:51:09 +00:00
Katie Smith
a9b755b08c Move letters which can't be opened to invalid PDF bucket
If a precompiled letter can't be opened (e.g. because it isn't a valid
PDF) we were setting its billable units to 0, but not moving it to the
invalid PDF bucket. If a precompiled letter failed sanitisation, we were
moving it to the invalid PDF bucket but not setting its billable units
to 0.

This commit makes sure that we always set the billable units to 0
and move the PDF to the right bucket if it fails sanitisation or can't be
opened.
2019-01-11 16:59:07 +00:00
Katie Smith
e9fb60f05c Send extra headers to Template Preview /precompiled/sanitise endpoint
We want to send two new headers, ServiceId and NotificationId to the
template preview /precompiled/sanitise endpoint. This is to allow us to log
errors from this endpoint in template preview with all the information needed,
instead of needing to pass the information back to notifications-api and
to log it there.
2018-12-19 13:49:27 +00:00
Rebecca Law
b2d12e6609 Merge pull request #2171 from alphagov/update-page-count-after-antivirus-scan
Update page count after antivirus scan
2018-10-25 11:11:59 +01:00
Rebecca Law
12d938b82b Merge branch 'master' into update-page-count-after-antivirus-scan 2018-10-24 15:13:11 +01:00
Rebecca Law
1cc2d26586 Explicitly set the billable units for update_letter_pdf_status 2018-10-24 14:50:50 +01:00
Rebecca Law
537ab2e965 Fix merge error.
Moved the billable unit calculation before the santise call.
2018-10-24 14:38:09 +01:00
Katie Smith
022b5b19ff Stop passing dvla_org_id to template preview
We were passing both dvla_org_id and filename to template-preview
temporarily while we switch to only using filename. Now that
template-preview is set up to use the filename, we can stop sending the
dvla_org_id too.
2018-10-23 15:52:44 +01:00
Leo Hemsted
bc3fab09d0 don't log exception info for retries
it includes task args, which might contain PII. And we don't need to
know where the retry exception came from - it came from the line above
2018-10-22 11:33:16 +01:00
Alexey Bezhan
5d91ba80fb Merge pull request #2170 from alphagov/reduce-logging-for-sanitise
Reduce the error logging for sanitse method
2018-10-19 14:40:50 +01:00
Katie Smith
4dab4fa8ce Pass letter logo filename to template preview
We now pass `filename`, the filename of the letter logo to use, through
to Template Preview in addition to the `dvla_org_id`. Once Template
Preview has been updated to only use the `filename` we will stop
sending the `dvla_org_id`.
2018-10-19 10:07:11 +01:00
Rebecca Law
02154f5fc0 Actually I decided we don't need an exception log here. 2018-10-18 16:46:04 +01:00
Rebecca Law
38c29d41a4 Reduce the error logging for sanitse method, since we ignore cysp.
Also fixed the spelling error, why not.
2018-10-18 16:43:14 +01:00
Rebecca Law
021a90f482 Merge branch 'master' into update-page-count-after-antivirus-scan 2018-10-18 16:01:59 +01:00
Leo Hemsted
e7dad9436f compare service id to UUID
it doesn't match a string 😩
I couldn't think of a good way to test this in a unit test, since
it involves changing the service id on all of the components of a
service.
2018-10-18 12:19:10 +01:00
Leo Hemsted
7bf68e3664 fix failed sanitise flow
the move from virus scan to validation failed function was called with
the wrong variables, and had some internal logic that was slightly
wrong.

Also, Don't use `update_notification_by_id` for notifications if they
are not in `created`, `sending`, `pending`, or `sent`. It silently
doesn't update them. I didn't want to do a deeper investigation into
the reasons behind this terrifying state machine as part of this commit
so I just changed the functions to call `dao_update_notification`
manually
2018-10-16 17:30:39 +01:00
Leo Hemsted
9606513e1f exclude CYSP from sanitise
we know their content is already good, but they slightly exceed the
margins. Until they deploy their fixed template, lets not valiate them
2018-10-16 17:30:39 +01:00
Pea Tyczynska
e22e7245fe Use sanitised pdfs for sending and handle invalid pdfs, details below:
- pass new, sanitised pdf for sending
- move invalid pdfs to a newly created bucket
- set status fro notifications that failed pdf validation to a new status validation-failed
- adjust existing tests
2018-10-16 17:30:35 +01:00
Rebecca Law
4263117189 We were getting the page count for the letter before virus scan happened.
This PR moves setting the billale_units for the letter after virus scan has passed.
2018-10-16 15:08:15 +01:00
Rebecca Law
a30ed976f4 Added an info log message when the precompiled pdf is successful. This is because we can't tell when the letters are passing. 2018-09-18 17:46:19 +01:00
Rebecca Law
f1b04193ca In this PR we remove trigger-letter-pdfs-for-day scheduled task and just call collate_letter_pdfs_for_day instead.
There was a datetime bug in the query which resulted in files not being sent to the postal provider.
The trigger-letter-pdfs-for-day task is no longer needed, so rather than fix the query just call collate_letter_pdfs_for_day directly.
Less code is always better.

Deployment considerations: I realized this is strictly not backwards compatible if the scheduled job is in progress and a task is on the queue that no longer exists. This is ok since we will deploy this well before 17:50.
2018-09-12 17:16:34 +01:00
Alexey Bezhan
18ab7f3337 Add updated history count to dao_update_notifications_by_reference
For returned letter updates most notifications won't exist in the
notifications table, so in order to find out whether the reference
matches any known letters we need to check the count of updated
history records.
2018-09-04 16:55:22 +01:00
Leo Hemsted
40c537a9f5 add tests 2018-08-24 15:12:02 +01:00
Leo Hemsted
001f84b0b8 Sanitise PDFs after virus scan
Notify antivirus, on success, calls the process_virus_scan_passed taks.
Previously, this task would:

* update status to created (or delivered for test keys)
* copy the file from the scan bucket to either the live or test bucket
  based on the results
* delete the old file in the scan bucket

We want it to:

* download file from scan bucket
* sanitise PDF using new template-preview functionality
* if sanitise failed, set to new status "validation-failed" and save
  the pdf somewhere.
* send new pdf to live/test bucket
* update status to created (or delivered for test keys)
* delete the original file in the scan bucket

This PR does some of that:

* download file from scan bucket
* sanitise PDF using new template-preview functionality
* if sanitise failed, just log.
* send OLD pdf to live/test bucket
* update status to created (or delivered for test keys)
* delete the original file in the scan bucket

So if sanitising fails, we won't fall over and not deliver the letter,
we'll just log a message for now. If sanitise throws an unexpected
error (as opposed to a 400), we'll retry up to fifteen times (the same
as when creating a new letter). I've added the code for using the
sanitised pdf, but it's commented out for now
2018-08-23 16:16:40 +01:00
Rebecca Law
5850663ca6 Added a method to reply letters that are in the error folder on S3.
You can replay one at a time by sending in the file name. Or all the messages in the error folder.
2018-06-27 16:40:30 +01:00
Richard Chapman
f1abce22ae Logging refactor to make debugging easier. Before the filename needed to
be known. Added the notification id to the logging message so that
the notification can be traced through the logging system by knowing
the notification id, making it easier to debug. Also changed to raise an
exception so that alerts are generated. This way we should get an email
to say that there has been an error.
2018-04-03 12:31:52 +01:00
Richard Chapman
8b6d28d3b0 Added a new task to handle any error cases with the anti-virus
application. If the Anti-virus app fails due to s3 errors or ClamAV
so does not scan (even after retries) the file at all an error needs
to be raised and the notification set to technical-failure.

Files should be moved to a 'folder' a separate one for ERROR and FAILURE.

* Added new letter task to process the error
* Added a new method to letter utils.py to move a file into an error or
failure folder based on the input
* Added tests to test the task and the utils.py method
2018-03-26 14:18:44 +01:00
Ken Tsang
2f09c943f7 Change error log to exception log for pdfs failing virus scans 2018-03-23 14:24:23 +00:00
Ken Tsang
0ee5c33084 Add antivirus check on precompiled letters sent with test key
- precompiled PDFs sent by test key uploaded to scan bucket
- set status to VIRUS-SCAN-FAILED for pdfs failing virus scan rather than PERMANENT-FAILURE
- Make call to AV app for precompiled letters sent via a test key, and set notification status to PENDING-VIRUS-SCAN
2018-03-23 12:04:37 +00:00
Ken Tsang
5481d743ac change failed virus scan log to error 2018-03-21 15:30:58 +00:00
Ken Tsang
8391353113 Update tasks in line with AV app 2018-03-20 14:56:42 +00:00
Ken Tsang
b1ac580e0a Add celery tasks to handle virus scan passing and failing 2018-03-20 10:12:59 +00:00