mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 08:25:15 -05:00
Mark letters as validation-failed if the templated letter is too long.
It is possible that the personalisation for a templated letter can make the letter exceed 10 pages or 5 sheets. We are not validating the letters posted via the API for this validation error. It is only possible to validate the letter once we create the PDF in notifications-template-preview. This means that the letter can only get a validation-failed status after the client has received a 201 from the POST to /v2/notifications.
NOTE: we only validate the preview row of a CSV for this validation error, this change will mean that it is possible for a letter to be marked as validation-failed after a successful file upload.
A new task to update the notification to `validation-failed` has been added to the API. If we find that the letter is too long once we have created the PDF we call the `update-validation-failed-for-templated-letter` task rather than `update-billable-units-for-letter` task.
New work flow for a letter in brief:
API - receives POST /v2/notifications
:: save to db
:: put CREATE_LETTERS_PDF task on queue for template preview to consume
TEMPLATE-PREVIEW - consumes task CREATE_LETTERS_PDF
:: create PDF
:: count pages of PDF
:: IF page count exceeds 10 pages
put in the letters-invalid-pdf S3 bucket with metadata (similar to the precompiled letters)
put `update-validation-failed-for-templated-letter` task on the queue for the API to consume
ELSE
put PDF in the `letters-pdf` bucket
put `update-billable-units-for-letter` task on the queue
API - consumes `update-billable-units-for-letter` OR `update-validation-failed-for-templated-letter` task
:: IF `update-billable-units-for-letter` task:
update billable units for notification as usual
:: ELSE `update-validation-failed-for-templated-letter`:
update notification_status = `validation-failed`
ADMIN - view notification page for letter
:: show validation letter for templated letter
There will be 3 PRs in order to make this change, one for the API, template-preview and the admin app.
Deployment plan
Deploy Admin first
Deploy API
Deploy template-preview
Related PRs:
alphagov/notifications-template-preview#619
alphagov/notifications-admin#4107
https://www.pivotaltracker.com/story/show/169209742
This commit is contained in:
@@ -296,7 +296,7 @@ def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_d
|
||||
'development',
|
||||
'preview',
|
||||
])
|
||||
def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_sending_and_sends_fake_response_file(
|
||||
def test_post_letter_notification_with_test_key_creates_pdf(
|
||||
notify_api, client, sample_letter_template, mocker, env):
|
||||
|
||||
data = {
|
||||
@@ -312,8 +312,6 @@ def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_s
|
||||
}
|
||||
|
||||
fake_create_letter_task = mocker.patch('app.celery.letters_pdf_tasks.get_pdf_for_templated_letter.apply_async')
|
||||
fake_create_dvla_response_task = mocker.patch(
|
||||
'app.celery.research_mode_tasks.create_fake_letter_response_file.apply_async')
|
||||
|
||||
with set_config_values(notify_api, {
|
||||
'NOTIFY_ENVIRONMENT': env
|
||||
@@ -323,7 +321,6 @@ def test_post_letter_notification_with_test_key_creates_pdf_and_sets_status_to_s
|
||||
notification = Notification.query.one()
|
||||
|
||||
fake_create_letter_task.assert_called_once_with([str(notification.id)], queue='research-mode-tasks')
|
||||
assert fake_create_dvla_response_task.called
|
||||
assert notification.status == NOTIFICATION_SENDING
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user