Commit Graph

105 Commits

Author SHA1 Message Date
Rebecca Law
6da552a00b Added a message before the error description, to explain that it's the input arguments that have caused a problem. 2018-07-03 09:41:02 +01:00
Rebecca Law
13155e24dc We are getting 500 errors when a POST notification has characters that can not be decoded or the json is malformed.
The exception is wrapped and a sensible error message is returned to the client.
2018-07-03 09:04:33 +01:00
Alexey Bezhan
c189f09687 Update template content values from notification personalisation
We need to set template_with_content placeholder values with an
updated personalisation dictionary after processing the document
uploads in order to avoid returning base64 file data instead of
the document URLs in the response contents.
2018-04-09 16:30:16 +01:00
Alexey Bezhan
b097a16a86 Handle and log document-download-api request errors
Catches the requests exception for document-download-api calls, logs
a warning and returns a matching response code and message.

Connection errors to document download result in 503 response to the
user.
2018-04-09 16:30:16 +01:00
Alexey Bezhan
f2e163dc43 Upload files from personalisation data to document download
Adds support for a new personalisation value type: file upload.

File uploads are represented as a dictionary with a "file" key and
a base64-encoded file data as the key's value:

```
personalisation={
  'field1': {'file': '<base64-encoded file contents>'}
}
```

Post notification endpoint checks the request personalisation data
looking for the file uploads in personalisation data. If any are
found and the service has permissions to upload documents the files
are sent to document download API and personalisation values are
replaced with the URLs returned in the document download response.

A fake document URL is returned for simulated notifications, no
documents are stored in Document Download.

Multiple files can be uploaded for one notification by providing
a file upload in more than one personalisation field.
2018-04-09 16:30:16 +01:00
Rebecca Law
b73bf4220f Refactor process_letter_notification to make the code easier to read.
- Separated the logic of precompiled and template letters.
- Remove the check for research mode, research mode is not relevant to api calls. The test key is used for testing.
Refactor upload_pdf_letter to accept a precompile boolean to save a query to template.
2018-04-09 13:56:44 +01:00
Rebecca Law
3c92f00fdb Revert "Fix research mode preview of precompiled letters" 2018-04-06 16:10:06 +01:00
Rebecca Law
39e4f63b8c Use the positive condition when checking the environment 2018-04-06 12:01:16 +01:00
Ken Tsang
8b35c1c007 Fix research mode preview of precompiled letters 2018-04-03 22:52:45 +01: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
65733a30a1 Add send_task to antivirus app for scanning precompiled letters 2018-03-20 10:12:59 +00:00
Ken Tsang
30e371fa4c Set precompiled letters to pending virus check initially 2018-03-20 10:11:36 +00:00
Richard Chapman
2a3095d5c5 Merge pull request #1770 from alphagov/Update_notifification_response_for_precompiled
Update notification response for precompiled
2018-03-16 14:00:39 +00:00
Ken Tsang
d3537cca74 Add upload pdf to test-letters bucket
- triggered when sending a precompiled letter using a test key
2018-03-14 18:16:43 +00:00
Richard Chapman
0c775314bd Updated the precompiled response to only include the notification id
and the client reference. It could confuse the client consumer so best
to remove it from the response altogether.

* Respond with only the notification_id and client_reference
* Updated the test to check for the response without the template
2018-03-14 14:01:08 +00:00
Richard Chapman
f3cca07d19 Updated the precompiled response to not include the template.
The template in precompiled is only used internally and cannot be
accessed from the UI. It could confuse the client consumer so best to
remove it from the response altogether.

* Remove the template from the dict before returning it and therefore
ensuring it still stays similar to letter
* Updated the test to check for the response without the template
2018-03-14 13:16:55 +00:00
Katie Smith
bc619efc4e Count the number of pages in pre-compiled letters
We were already counting the billable units in PDFs that we generate.
We are now also counting the number of billable units in pre-compiled letters
and saving the result.
2018-02-28 16:14:25 +00:00
Alexey Bezhan
d803b48d23 Return 400 response for invalid per-compiled letter content 2018-02-23 17:52:25 +00:00
Alexey Bezhan
bef91bcd99 Check for precompiled letter permission in the post notification 2018-02-23 17:52:25 +00:00
Alexey Bezhan
8971a5adce Upload pre-compiled letter PDF to S3
Pre-compiled letter endpoint uploads PDF contents to S3 directly
instead of creating a letter task to generate PDF using template
preview.

This moves some of the utility functions used by existing letter
celery tasks to app.letters.utils, so that they can be reused by
the API endpoint.
2018-02-23 17:52:25 +00:00
Alexey Bezhan
5327298371 Add a view function for pre-compiled PDF letters
Adds a separate view function that is registered under the same
route as existing letter POST notification.
2018-02-23 17:52:24 +00:00
Rebecca Law
e736c90d00 Switch to using the pdf letter flow.
When sending letters always use the pdf letter flow regardless of service permissions.
2018-02-13 18:38:32 +00:00
Rebecca Law
dce79832ff As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.

Messaging would change to something like this:
February 2nd 2018, 15:39:05.885	Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727	SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727	Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727	Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery

To somthing like this:
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
Ken Tsang
54835b56e1 Remove sent to dvla task
- task not really necessary as the status is already set to 'sending' before the task is called if it is not sending i.e. in reseach mode or using a test key
2018-01-29 14:34:22 +00:00
kentsanggds
014f738a3d Merge pull request #1609 from alphagov/ken-refactor-letter-research-process
Refactor letter research processing for letter pdfs
2018-01-26 16:39:53 +00:00
Ken Tsang
5ef9b426bb Update letter notification processing for letter pdfs in research mode
- calls create fake response file to allow functional tests to run and trigger update of status to delivered only on preview and development so that FT response files don't pollute staging and live buckets
2018-01-26 15:05:02 +00:00
Richard Chapman
eee572276f Removed the imports for statsd as the decorators are no longer being
used.
2018-01-26 09:39:11 +00:00
Richard Chapman
083bfb9ea5 Removed the performance testing statsd calls as they are no longer
needed for monitoring the performance of the v2 endpoints. They were put
in as a temporary measure whilst sustained performance testing was
taking place.
2018-01-26 09:08:45 +00:00
Alexey Bezhan
7df9fdf42a Normalize outbound SMS sender number in notifications API
Some of the tests don't set up a service sms_sender, so we need to
check if it's None before trying to format the number.
2018-01-03 10:32:34 +00:00
Alexey Bezhan
a98e5247b8 Update notificaiton API endpoints to use template's reply_to
Sets the reply_to_text on notification from the template value if
it's set.
2017-12-19 10:23:24 +00:00
Ken Tsang
ab72d6f555 Call the create letters pdf task in api calls for services with letters as pdf 2017-12-12 12:07:55 +00:00
Richard Chapman
344e5c1f5d dded statsd to the endpoint and removed it from a letters only method
as we are not interested int he letters performance at the moment.
2017-12-01 15:46:31 +00:00
Richard Chapman
5f25d3162a Disable Redis for Staging added statsd for post methods
- Disable Redis as there is a current connection limit of 256 which
 could slow down the request if they are all used
 - Added statd to methods in the post to help spot any bottlenecks
2017-12-01 15:41:53 +00:00
Rebecca Law
8aa94af5d7 Stop populating the notification to sender mapping table when creating a notificaiton. 2017-11-29 16:47:23 +00:00
Rebecca Law
12024e9619 Update save_letter task to save the default letter contact block when creating the notification. 2017-11-27 11:33:04 +00:00
Rebecca Law
d779751bae Set reply_to_text for letter notifications posted to /notifications/letter 2017-11-24 16:17:25 +00:00
Rebecca Law
e0d0b2f4fd Merge branch 'add-reply-to-notifications' of github.com:alphagov/notifications-api into add-reply-to-notifications 2017-11-23 16:57:17 +00:00
Rebecca Law
75d99ea397 [WIP] 2017-11-23 16:01:05 +00:00
Rebecca Law
df2d3a95ae [WIP] 2017-11-23 14:55:49 +00:00
Rebecca Law
fe6bafcfb2 Update the from number in the response of post notification. 2017-11-10 14:17:29 +00:00
Rebecca Law
4eec11b633 Added an optional parameter in the form for POST /v2/notifications/sms and /service/<service_id>/send-notification to pass in the SMS sender id.
The send_sms_to_provider still needs to use the SMS sender being passed in to the POST.

As part of https://www.pivotaltracker.com/story/show/152106587
2017-10-30 13:36:49 +00:00
Rebecca Law
8d6c38e1fe Now that we allow multiple SMS senders for a service, update the sender for SMS to be the default SMS sender, regardless if it is inbound number or not 2017-10-24 13:37:17 +01:00
Richard Chapman
068ecd80a1 Changes after review. Style changes to ensure consistency with the rest of the code base to ensure good maintainability in future. 2017-10-05 16:50:18 +01:00
Richard Chapman
7974e59eb7 Changes after review. Updates to style and import order to be more consistent with other code.
Added clarification to an error message to give better debugging information.
Removed using dao_get_reply_to_by_service_id in tests to be more consistent with other code and use the test db functions or remove the need for a call altogether making the code less complex.
2017-10-05 16:50:18 +01:00
Richard Chapman
d2168b7985 Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality. 2017-10-05 16:50:17 +01:00
Richard Chapman
2fbe492d5c [2/10] Allow API calls to specify the reply address option (#1291)
* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Minor update after manual merge to fix check style rule break in test_validators.py where a single space was introduced.

* Updates after code review. Moved the template from the exception message as it was not required and updated the error message to match the field name in the sschema for better debugging and error identification.

* Fixed test after update of exception message
2017-10-04 14:34:45 +01:00
Leo Hemsted
b1928b928c update process_letter tests 2017-09-26 11:28:54 +01:00
Leo Hemsted
f3db920c71 remove jobs from letter api calls
we now no longer create a job. At the end of the post there is no
action, as we don't have any tasks to queue immediately - if it's a
real notification it'll get picked up in the evening scheduled task.

If it's a test notification, we create it with an initial status of
sending so that we can be sure it'll never get picked up - and then we
trigger the update-letter-notifications-to-sent-to-dvla task to sent
the sent-at/by.
2017-09-26 09:57:36 +01:00
Leo Hemsted
17ba8db97f remove jobs from letter api and make success/error ftp callback tasks
1. No longer create jobs when creating letters from api 🎉
2. Bulk update notifications based on the notification references after
   we send them to DVLA - either as success or as error
2017-09-26 09:57:35 +01:00
Leo Hemsted
2c758cbccd use new send-jobs-to-dvla task instead of send-files-to-dvla
the tasks (on the ftp app) do the same thing, but to improve clarity
i've renamed it to jobs, because we'll be adding a notifications one
soon
2017-09-12 17:28:07 +01:00