Commit Graph

206 Commits

Author SHA1 Message Date
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
Leo Hemsted
efaa4f2ad2 karlify the exception messages
also create a PDFNotReadyError class, separate to BadRequestError, to
imply to the end user that this is something they should handle
separately to all the other errors
2019-09-17 12:16:24 +01:00
Leo Hemsted
1ad32c9168 move get_pdf functionality to its own endpoint
it felt very awkward when the body of a pdf might be empty, might have
things in it, and whether it is empty or not can change even when the
status is the same (a created template notification might have a pdf,
but might not, we don't know).

So move it to its own endpoint, so we can hand craft some 400 errors
that appropriately explain what's going on.
2019-09-12 17:06:22 +01:00
Katie Smith
0c1fa3852f Add endpoint for getting / creating a hidden template
We want a way of getting the hidden precompiled template from admin,
so this adds an endpoint which gets the template or creates it if it doesn't
exist. The function to get or create the hidden template already existed
but has been moved to the template DAO now that it is used in more
places.
2019-09-12 09:56:10 +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
Leo Hemsted
22aff482a8 add flag to return pdf content via api
this is only applicable when getting a single notification by id. it's
also ignored if the notification isn't a letter.

Otherwise, it overwrites the 'body' field in the response.

If the notification's pdf is available, it returns that, base64
encoded. If the pdf is not available, it returns an empty string.

The pdf won't be available if the notification's status is:
* pending-virus-scan
* virus-scan-failed
* validation-failed
* technical-failure

The pdf will be retrieved from the correct s3 bucket based on its type
2019-09-11 15:02:12 +01:00
Pea Tyczynska
eec5f5490d Don't require precompiled_letter service permission
Everyone can send precompiled letters now yay
2019-05-13 13:04:29 +01: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
Pea Tyczynska
5b9e6c2086 Set postage on basis of postage argument or template postage 2019-02-06 13:23:09 +00:00
Pea Tyczynska
9ab97d3481 Return notification postage in response for .post_precompiled_letter_notification 2019-01-16 16:57:57 +00:00
Pea Tyczynska
5a1094b6fd Throw error if postage parameter for precompiled POST request incorrect 2019-01-10 16:04:06 +00:00
Pea Tyczynska
56bae2b077 Allow users to set postage per precompiled letter 2019-01-09 17:49:19 +00: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
b00308d122 Removed an update statement to notifications.
It's a small change, but we should remove any db operations that are not necessary.
2018-09-20 14:47:24 +01:00
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
Katie Smith
8c22a6afda Change schema format name of datetime format
Renamed the 'datetime' format to 'datetime_within_next_day'. This format
is used to validate the date and time of scheduled notifications, not to
check the format of a datetime.
2018-06-27 09:11:38 +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
002b96b4f8 Merge pull request #1820 from alphagov/ken-fix-precompiled-research-mode
Fix research mode preview of precompiled letters
2018-04-06 15:22:09 +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
Rebecca Law
ecc4cde4de Update the get_notification_by_id to return a sensible message if the id is not a valid UUID.
Previously "Result not found" would be returned when the id is not a valid uuid, which does not make sense.
Now the message says "notification_id is not a valid UUID", this should be a clearer message for the client service.
2018-04-03 16:37:41 +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