Commit Graph

108 Commits

Author SHA1 Message Date
Leo Hemsted
2cf1d22748 add filters to GET /notifications endpoints to only return for provided key_type
if api_key used to access endpoint is type team, endpoints only return that type -
will 404 if you provide a different ID. Same applies for normal (normal api keys
cannot see team notifications)
also, for convenience, set sample_notification to supply key_type of KEY_TYPE_NORMAL
by default
2016-07-01 14:35:02 +01:00
Leo Hemsted
01419e7894 store api_key_id and key_type on notification
pass through from POST /notification/<type> to the celery task
also removed a couple of asserts that can fail (based on unfrozen time comparisons)
2016-07-01 14:35:02 +01:00
Leo Hemsted
5ae7ed1acb only send to team emails/phones if POST /notificaiton/<type> with team api_key
uses same restriction as a service in trial mode
2016-07-01 14:33:25 +01:00
Leo Hemsted
11093530f9 Merge pull request #485 from alphagov/api_user-cleanup
Api user cleanup
2016-07-01 10:58:18 +01:00
Rebecca Law
3f11447bc8 A small refactor to use the SMS_TYPE and EMAIL_TYPE in code rather that 'sms' or 'email' 2016-06-30 15:41:51 +01:00
Leo Hemsted
39519e3f36 attach api_key to app
we previously attached the service id and the key's secret
also more refactoring of auth.py
2016-06-30 10:44:21 +01:00
Leo Hemsted
2b645f490a move get_all_notifications_for_service and get_all_notifications_for_job
moved from notifications/rest -> service/rest and job/rest respectively
endpoint routes not affected
removed requires_admin decorator - that should be set by nginx config
as opposed to python code
2016-06-30 10:44:21 +01:00
Leo Hemsted
5cd3043fc5 return replaced subject back from send_notification API 2016-06-21 15:03:33 +01:00
Adam Shimali
731bb19a9c Template and personalisation content is now merged and returned with
notifications, when retrieved by notification id, or service id (i.e.
all notifications for service).

There is a new element returned at top level of notification json called
body, which is the template content merged with personalisation. This
is consistent with api to endpoint to create notification which returns
what was sent as 'body' in json response.

Merging of template with personalisation is done in the
NotificationStatusSchema.

Personalisation data in encrypted before storing in db.
2016-06-20 16:49:17 +01:00
Leo Hemsted
f7ceaf9009 Merge pull request #426 from alphagov/api-template-response
add template body, version, and subject to send_notification api
2016-06-16 11:36:08 +01:00
Adam Shimali
c268401554 Updated for pr comments 2016-06-15 16:19:28 +01:00
Leo Hemsted
2b13033e85 add template body, version, and subject to send_notification api 2016-06-15 14:51:35 +01:00
Adam Shimali
b33312b855 Change endpoint responses where there are marshalling, unmarshalling
or param errors to raise invalid data exception. That will cause
those responses to be handled in by errors.py, which will log
the errors.

Set most of schemas to strict mode so that marshmallow will raise
exception rather than checking for errors in return tuple from load.

Added handler to errors.py for marshmallow validation errors.
2016-06-15 14:37:51 +01:00
Rebecca Law
4c34238a88 Fix send_email task requested from notifications endpoint. 2016-06-14 16:53:52 +01:00
Rebecca Law
a6ce109c62 Rename first send_email to send_email_v1.
Fix the tests
2016-06-13 16:16:56 +01:00
Rebecca Law
cd2627e5ed Create a new task called send_email_v2 so that I can get rid of the from_address in the signature.
This is done to make sure we do not lose any messages in the queue during deployment.
2016-06-13 15:31:45 +01:00
Rebecca Law
c9f1eb65a7 Build the from address in the task instead of the rest call. 2016-06-13 14:57:59 +01:00
Leo Hemsted
6926769f66 log firetext response code 2016-06-09 10:35:07 +01:00
Leo Hemsted
d41048f4aa statsd counters for callback statuses
also for the 'code' param from firetext
2016-06-02 15:53:04 +01:00
Martyn Inglis
909fac3c05 Added research mode tasks
- if a service is in research mode the don't send the notifications via the providers (MMG/SES/etc)
- instead set up a task to mimic those services callbacks - this completes the loop, and show stats, delivery receipts and so on.
- Use the "to" field to choose the response, allows users to create successful and errored notifications

temp fail sms, uses  "07833333333"
perm fail sms, uses = "07822222222"
success = "07811111111" (or anything else)

success email = "delivered@simulator.notify"
perm fail = "perm-fail@simulator.notify"
temp fail = "temp-fail@simulator.notify"
2016-05-31 16:55:26 +01:00
Martyn Inglis
2108bb52d5 Reorder updates to the notification / stats tables to match create. 2016-05-31 10:17:15 +01:00
Leo Hemsted
24625a44f3 prevent public api from sending archived templates 2016-05-24 13:08:38 +01:00
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