Commit Graph

3470 Commits

Author SHA1 Message Date
Leo Hemsted
7fe075393d fix timezone related cancel letter job bug 2020-04-14 14:32:36 +01:00
Chris Hill-Scott
36e61272c5 Save the first non-empty line as recipient
Since we now allow the address to be populated from any three lines, we
can’t guarantee that the recipient will be in the `addressline1` field.
2020-04-09 18:19:53 +01:00
Chris Hill-Scott
7032bac178 Start allowing any three lines in addresses
This is part of moving away from `postcode` and towards `address line 7`

We think it will be easier for people to map their existing data to our
API if we let them fill in any 3 lines, instead of requiring at least
1, 2, and postcode specifically.
2020-04-09 18:19:53 +01:00
Chris Hill-Scott
264fbed04e Refactor postcode validation to use utils
We don’t need to reformat the postcode here once template preview takes
care of it when rendering the PDF.

It’s better (and less code) to store what people give us, so we give
them back the same thing.
2020-04-09 18:19:53 +01:00
Katie Smith
4fd74af3bd Revert "Update postage db constraints for international letters" 2020-04-08 10:53:51 +01:00
Katie Smith
f0c5463440 Merge pull request #2747 from alphagov/update-postage-constraint
Update postage db constraints for international letters
2020-04-08 08:23:43 +01:00
Chris Hill-Scott
054cd16d02 Ensure correct object renders V2 template preview
The `body` field of the ‘preview a template’ endpoint should contain the
content of the template with the placeholders replaced.

It should not be rendered into a plain text email, which does stuff like
normalising newlines (so `\r\n` becomes `\n`). However the object that
the `create_post_template_preview_response` function receives is an
instance of `PlainTextEmailTemplate`. So we can’t just call `str()` on
it. Instead we need to call the `__str__` method of
`WithSubjectTemplate` which gives us the result we want.

We were already doing this the right way in the V1 endpoint[1] but
forgot to do it here too.

1. 0108749daa/app/template/rest.py (L181-L184)
2020-04-07 17:09:59 +01:00
Chris Hill-Scott
0108749daa Merge pull request #2795 from alphagov/extract-placeholders-from-all-parts-of-letter-template
Look in all parts of a letter template to find placeholders
2020-04-07 15:20:43 +01:00
Chris Hill-Scott
025ac3ea89 Use same template to validate and send notification
To be absolutely sure that we can send a message we should also validate
it using the same template class that we use to render it.
2020-04-07 10:41:16 +01:00
Chris Hill-Scott
8c8c8b6328 Look in all parts of a letter template to find placeholders
Text messages have placeholders in their body.

Emails have them in their subject line too.

Letters have them in their body, subject line and contact block.

We were only looking in the the body and subject when processing a job,
therefore the thing assembling the letter was not looking in all the
CSV columns it needed to, because it hadn’t been told about any
placeholders in the contact block.

Fixing this means always making sure we use the correct `Template`
instance for the type of template we’re dealing with. Which we were
already doing in a different part of the codebase. So it makes sense to
reuse that.

Turns out we fixed the same bug for email subjects over 3 years ago:
3ed97151ee
2020-04-07 10:41:16 +01:00
Katie Smith
e2effb6ee1 Update JSON schema postage validation for new values 2020-04-07 08:01:11 +01:00
Leo Hemsted
9673619519 Update provider splits
also fix tests so they're independent of future config changes
2020-04-06 15:16:00 +01:00
Katie Smith
e386d2ac38 Merge pull request #2792 from alphagov/delete-old-letter-task
Delete old 'process-virus-scan-passed-task'
2020-04-03 09:35:35 +01:00
Katie Smith
6ac89c9a2f Delete old 'process-virus-scan-passed-task'
This has been replaced by a new task, `sanitise-letter`, to this deletes
all the code in the old task and ensures that when antivirus is not
enabled locally we are calling the new task.
2020-04-02 14:52:15 +01:00
Katie Smith
62b11bc61e Delete delete_dvla_response_files_older_than_seven_days task
This was not being used.
2020-04-02 14:49:47 +01:00
Katie Smith
bfd40a843c Delete send-scheduled-notifications task
This was added a few years ago, but never used.
2020-04-02 14:45:18 +01:00
David McDonald
98d8388805 Add runbook link to ticket 2020-04-02 09:42:46 +01:00
David McDonald
b28fffc330 Refactor raise_alert_if_letter_notifications_still_sending
Move finding of letter logic into a separate method so it can be unit
tested rather than having to test it by checking the contents of a
zendesk ticket api call.

This will enable us to change the zendesk api ticket call message
without needing to edit lots of tests.
2020-04-02 09:36:56 +01:00
Pea Tyczynska
f8286fdd21 Add missing freezetime to a test 2020-04-01 11:53:13 +01:00
Pea M. Tyczynska
cff7f7b72d Merge pull request #2751 from alphagov/validate-and-format-postcode-api-flow
Validate and format postcode for the API letter sending flow.
2020-04-01 11:09:25 +01:00
Rebecca Law
a7a158fe69 Merge pull request #2784 from alphagov/add-team-key-to-query
Add team key to query
2020-03-31 17:13:42 +01:00
Katie Smith
113ab4805f Merge pull request #2775 from alphagov/task-retries
Add retries to process_sanitised_letter task
2020-03-31 15:39:31 +01:00
Pea M. Tyczynska
401c8e41d6 Merge pull request #2779 from alphagov/change-error-code
Change error code for duplicate reply-to address to 409 meaning conflict
2020-03-31 14:48:56 +01:00
Rebecca Law
1444150d48 Add team key to the notifications to delete/insert into notifications/notification_history 2020-03-31 09:23:41 +01:00
Leo Hemsted
885f3122bd fix purge functional test data task
* it doesn't delete service email reply to or letter contacts, or
  contact lists. I don't think the contact lists will ever be an issue
  but it doesn't hurt to add it to the list of things to remove.
* it doesn't remove users from organisations before deleting the users

there may be more tables that link to Service that should be deleted,
but for now just add these ones that I could spot.
2020-03-30 17:45:29 +01:00
Katie Smith
8b8e736e49 Add retries to process_sanitised_letter task
This task didn't have retries before, based on the assumption that if
the task failed it was likely to be due to a Boto error, so retrying
would not help because a file was probably not in the expected bucket.
During an incident with the database, we had some letters that were
stuck in the `pending-virus-check` state because this task failed.

This change adds retries to the task if there was an Exception that was
not a `BotoClientError`.
2020-03-30 17:28:01 +01:00
Pea Tyczynska
0250bee1a0 Change error code for duplicate reply-to address to 409 meaning conflict 2020-03-30 17:16:55 +01:00
David McDonald
c1ba3fb1be Merge pull request #2777 from alphagov/add-runbook-link
Add runbook link to resolve letters pending virus scan
2020-03-30 13:50:30 +01:00
David McDonald
87cb02fa1d Add runbook link to resolve letters pending virus scan 2020-03-30 12:07:05 +01:00
Leo Hemsted
0b3d711652 if message too big to put on high volume queue then save to queue
SQS fails if the message body is over 256kb. Normally our messages are
quite small, but if we're using the new save-api-email task with an
email that has a large body, we can get over that limit. If so, handle
the exception and fall back to the existing code path (saving to the
database and sending a deliver-email task, which only has a notification
id.
2020-03-28 09:55:31 +00:00
Rebecca Law
c81388d004 Merge pull request #2774 from alphagov/fix-report-and-delete-tasks
Fix report and delete tasks
2020-03-27 16:30:16 +00:00
Rebecca Law
5d0830d7f7 Rename function for clarity 2020-03-27 15:48:54 +00:00
Chris Hill-Scott
4aed012d92 Merge pull request #2759 from alphagov/delete-contact-list
Add an endpoint to delete a contact list
2020-03-27 14:50:51 +00:00
Rebecca Law
46b72a6bbb Refactor process_ses_receipt
It is possible a service has data rention that is smaller than the time it takes to get a delivery receipt.
This PR refactors process_ses_receipt to update NotificationHistory if the Notifcation has already been purged.
2020-03-27 14:12:39 +00:00
Chris Hill-Scott
14605764bd Add comment explaining test data 2020-03-27 13:41:32 +00:00
Rebecca Law
8da73510c2 Delete all notification_status types.
This will ensure the whole day has been deleted. The stats table could get the wrong updates if there is partial data for a day.
2020-03-27 12:14:30 +00:00
Chris Hill-Scott
5fe0fafadf Archive, don’t delete contact lists
So we keep a record of who first uploaded a list it’s better to archive
a list than completely delete it.

The list in the database doesn’t contain any recipient info so this
isn’t a change to what data we’re retaining.

This means updating the endpoints that get contact lists to exclude ones
that are archived.
2020-03-27 09:51:54 +00:00
Rebecca Law
dc44cb29d1 To make the deployment and testing a little easier move the high volume service ids to the credential repo.
This way we can only add the ids when we are ready and all the infrastrure for the new service has been applied.
2020-03-27 08:02:51 +00:00
Chris Hill-Scott
4a6143aeb1 Remove the list from S3 once we don’t need it
Once a contact list is gone from the database there’s no way to
reference it again. Any jobs have made their own copy.

So we can clean it up, meaning we’re not storing personal data longer
than we need to.
2020-03-26 17:42:38 +00:00
Chris Hill-Scott
b50dbab8fd Add an endpoint to delete a contact list
This was one of things we de-scoped when we first shipped this feature.

In order to safely delete a list, we first need to make sure any jobs
aren’t referencing it.
2020-03-26 17:42:38 +00:00
Rebecca Law
a801230fc4 Added test that the notification exists or not 2020-03-26 11:18:59 +00:00
Rebecca Law
db4b4d929d - If the task runs twice and the notification already exists ignore the primary key constraint.
- Remove prints
- Add some more tests
- Only allow the new method to run for emails
2020-03-25 12:39:15 +00:00
Rebecca Law
a13bcc6697 Reduce the pressure on the db for API post email requests.
Instead of saving the email notification to the db add it to a queue to save later.
This is an attempt to alleviate pressure on the db from the api requests.
This initial PR is to trial it see if we see improvement in the api performance an a reduction in queue pool errors. If we are happy with this we could remove the hard coding of the service id.

In a nutshell:
 - If POST /v2/notification/email is from our high volume service (hard coded for now) then create a notification to send to a queue to persist the notification to the db.
 - create a save_api_email task to persist the notification
 - return the notification
 - New worker app to process the save_api_email tasks.
2020-03-25 07:59:05 +00:00
Rebecca Law
69102db4cb Remove the hourly loop and replace it with a while loop, which check if we still have things to delete for the day.
We are already limiting the query by a query limit.
2020-03-24 14:54:06 +00:00
Rebecca Law
3ca73a35ed Change as per code review
- fix test name
 - make query filter consistent with each other
 - add comment for clarity
 - add inner loop to continue to insert and delete notifications while the delete count is greater than 0
2020-03-24 14:17:47 +00:00
Rebecca Law
f04210ba7d Refactor delete_notifications_older_than_retention_by_type to use a new strategy.
The insert_notification_history_delete_notifications function uses a temp table to store the data to insert and delete. This will save extra queries while performing the insert and delete operations.
The function is written in such a way that if the task is stop while processing when it's started up again it will just pick up where it left off.

I've made a decision to delete all test data in one query, I don't anticipate a problem with that.

The performance of this might also be better than last nights test because we are inserting everything we need for the NotificationHistory insert, so we don't need the join to Notifications to perform the insert.
2020-03-24 12:21:28 +00:00
Rebecca Law
80845e1abb Transaction to insert history and delete notifications.
Need to test the performance of this function, then we can call it from the task.
- Create a temporary table to insert ids of the desired rows, limit by 10K (might be too low).
- Insert into NotifcationHistory select from notification where id in temp table
- Delete from Notifications where id in temp table
- drop temp table

We should be able to iterate of this. The query stats for the query to create the temp table are very good, 17ms.
2020-03-23 16:33:06 +00:00
Pea M. Tyczynska
d80fef8fe8 Update postcode validation error message 2020-03-19 14:40:26 +00:00
Pea Tyczynska
24cfde3410 Validate and format postcode for the API letter sending flow. 2020-03-19 14:23:39 +00:00
Katie Smith
24b77726f4 Add a task to process sms callback from our providers
This runs on the new `sms-callbacks` queue. The function
`process_sms_client_response` has been replaced with a task called
`process_sms_client_response`. This involved some reorganisation of the
existing code and tests.
2020-03-19 13:41:14 +00:00