Commit Graph

52 Commits

Author SHA1 Message Date
Chris Hill-Scott
044f2b7896 Merge pull request #203 from alphagov/double-check-restricted-mode
Catch sending to restricted recipients in Celery
2016-04-06 13:10:45 +01:00
Chris Hill-Scott
a63d6aa168 Add test for sending email while service restricted 2016-04-05 15:27:16 +01:00
Chris Hill-Scott
eef6d80ae2 Catch sending to restricted recipients in Celery
The Celery `send_sms` and `send_email` tasks _could_ assume that all the
recipients it gets are safe, because they have been checked either:
- when the admin app processes the CSV
- in the `/notifications/sms|email` endpoint

*However*, it’s probably safer to make the check again when the Celery
task run and passes the message off to the third party.

This also means that changing a service _back_ to restricted would have
an effect on messages that were queued, as well as all subsequent
messages.

This commit:
- restores the test that was removed here:
  e56aee5d1d (diff-e5627619e387fccc04783c32a23e6859L346)
- adds checks back into the Celery tasks for sending email and SMS,
  using the `allowed_to_send_to` function that was introduced into utils
  in https://github.com/alphagov/notifications-utils/pull/16
2016-04-05 15:11:27 +01:00
NIcholas Staples
2e09ead30f Merge pull request #198 from alphagov/retain_all_notifications_for_7_days
Successful notifications are deleted after a week now. All tests pass…
2016-04-05 15:05:58 +01:00
Nicholas Staples
4cc0028b01 Remove csv after process job is finished.
Fixed new tests.
2016-04-05 14:55:03 +01:00
Nicholas Staples
4d15409781 Successful notifications are deleted after a week now. All tests passing. 2016-04-05 11:07:21 +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
Chris Hill-Scott
f3ddf1f456 Add HTML email
Make the SES client optionally pass through HTML and text body, as per:
http://docs.aws.amazon.com/ses/latest/APIReference/API_Body.html

Gets the message as HTML from:
https://github.com/alphagov/notifications-utils/pull/12
2016-03-18 15:26:32 +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
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
Chris Hill-Scott
d6cf15469f Be agnostic about format when comparing phone #s
If a service is in restricted mode then a user can’t send messages to anyone
other than themselves and members of their team. To do this the API has to
compare the numbers they are sending to with those of their team members.

It will (falsely) say the numbers do not match if they are in a different
format, eg 07700 900849 vs +447700900849

This commit uses the code we use elsewhere for formatting phone numbers to
make sure that both numbers are in a consistent format before doing a
comparison.

I have a strong preference for doing it this way, rather than formatting numbers
before we store them:

1. https://en.wikipedia.org/wiki/Robustness_principle
2. It’s confusing to a user to see their own phone number formatted in a
   different way to that which they entered it, and the alternative, storing
   the phone number in two different formats is grim
2016-03-11 13:19:54 +00:00
Martyn Inglis
901d04605f Ad a reference to the model
- used if 3rd party needs to record an ID for reconciliation purposes
2016-03-11 09:40:35 +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
c580b9c084 Pass notification ID to fire text as our reference
- also handle fire text errors, non-zero response code means error.
2016-03-10 13:22:45 +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
976a4c06e3 Renamed some files and fixed a bug on deleting the failed notifications 2016-03-10 09:34:27 +00:00
Martyn Inglis
c8a5366484 Scheduled tasks to clean up the database
- tasks run hourly
- uses celery beat to schedule the tasks

4 new tasks
- delete verify codes (after 1 day)
- delete invitations (after 1 day)
- delete successful notifications  (after 1 day)
- delete failed notifications (after 7 days)

Delete methods in the DAO classes
2016-03-09 17:46:01 +00:00
Martyn Inglis
45b19a49a4 Updated tests 2016-03-09 14:49:14 +00:00
Martyn Inglis
2a13fe4a54 Merge branch 'master' into rate-limit
Conflicts:
	app/celery/tasks.py
	tests/app/celery/test_tasks.py
2016-03-09 14:16:59 +00:00
Martyn Inglis
b0074449bd Adds another job state to account for when sending limits have been exceeded. 2016-03-09 13:57:53 +00:00
Martyn Inglis
61af70a392 Some more tests around edge cases 2016-03-09 11:35:12 +00:00
Martyn Inglis
14d621d243 Job processing respects sendlimits
- If a job starts it MUST be able to fit into the days sending limits
- So if service limit is 10, and we've sent 5 messages and the current job is 4 then it's OK.
- If the job is 6 then it's over the limit and it should fail
- Job should NOT start if can't complete in the limit
2016-03-09 11:28:52 +00:00
Chris Hill-Scott
03f5f01a51 Merge pull request #142 from alphagov/allow-csvs-with-extra-personalisation
Accept CSV files with additional columns
2016-03-09 11:13:18 +00:00
Chris Hill-Scott
589b4de5f9 Accept CSV files with additional columns
Currently when the Celery task processes a CSV it will call the API with the
values for all the non-recipient columns in the `personalisation` field. This
means that those API calls would fail, even though the CSV has been processed
‘successfully’.

This was not being caught by the tests, so this commit adds extra tests to check
what data the task is passing to the API call.

It then updates utils to version 2.0.1 which brings in this fix:
https://github.com/alphagov/notifications-utils/pull/10
2016-03-09 09:52:39 +00:00
Rebecca Law
49198b26e7 Merge branch 'master' into reset-password
Conflicts:
	app/schemas.py
	tests/app/celery/test_tasks.py
2016-03-09 09:36:57 +00:00
Martyn Inglis
e07d16e8c6 Fixed up dates so that we respect mills 2016-03-08 17:45:37 +00:00
Rebecca Law
ba337374fd - Remove password_changed_at from the update_dict in users_dao
- Format dates in UserSchema
- Properly formatted subject and message body for the password reset email
- Add name to the message for reset password
2016-03-08 14:33:06 +00:00
Rebecca Law
b15d3434c3 Added an endpoint and celery task to email a reset password url. 2016-03-07 14:34:53 +00:00
Martyn Inglis
800afc9e44 Ensure restricted service are respected by tasks:
This is checked on 3rd party API calls, but jobs (CSV files) were able expected to only allow valid files.

Change in tack means we want to have restricted notification failures reported in the UI.
2016-03-03 12:05:18 +00:00
Chris Hill-Scott
b202af716d Fix bug where sending messages failed
When building the template it was looking for a placeholder called
((phone number)). This caused it to fail because the template it had did not
match the personalisation it was being given.

`Template` has an optional parameter for specifying personalisation values that
should be ignored. The recipient of a message is an example of such a value.

This commit passes that extra parameter, which fixes that bug.
2016-03-02 12:27:50 +00:00
Chris Hill-Scott
0e5d72494e Prefix all SMS messages with service name
Implements https://github.com/alphagov/notifications-utils/pull/4
2016-03-02 11:14:32 +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
Rebecca Law
9f6255ac94 Add subject line to the invitation email. 2016-02-29 16:12:12 +00:00
Rebecca Law
3879350c12 Send email invitation to invited user 2016-02-29 15:56:00 +00:00
Rebecca Law
df278a8e6e Email invitation to an invited user.
New celery task to send the email.
2016-02-29 13:21:12 +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
10a764a2c1 Renamed the header of the CSV to 'to' from 'number' to allow for email jobs
- added new columns to Job and Notification to capture the start/end dates accurately
2016-02-25 09:59:50 +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
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
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
Nicholas Staples
c8bb96b883 Fixes added. 2016-02-22 13:02:09 +00:00
Rebecca Law
aff948e9ca Merge branch 'celery-send-sms-code' into celery-send-email-code
Conflicts:
	app/celery/tasks.py
	app/user/rest.py
	scripts/run_celery.sh
2016-02-18 10:50:14 +00:00
Rebecca Law
3ce6758f3e Change names for clarity sake.
Rename test.
What we do when the validation_code fails to send is still to be decided.
2016-02-18 09:59:18 +00:00
Rebecca Law
c1df61a7d4 Use celery to send the email verification code. 2016-02-18 09:52:27 +00:00
Rebecca Law
9073814d9f I have an issue with the test, not sure why? 2016-02-17 17:48:23 +00:00
Rebecca Law
66cf6cfd30 Use Firetext client 2016-02-17 15:52:09 +00:00
Rebecca Law
7afa87c367 Merge branch 'master' into celery-send-sms-code
Conflicts:
	tests/app/celery/test_tasks.py
2016-02-17 15:43:57 +00:00
Rebecca Law
d022d036dc Celery task to send the sms verify code.
Each celery task will use it's own queue.
2016-02-17 15:41:33 +00:00
Martyn Inglis
837c9b7cdb Removed logging, and make fire text only client. 2016-02-17 13:59:01 +00:00