Commit Graph

133 Commits

Author SHA1 Message Date
Martyn Inglis
dde22bc58b Implemented deleted notification if SQS write fails 2016-09-08 16:00:18 +01:00
Martyn Inglis
b4d40dcd18 Merge branch 'master' into write-to-postgres-not-sqs
Conflicts:
	app/notifications/rest.py
	tests/app/notifications/rest/test_send_notification.py
2016-09-08 09:15:07 +01:00
Martyn Inglis
770b0c2838 Update rest end point to wrote to the DB not the queue.
We wrote to the queue as a performance optimisation , however dev found it confusing to not have immediate access to the notification as it may be perished some minutes later under periods of load. Additionally we had a couple of DB issues which led to us dropping notifications.

Pushing the DB write to earlier in the flow makes the system a little  more robust in the early days, we may want to change this when the traffic increases.
2016-09-07 13:47:22 +01:00
Martyn Inglis
259fb0cb62 Slightly changed to only unlimited the live services.
Logic:
- live services don't check days limit for now
- restricted services check limits
(caveat) simulate keys aren't checking day limit even in restricted mode.
2016-09-06 14:21:36 +01:00
Imdad Ahad
d6a8780515 Remove send notification test 2016-09-06 11:39:22 +01:00
Leo Hemsted
95e3f39c6f Merge pull request #632 from alphagov/readme-cleanup
cleaned up readme + environment file
2016-08-31 17:08:49 +01:00
Leo Hemsted
5ac4e630d8 remove some legacy code/tests relating to old invite/verification code 2016-08-31 14:49:26 +01:00
Chris Hill-Scott
f3495f9dae Merge pull request #645 from alphagov/no-restrictions-on-test-key
Remove restrictions when using simulate API key
2016-08-31 13:25:12 +01:00
Martyn Inglis
f3c614634f Merge branch 'master' into seperate-queues-for-sending-and-for-db 2016-08-30 14:25:14 +01:00
Chris Hill-Scott
7769923dda Allow test key to send irrespective of daily limit
When you use a simulate API key it should behave like a live service,
except for actually sending the messages. There should be no limits even
if the service is in trial mode.

This commit removes the restriction on sending messages when you’ve sent
up to your daily limit.
2016-08-30 11:06:38 +01:00
Chris Hill-Scott
5eaec8c235 Allow test key to send irrespective of trial mode
When you use a simulate API key it should behave like a live service,
except for actually sending the messages. There should be no limits even
if the service is in trial mode.

This commit removes the restriction on sending messages to peole outside
your team when you’re in trial mode.
2016-08-30 11:06:15 +01:00
Martyn Inglis
486697d07c New queues for the sms/email tasks
Previously there were 4 queues for sending messages

The was based on the fact that each notification has 2 actions - persist in the database and send to provider.

Two queues supported the CSV upload - for the first of these tasks
- bulk-email
- build-sms

And there were two more queues for the tasks that make the 3rd party client calls.
- sms
- email

API Calls just used the latter two queues for both tasks

Added four new queues
- db-email
- db-sms
- send-sms
- send-email

So an API call puts a notification into the db-[type] queue first, which then puts the notification into the send-[type] queue

Build queues stay as before.

This will allow us to target processing of these tasks with separate workers to manage these differently.
2016-08-30 10:42:24 +01:00
Martyn Inglis
893164ae40 Removed contented updates the notifications stats table
- As before this is now driven from the notifications history table

- Removed from updates and create
- Signatures changes to removed unused params hits many files
- Also potential issue around rate limiting - we used to get the number sent per day from the stats table - which was a single row lookup, now we have to count this. This applies to EVERY API CALL. Probably not a good thing and should be addressed urgently.
2016-08-25 11:55:38 +01:00
Leo Hemsted
5418f65ae7 Merge pull request #599 from alphagov/version-500
fix GET /notifications 500 error
2016-08-22 10:59:46 +01:00
Chris Hill-Scott
ebfaa5dac2 Show separate error messages for team key
Although using a team key is functionally the same as your service being
restricted, conflating the two errors is not helpful. What we typically
saw in research was that someone was using a team key, got the error,
used a live key and got the _same_ error.

This commit adds a new error message that specifically mentions the type
of API key that you’re using.
2016-08-10 16:20:01 +01:00
Chris Hill-Scott
0a429e18b4 Give better error when sending to non-team member
Scenario we saw in research:
- trying to send a message to someone outside your team
- service is in trial mode

Result:
- error message was terrible, no-one understood it

Solution:
- better error message
2016-08-10 16:17:47 +01:00
Leo Hemsted
46c0728b12 add actual_template relationship to notification
also renamed the function to make it apparent that it'll join and grab personalisation
2016-08-09 16:57:18 +01:00
Martyn Inglis
fe54fa9f73 Final pass through existing statsd endpoints to ensure they match new naming strategy.
Updates accordingly.
2016-08-08 11:23:58 +01:00
Martyn Inglis
f223446f73 Refactor statsd logging
Removed all existing statsd logging and replaced with:

- statsd decorator. Infers the stat name from the decorated function call. Delegates statsd call to statsd client. Calls incr and timing for each decorated method. This is applied to all tasks and all dao methods that touch the notifications/notification_history tables

- statsd client changed to prefix all stats with "notification.api."

- Relies on https://github.com/alphagov/notifications-utils/pull/61 for request logging. Once integrated we pass the statsd client to the logger, allowing us to statsd all API calls. This passes in the start time and the method to be called (NOT the url) onto the global flask object. We then construct statsd counters and timers in the following way

	notifications.api.POST.notifications.send_notification.200

This should allow us to aggregate to the level of

	- API or ADMIN
	- POST or GET etc
	- modules
	- methods
	- status codes

Finally we count the callbacks received from 3rd parties to mapped status.
2016-08-05 10:44:43 +01:00
Leo Hemsted
c81b30dba1 separated schemas once more into "with template" and "with personalisation"
"with personalisation" should only be used by the public notification api
"with template" should be used when we want template name, etc details.

also added an xfail test for correctly constructing notification
personalisation
2016-07-26 14:34:59 +01:00
Leo Hemsted
b28e7efd14 dont load template contents for job page
rename the notification_status_schema to make it apparent that it
involves the template, and then don't use it on the job page - the
job page doesn't do anything with the data. won't somebody think of
the cpu cycles! (also means it ignores problems with template
versions)
2016-07-26 14:34:59 +01:00
Chris Hill-Scott
c38962e91a Only put a character limit on SMS notifications
We limit SMS to be a maximum of 495 characters at the point of an
API call being made.

We were also applying this limit to emails, which is wrong.
2016-07-21 16:33:21 +01:00
Adam Shimali
9f9040869d Daily message limit imposed for service api calls. 2016-07-14 11:25:45 +01:00
Chris Hill-Scott
a8a556d02a Use PassThrough renderer
Implements and depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/49
2016-07-07 22:48:07 +01:00
Chris Hill-Scott
824085ead8 Bring in changes to template and CSV processing
Functional changes:
- adds the blue bar

Performance changes
- faster CSV processing

Depends on:

- [ ] https://github.com/alphagov/notifications-utils/pull/47
- [ ] https://github.com/alphagov/notifications-utils/pull/48

Also brings in some breaking changes, which do not affect utils (apart
from a weird import).
2016-07-07 15:44:30 +01:00
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