Commit Graph

86 Commits

Author SHA1 Message Date
Leo Hemsted
81e5eb2c0a return all zeros when NotificationStatistics dont exist 2016-05-20 15:24:57 +01:00
Leo Hemsted
1b27c15c16 /notifications/statistics now takes 'day' parameter
avoids potential issues with date.today being inconsistent with user timezone
2016-05-20 11:31:35 +01:00
Leo Hemsted
0ad050043c new /notification/statistics endpoint 2016-05-20 09:48:06 +01:00
Rebecca Law
281a93b32d Update ses callback to interpret hard and soft bounces.
If the notification has a status == sending then update the status otherwise do not update the status.
In other words do not change the status more than once.
2016-05-17 15:38:49 +01:00
minglis
3c751d94a4 Merge pull request #309 from alphagov/statsd-integration
Statsd integration
2016-05-16 12:29:14 +01:00
Martyn Inglis
3f7559b286 Added statsd integration into the API
- new client for statsd, follows conventions used elsewhere for configuration
- client wraps underlying library so we can use a config property to send/not send statsd

Added statsd metrics for:
- count of API successful calls SMS/Email
- count of successful task execution for SMS/Email
- count of errors from Client libraries
- timing of API calls to third party clients
- timing of how long messages live on the SQS queue
2016-05-13 17:15:39 +01:00
Rebecca Law
917110870d Use the template version at the time the notification is created or at the time the job is created.
Update notifications/sms|email endpoint to send the template version to the queue.
Update the process_job celery talk to send the template version to the queue.
When the send_sms|send_email task runs it will get the template by id and version.

Created a data migration script to add the template_vesion column for jobs and notifications.
The existing jobs and notifications are given the template_version of the current template.
There is a chance this is the wrong template version, but deemed okay since the application is not live.

Create unit test for the dao_get_template_versions method.
Rename /template/<id>/version to /template/<id>/versions which returns all versions for that template id and service id.
2016-05-13 16:25:05 +01:00
Nicholas Staples
f71dbe9c0f Message limit added and all tests passing. 2016-04-29 10:36:59 +01:00
Adam Shimali
4e81695c84 Added limit_days filter to get notifications dao. 2016-04-28 16:51:19 +01:00
Chris Hill-Scott
ac0fa5b211 Send emails with a friendly from name
It’s nicer to have emails with a sender name, as well as the raw email
address.

Amazon SES can acheive this by using the format
```
"Sender name" <sender.name@domain.com>
```
— http://docs.aws.amazon.com/ses/latest/DeveloperGuide/email-format.html
We also have to remove all non-ASCII characters from the sender name,
because SMTP only supports 7-bit ASCII:

> A field name MUST be composed of printable US-ASCII characters (i.e.,
> characters that have values between 33 and 126, inclusive), except
> colon.

— http://www.ietf.org/rfc/rfc5322.txt

We use the service name as the sender name when:
- sending emails from the API
- sending emails from a CSV file

We use GOV.UK Notify as the sender name when:
- sending invitation emails
- sending password reset emails
2016-04-25 16:57:17 +01:00
Nicholas Staples
3b1423a2ea Provider Statistics added.
Rates command added with a test.

Updated to include added migration.
2016-04-21 13:47:04 +01:00
Rebecca Law
41ce691704 Update to processing the the response from MMG
MMG changed the datatype and the status codes they send us for the delivery receipts.
This PR accounts for that change.
2016-04-20 09:45:13 +01:00
Nicholas Staples
31978bd987 Added page_size parameter for notifications api. All tests passing.
Add page_size and total parameters to all calls for notifications.
2016-04-19 11:26:21 +01:00
Nicholas Staples
1b76646170 Working placeholders in subject with upgraded notifications-utils.
Fix test.
2016-04-13 15:53:27 +01:00
Nicholas Staples
90f0505a3d Update limit to message_limit.
Further db changes and updates.

Remove traceback print out.

Fix bug in passing template id to a task.
2016-04-11 16:53:40 +01:00
Nicholas Staples
c4b316bde6 Rebased migrations, all tests working. 2016-04-08 13:34:54 +01:00
Rebecca Law
90194cbbb8 Remove the abstract ClientResponses class. Refactor aws_ses not to require the class.
All three client now use a response_map for the delivery receipt processing.
2016-04-06 16:34:45 +01:00
Rebecca Law
e8d5a9292a Merge branch 'master' into integrate_MMG
Conflicts:
	app/notifications/rest.py
2016-04-06 14:58:13 +01:00
Rebecca Law
4806123d5c Add process_mmg_responses
Refactor process_firetext_responses
Removed the abstract ClientResponses for firetext and mmg. There is a map for each response to handle the status codes sent by each client.
Since MMG has about 20 different status code, none of which seem to be a pending state (unlike firetext that has 3 status one for pending - network delay).
For MMG status codes, look for 00 as successful, everything else is assumed to be a failure.
2016-04-06 14:31:33 +01:00
Rebecca Law
f2ee8f3eb7 WIP 2016-04-05 14:39:59 +01:00
Chris Hill-Scott
e56aee5d1d Validate recipient for restricted service w/ utils
Implements
https://github.com/alphagov/notifications-utils/pull/16

Once
https://github.com/alphagov/notifications-admin/pull/376
is merged it will no longer be possible for a user to upload a CSV file
containing recipients that they’re not allowed to send to.

So this commit also removes any restricted service checks in the task,
because any public phone numbers/email addresses no longer have any way
of reach this point if the service is restricted.
2016-04-04 20:10:19 +01:00
Rebecca Law
3820090a19 WIP: building the mmg delivery receipt endpoint. 2016-04-04 18:08:37 +01:00
Rebecca Law
2ba12da77d WIP: adding delivery receipt endpoint for mmg 2016-04-04 15:02:21 +01:00
Nicholas Staples
514d490d2f No limit for live services. 2016-04-01 11:12:44 +01:00
Adam Shimali
ca9c886c3e [WIP] On create of notification. Upsert record for template stats
recording usages of template by day.
2016-03-31 15:57:50 +01:00
Adam Shimali
7bc81528bb Post endpoint to create notificaition and get endpoint
to retrieve notification by id return data in shape more
consistent with other api endpoints.
2016-03-24 13:34:45 +00:00
Martyn Inglis
268819284f Merge branch 'master' into capture-delivery-outcomes
Conflicts:
	tests/app/notifications/test_rest.py
2016-03-21 13:32:31 +00:00
Martyn Inglis
e0316d1881 Adds notification stats update into the callback process
- when a provider callback occurs and we update the status of the notification, also update the statistics table

Adds:
- Mapping object to the clients to handle mapping to various states from the response codes, this replaces the map.
- query lookup in the DAO to get the query based on response type / template type

Tests around rest class and dao to check correct updating of stats

Missing:
- multiple client callbacks will keep incrementing the counts of success/failure. This edge case needs to be handle in a future story.
2016-03-21 13:24:37 +00:00
Nicholas Staples
327f169575 Filtering added and tests working. 2016-03-21 12:37:34 +00:00
NIcholas Staples
7d99787146 Merge pull request #161 from alphagov/fix_pagination_bug
Fix pagination bug and swapped file name with original file name.
2016-03-18 15:08:30 +00:00
Nicholas Staples
c3a15f9f30 Fix pagination bug and swapped file name with original file name. 2016-03-16 16:47:18 +00:00
Rebecca Law
4268f8453b Use the same validation in the endpoint and the task to validate the phone number is ok to send to.
Format the phone number before sending it to the sms provider.
2016-03-16 13:36:46 +00:00
Martyn Inglis
3192f5f6d1 SES Callback testing
- SES/AWS JSON is horrible and not valid.
- JSON in tests did not test accurately what it looked like in reality
- Using very odd looking bytes/strings as input into API which is more accurate
2016-03-14 14:49:02 +00:00
Martyn Inglis
1ff4ebad5c Merge branch 'master' into client-callbacks
Conflicts:
	app/notifications/rest.py
	tests/app/celery/test_tasks.py
2016-03-14 11:45:21 +00:00
Rebecca Law
e055590b07 Changed db queries to use one, which throws NoResultFound exception, this exception is dealt with in our error handlers.
Now a lot of the if none checks can be removed.
2016-03-11 12:39:55 +00:00
Martyn Inglis
62a7b8bcd0 Update notification status by message reference
- SES sends a reference to allow us to identify the notification
- use this to update status

If source of email is one of our internal emails (invites or validations) - don't try and update a notification.
2016-03-11 10:19:40 +00:00
Martyn Inglis
8d9b5b172b Changed exception type to ValueError 2016-03-11 09:06:22 +00:00
Martyn Inglis
58c78f864b Changed path to decode error for 3.4.x compatibility 2016-03-11 09:00:02 +00:00
Martyn Inglis
2d3364d946 Fixing import path to JSON decode exception 2016-03-11 08:37:04 +00:00
Martyn Inglis
f88f86a924 Endpoint to allow SES updates to occur
- update notification with delivery state
2016-03-10 17:29:17 +00:00
Martyn Inglis
2922712f0b Make sms code task use a reference too
- makes the fire text callback behave in consistent way
2016-03-10 15:51:11 +00:00
Martyn Inglis
1f22f2b7cc Updates to fire text integration:
- client updated to raise errors with fire text error codes/messages

New endpoint
- /notifications/sms/firetext
For delivery notifications to be sent to.
2016-03-10 15:40:41 +00:00
Martyn Inglis
685c66b3d3 Print statement 2016-03-10 09:57:44 +00:00
Martyn Inglis
fd7eb54d10 Merge branch 'master' into delete-expired-things
Conflicts:
	app/celery/tasks.py
	tests/app/celery/test_tasks.py
	tests/app/dao/test_notification_dao.py
2016-03-10 09:48:29 +00:00
Martyn Inglis
61a0cf32c8 Ensure clients have rate limit enforced
- rate limiting is a hard number per day
- not limited in terms of rate of request
- limit is a single number held against the service
- every notification counts against the limit, regardless of type
- return a 429 if limit exceeded.
2016-03-09 11:06:37 +00:00
Martyn Inglis
e07d16e8c6 Fixed up dates so that we respect mills 2016-03-08 17:45:37 +00:00
Chris Hill-Scott
d6f7c7d1c9 Replace placeholders before sending a message
This commit replaces placeholders in a template with the user’s data, using
the Template class from utils
(https://github.com/alphagov/notifications-utils/tree/master/utils#template)

It also extracts the personalisation data from the CSV, taking account of the
different column headings that SMS and email CSVs will have.

At the point of creating the task to send an individual messages, validation of
the placeholders matching the template is assumed to have been done either:
- in processing the CSV in the admin app
- in the endpoint for the API call

No exceptions should be raised at this point.
2016-03-02 08:59:34 +00:00
Chris Hill-Scott
68eaacaafb Accept and validate personalisation
This commit allows the send notification endpoint to accept an extra parameter,
`personalisation`, the contents of which will be used (later) to replace the
placeholders in the template.

It does validation in the following places:
- at the schema level, to validate the type and (optional) presence of
  personalisation
- at the endpoint, to check whether the personalisation provided matches exactly
  the placeholders in the template

It does not do validation when processing CSV files, as these are assumed to
already have been validated by the admin app.

It explicitly does not persist either the names of the placeholders (these
should always be derived from the template contents unless it really becomes a
performance concern) or the values of the placeholders (because they might be
personal data).
2016-03-02 08:59:34 +00:00
Chris Hill-Scott
68f31c6f84 Refactor send notification into one route
Using a URL parameter means that sending a notification can be done in one
route, rather than two separate routes and an extra method.

This commit also refactors that one remaining method to be shorter/cleaner/more
readable (or I think so anyway).

No functional changes in this commit.
2016-03-02 08:59:34 +00:00
Martyn Inglis
c5a993ead1 Fetch endpoints for notifications
- includes check on token type to ensure clients can perform admin style fetches
2016-03-01 13:30:10 +00:00