Commit Graph

437 Commits

Author SHA1 Message Date
Chris Hill-Scott
b3f4e40421 Strip HTML from template content
Templates are created in the admin app and persisted in the API.

They are consumed:
- in the admin app, by requesting them from the API
- in the API, by loading them from the database

There are two potential places where unescaped HTML could be sent to a user:
- when the admin app is previewing a template (it has to render the template as
  markup in order to show the placeholders)
- in the body of an email

For all consumers to have confidence that the templates are safe, it makes sense
to santitise them at the point of creation (and modification). This also avoids
any performance issues that could come from doing it at the point of requesting
a template.

In the future they could be created by a direct API call, bypassing the admin
app. Therefore it makes sense for the API to sanitise them.

The commit sanitises templates using a Mozilla’s Bleach library[1]. It is
configured to get the text content of the template, minus any HTML tags. It is
not using a regex because[2].

1. https://github.com/mozilla/bleach
2. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
2016-03-04 22:07:10 +00:00
Rebecca Law
3fd3aa5b3e Merge pull request #119 from alphagov/update_permission_endpoints
Update permission endpoints
2016-03-02 14:33:18 +00:00
NIcholas Staples
45ae336bd0 Merge pull request #121 from alphagov/revert-queue-config
Revert queue config
2016-03-02 14:15:54 +00:00
Rebecca Law
fde062ec7d Reduce polling_interval back to 1 second 2016-03-02 14:04:03 +00:00
Rebecca Law
0c4b34d65a Merge branch 'master' into revert-queue-config 2016-03-02 13:20:55 +00:00
Rebecca Law
6d44a91696 Removed unused tests 2016-03-02 13:20:12 +00:00
Rebecca Law
6a739d5ec9 Remove celery_queues from config.
Removed unused endpoint.
2016-03-02 13:15:23 +00:00
NIcholas Staples
18baa6ffc7 Merge pull request #120 from alphagov/template-personalisation-fix
Fix bug where sending messages failed
2016-03-02 12:57:16 +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
NIcholas Staples
62f66329a9 Merge pull request #117 from alphagov/time-3rd-party-calls
Add logging around 3rd party delivery calls
2016-03-02 11:27:00 +00:00
NIcholas Staples
90b5082972 Merge pull request #109 from alphagov/replace-placeholders
Replace placeholders with personalisation
2016-03-02 11:25:26 +00:00
Chris Hill-Scott
cc741003c0 Log FireText exceptions as exceptions 2016-03-02 11:14:32 +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
Nicholas Staples
01f616eeac Fix all tests. 2016-03-02 11:10:52 +00:00
Nicholas Staples
6f689a187e Merge remote-tracking branch 'origin/master' into update_permission_endpoints 2016-03-02 10:44:38 +00:00
Nicholas Staples
bd898a4526 Upgrade and downgrade now works.
Fix bug with repeated upgrade and downgrade.

Fix script revision number.
2016-03-02 10:44:20 +00:00
Martyn Inglis
35b7b884f8 Add logging around 3rd party delivery calls
- time SES, Twilio, fire text calls
- use monotonic for accuracy
2016-03-02 09:33:20 +00:00
Rebecca Law
f1cf4eddd5 Merge pull request #116 from alphagov/queues-defined-in-config
Moved the deinition of which queues the worker will consume from
2016-03-02 09:21:29 +00:00
Chris Hill-Scott
fa4b2e16e7 Remove CSV utils
These are in the utils repo since https://github.com/alphagov/notifications-utils/releases/tag/0.2.1
2016-03-02 08:59:34 +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
Nicholas Staples
47c4368007 Merge with master. 2016-03-01 17:18:46 +00:00
Martyn Inglis
3872ac5e67 Moved the deinition of which queues the worker will consume from
- now in config not the script
2016-03-01 16:57:06 +00:00
Rebecca Law
a2b1dc0432 Merge pull request #115 from alphagov/accept-invite
[WIP] Start of api for accepting invite.
2016-03-01 15:57:52 +00:00
Adam Shimali
ac9adc292b [WIP] Change status code to 404 rather than 400. 2016-03-01 15:51:22 +00:00
Adam Shimali
993bdc8055 [WIP] use correct dao function for adding user to service.
Check for no user returned from user dao and return correct
error message.
2016-03-01 15:36:31 +00:00
Adam Shimali
9fe08d480c Merge pull request #114 from alphagov/cancel-invited-user
New endpoint to update invited user.
2016-03-01 15:17:03 +00:00
Rebecca Law
dd503e7f14 Merge pull request #113 from alphagov/fetch-notifications-endpoints
Fetch endpoints for notifications
2016-03-01 15:16:54 +00:00
Rebecca Law
ecc96bfd68 Merge pull request #111 from alphagov/add_manage_team
Fixed some tests.
2016-03-01 15:02:08 +00:00
Martyn Inglis
dd67b84f6d Merge branch 'fetch-notifications-endpoints' of github.com:alphagov/notifications-api into fetch-notifications-endpoints
Conflicts:
	app/dao/notifications_dao.py
2016-03-01 14:59:21 +00:00
Martyn Inglis
6d345c1dfc Fixed ordering of the notifications test
- was backwards
2016-03-01 14:58:27 +00:00
minglis
57d8aa2bfd Removed print statement 2016-03-01 14:38:54 +00:00
Nicholas Staples
a2f021efad Fix git review. 2016-03-01 14:22:46 +00:00
Nicholas Staples
918d40cc9d Functionality added and all tests working. 2016-03-01 14:21:28 +00:00
Adam Shimali
3b66745677 [WIP] Start of api for accepting invite. 2016-03-01 14:13:38 +00:00
Rebecca Law
98c9ba14f7 New endpoint to update invited user.
Can be used to update status on invited user.
2016-03-01 13:33:20 +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
Nicholas Staples
7d43b4265f Merge and fix conflicts. 2016-03-01 11:59:50 +00:00
Nicholas Staples
22f550dd34 Add missing file. 2016-03-01 11:45:54 +00:00
NIcholas Staples
4e678ac391 Merge pull request #112 from alphagov/permission-fix
Fix bug in PermissionDAO
2016-03-01 11:44:16 +00:00
Rebecca Law
ecbfbbc6b0 Fix bug in PermissionDAO
Refactor user/test_rest
Remove conftest/sample_admin_service
2016-03-01 10:34:27 +00:00
Nicholas Staples
47ac0b8a98 Fixed some tests. 2016-02-29 18:32:25 +00:00
Adam Shimali
5aa2243e81 Merge pull request #110 from alphagov/invitation
Email invitation to user
2016-02-29 16:25:04 +00:00
Rebecca Law
6f338f17ac Merge branch 'master' into invitation
Conflicts:
	scripts/run_celery.sh
2016-02-29 16:14:35 +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
minglis
4b068b9c18 Merge pull request #108 from alphagov/add_template_permission
Manage template permission added. All tests passing.
2016-02-29 15:32:40 +00:00
Nicholas Staples
8ad13b6356 Manage template permission added. All tests passing. 2016-02-29 15:21:35 +00:00
minglis
bf4417c05f Merge pull request #107 from alphagov/permissions-on-invite
Permissions on invite
2016-02-29 14:59:59 +00:00