Commit Graph

62 Commits

Author SHA1 Message Date
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
Martyn Inglis
0b63477e49 Removed now unused notification for job endpoints
- this is now handled in the tasks
2016-02-25 11:35:32 +00:00
Martyn Inglis
44632c36d3 Add sender name to the notification
- also ensure that the created time is handled properly
2016-02-25 11:23:04 +00:00
Martyn Inglis
b3884e2d6c Move job processing into celery
- brings boto S3 into new AWS folder
- CSV processing utils method

Rejigs the jobs rest endpoint - removes some now unused endpoints,

Calls to the task with the job, job processing in task, delegating SMS calls to the sms task
2016-02-24 17:12:30 +00:00
Martyn Inglis
8389976250 Use service ID, not from token to build notification 2016-02-24 11:11:02 +00:00
Martyn Inglis
b0609b1813 More refactors
- single base method to send notifications
- knows about service id (present if job based)
- knows about jobs - if needed
- knows about type

Does the right thing

Was lots of shared code around error checking now in one place.
2016-02-24 09:55:05 +00:00
Martyn Inglis
0007c69972 Restored code to share sms creation logic between:
- sms for API calls
- sms for Jobs
2016-02-24 09:23:21 +00:00
Martyn Inglis
201c2d01ba Task is the same whether job based or not
- use notification to build action
- notification has job
- based in encrypted blob
2016-02-23 17:39:08 +00:00
Martyn Inglis
635debb5a6 Moved the sending sms for a job into celery tasks 2016-02-23 17:30:50 +00:00
Martyn Inglis
c694dae933 Refactored to make email and sms template check the same 2016-02-23 12:35:28 +00:00
Martyn Inglis
b01782bbe6 Send Email via the API
- uses the new subject/email from fields present on the templates / service tables
- brings the send email api call into line with the sms one.
- same fields (to/template_id)
- same rules regarding restricted services
- wired in as a task into celery

Requires
- new celery queue
- new env property (NOTIFY_EMAIL_DOMAIN)
2016-02-22 17:17:29 +00:00
Adam Shimali
4f33b6f406 Wire up error handlers.
Replace some 400s with more appropriate 500s.

DAO methods that cause unexpected exceptions get caught and
logged by errors.py 500 error handler.
2016-02-17 17:04:50 +00:00
Martyn Inglis
e0e47b40fc Setup celery config 2016-02-17 10:22:25 +00:00
Martyn Inglis
0933e5c647 Building tests for the tasks class 2016-02-16 17:17:02 +00:00
Martyn Inglis
18d63e241b Extracted serialiser for encryption into a flask module
- allows mocking easier
- shared across methods
- not built everytime
2016-02-16 15:28:30 +00:00
Martyn Inglis
e42da7dd54 Fixing up tests to validate the call to the celery tasks.
- mocker used to test call or otherwise of the task
- no new tests just a spring clean
2016-02-16 14:06:56 +00:00
Martyn Inglis
655beddba6 Fixed up the get_notitication endpoint
- returns a notification
2016-02-16 11:22:44 +00:00
Martyn Inglis
223cb8c2dd Made SMS messages go through celery
- twilio client pulled in from delivery app
- made method to perform task
2016-02-15 16:01:14 +00:00
Martyn Inglis
ffbe94f390 Merge branch 'master' into celery-spike
Conflicts:
	app/notifications/rest.py
2016-02-15 11:12:07 +00:00
Martyn Inglis
16c5e7bf10 Celery task added 2016-02-15 11:11:20 +00:00
Rebecca Law
a01828a6d0 Return notification_id on create notification endpoints
- /notification/sms
 - /notification/email
 - /notificaiton/sms/service/<service_id>
Update message attribute on SQS to notification_id from message_id
2016-02-10 12:46:52 +00:00
Nicholas Staples
1b25a3c762 Removed alpha client imports. 2016-02-09 16:13:48 +00:00
Nicholas Staples
68b6444eed Comment added for missing code. 2016-02-09 16:02:38 +00:00
Nicholas Staples
2fda7ee59b Alpha client removed from code. Tests fixed but will wait till other notifications jobs are done before creating a pull request. 2016-02-09 11:38:57 +00:00
Adam Shimali
0580f5ab06 New endpoint for delivery app to use.
Once removal of code that uses existing alpha is done, then
duplicated code from /notifications/sms and the new endpoint
can be merged.

Job id is now avaiable in notificaiton but is not used yet.
2016-02-08 14:54:15 +00:00