Commit Graph

1779 Commits

Author SHA1 Message Date
Rebecca Law
8cf2fc72a8 - Refactor version 1 of post notificaitons to use the common persist_notificaiton and send_notification_to_queue methods.
- It would be nice to refactor the send_sms and send_email tasks to use these common functions as well, that way I can get rid of the new Notifications.from_v2_api_request method.
- Still not happy with the format of the errors. Would like to find a happy place, where the message is descript enough that we do not need external documentation to explain the error. Perhaps we still only need documentation to explain the trial mode concept.
2016-10-28 17:10:00 +01:00
Rebecca Law
6e4bad135a - Implemented persist_notification and send_notification_to_queue in the process_notifications module
- Not sure I want to create a new classmethod on Notifications to create from v2 request. Will take another look at that.
2016-10-27 17:34:54 +01:00
Rebecca Law
c2eecdae36 - Add validation methods for post notification.
- Use these validation methods in post_sms_notification and the version 1 of post_notification.
- Create a v2 error handlers.
- InvalidRequest has a to_dict method for private and v1 error responses and a to_dict_v2 method to create the v2 of the error responses.
- Each validation method has extensive unit tests, so the unit test for the endpoint do not need to check every error case, but check that the error handle formats the message correctly.
- The format of the error messages is still a work on progress.
- This version of the api could be deployed without causing a problem to the application.
- The new endpoing is still a work in progress and is not being used yet.
2016-10-27 11:46:37 +01:00
Leo Hemsted
a45c62d41d add can_send_letters flag to services
defaults to false
2016-10-26 13:01:40 +01:00
Rebecca Law
23a4f00e56 New package structure for the version 2 of the public api.
Start building up the validators required for post notificaiton.
The app/v2/errors.py is a rough sketch, will be passed a code, the error can look up the message and link for the error message.
2016-10-25 18:04:03 +01:00
Rebecca Law
a5e07d8aff V2 schemas for post sms notifications, post_sms_request and post_sms_response 2016-10-25 14:53:31 +01:00
Imdad Ahad
72993311b3 Install wheel when building artifact 2016-10-24 16:23:18 +01:00
Imdad Ahad
177515de8f Use python wheels to speed up AS deployment:
* Create wheels from python dependencies on building codedeploy artifact
* Update script to install wheels and default to pypi if not found
2016-10-21 16:16:10 +01:00
Leo Hemsted
e5bedbd789 Merge pull request #716 from alphagov/error-handling
Error handling
2016-10-19 10:24:18 +01:00
Andras Ferencz-Szabo
5d840bfab0 Merge pull request #715 from alphagov/use_patched_boto
Bump up boto version to 2.42.0-patch2
2016-10-18 09:58:20 +01:00
bandesz
a675509b5e Bump up boto version to 2.42.0-patch2 2016-10-17 18:10:16 +01:00
Leo Hemsted
a1cc092d3b fix logger.exception syntax
when given any log function with multiple parameters, the python logging utils
assume the first param is a format string and the rest are arguments to pass
in - we were passing in the exception object to `logger.exception`, however,
the purpose of .exception is to add the exception object itself - so we didn't
need to
2016-10-17 17:44:17 +01:00
Leo Hemsted
65197a6c91 handle Exception and remove duplication in errors.py
ensure that if unexpected Exceptions are thrown, we handle them correctly
(log and then return JSON)

also remove some branches that will never trip, and combine a couple of
identical functions
2016-10-17 17:41:39 +01:00
Andras Ferencz-Szabo
7ff373723d Merge pull request #714 from alphagov/use_patched_boto
Use custom patched boto: 2.42.0-patch1
2016-10-17 16:55:10 +01:00
bandesz
cffedb1a05 Use custom patched boto: 2.42.0-patch1 2016-10-17 16:42:41 +01:00
Leo Hemsted
6e015b5a7a Merge pull request #713 from alphagov/email-exception
Don't retry invalid emails
2016-10-17 11:26:50 +01:00
Chris Hill-Scott
2a65bf3bb5 Merge pull request #711 from alphagov/extend-scheduling-to-96-hours
Let jobs be scheduled up to 96 hours in the future
2016-10-14 15:33:44 +01:00
Leo Hemsted
c69d2aa778 add tests for ses client 2016-10-13 16:07:32 +01:00
Leo Hemsted
a2c3d265de remove unused former send_sms_to_provider and send_sms_to_email functions
they were superceded by deliver_sms and deliver_email in the same file 3 wks ago
2016-10-13 15:53:01 +01:00
Leo Hemsted
a095aa41f3 don't retry task if InvalidEmailError
just record it as a technical error - retrying wont fix a bad email
2016-10-13 15:27:47 +01:00
Leo Hemsted
c0c62e02b7 move statsd call out of generic tryexcept
we shouldn't try and use statsd to log an error if they fail, for example

[we also shouldn't retry sending the message but that's a problem for another time]
2016-10-13 14:17:17 +01:00
Rebecca Law
d9ced9f912 Merge pull request #712 from alphagov/change-email-confirmation
Change email confirmation
2016-10-13 14:01:23 +01:00
Rebecca Law
9ffdf66c49 Rename the endpoints.
Increase test coverage to include the encrypted message sent to the task.
2016-10-13 11:59:47 +01:00
Chris Hill-Scott
9f36b363f2 Let jobs be scheduled up to 96 hours in the future
If you want to send a job on Monday morning, you should be able to
schedule it on Friday. You shouldn’t need to work on the weekend.

96 hours is a full 4 days, so you can schedule a job at any time on
Friday for any time on Monday.

We’ve checked with the information assurance people, and they’re OK with
us holding the data for this extra amount of time.
2016-10-12 13:38:12 +01:00
Rebecca Law
b37eef974c Change email confirmation
- New endpoint to send a user an email to verify the email address when they want to change it.
2016-10-12 13:06:39 +01:00
Chris Hill-Scott
2f12ad987d Merge pull request #710 from alphagov/email-regex
bump notification-utils to 9.0.5
2016-10-12 11:24:00 +01:00
Leo Hemsted
8aaa444489 bump notification-utils to 9.0.5
includes improved email validation regex
2016-10-11 17:04:42 +01:00
Leo Hemsted
9ade3ee767 Merge pull request #709 from alphagov/test-message-filtering
Test message filtering
2016-10-11 15:55:57 +01:00
Leo Hemsted
487554c025 use partial to make tests more legible 2016-10-11 14:40:23 +01:00
Leo Hemsted
d8467bfc3c filter out test jobs from the GET /service/{}/job endpoint
this is so that the filtering, which we do on the admin side, is applied
before pagination - so that the pages returned are all valid displayable
jobs. unfortunately this means that another config value has to be copied
to the server side but it's not the end of the world
2016-10-11 14:30:40 +01:00
Rebecca Law
153e9c3f3a Merge pull request #708 from alphagov/change-email-template
Confirm new email address template.
2016-10-11 13:44:37 +01:00
Rebecca Law
c17f0b9b91 Confirm new email address template.
Creation of a new template for the GOV.UK Notify service to send to users to confirm the change of their email address.
2016-10-11 13:28:46 +01:00
Chris Hill-Scott
2bdbc4d788 Merge pull request #707 from alphagov/loosen-get-notification-key-restriction
Loosen key restriction on get notification
2016-10-11 10:40:02 +01:00
Chris Hill-Scott
717e73a9f7 Loosen key restriction on get notification
Currently getting a single notification by ID is restricted to
notifications created with the same key type.

This makes things awkward for the functional tests now we’ve removed the
ability to create live keys in trial mode. So this commit removes the
restriction, so that any key can get any notification, no matter how it
was created.

And you’re never going to guess a UUID, so the chances of this giving
you privileged access to someone’s personal information is none.

This does not change the get all notifications endpoint, which
absolutely should be restricted by key type.
2016-10-10 17:29:38 +01:00
Chris Hill-Scott
88362cb075 Merge pull request #706 from alphagov/sort-jobs-by-processed-time-first
Sort jobs by processed time first
2016-10-10 14:03:27 +01:00
Chris Hill-Scott
ac1f5fcc91 Fix impossible test notification
No way a notification can be processed before it’s created.
2016-10-10 13:12:50 +01:00
Chris Hill-Scott
a2ea0db393 Make test easier to read
Explicity labelling what the numbers mean makes it easier to understand
what’s going on rather than having to refer back to the function call.
2016-10-10 13:12:40 +01:00
Chris Hill-Scott
df0504ddda Refactor job order test
- uses 4 rather than 8 entries to test the sort (2 notifications × 2
  columns on which we’re sorting)
- makes sure we test for when a scheduled job was created before a job
  that’s been processed already
- removes any relative datetimes so the tests are independant of
  database speed
2016-10-10 12:45:48 +01:00
Chris Hill-Scott
2451d8cac5 Merge pull request #705 from alphagov/team-key-sends-to-whitelist
Let team key send to whitelist
2016-10-10 10:59:06 +01:00
Imdad Ahad
9bbd4713e4 Fix PEP issueFix PEP issueFix PEP issueFix PEP issueFix PEP issueFix PEP
issueFix PEP issueFix PEP issue
2016-10-10 10:27:57 +01:00
Imdad Ahad
ed203e33ea Refactor test for sending to non-whitelist member 2016-10-10 10:24:33 +01:00
Chris Hill-Scott
b4291684b7 Sort jobs by processed time first
Say you have a dashboard with some jobs you sent. Normally looks like:

job | sent
--- | ---
file.csv | **5pm**
file.csv | 3pm
file.csv | 1pm
file.csv | 11am

However if your 5pm job was scheduled at lunchtime, then it will look
like this:

job | sent
--- | ---
file.csv | 3pm
file.csv | 1pm
file.csv | **5pm**
file.csv | 11am

This is because the jobs are sorted by when they were created, not when
they were sent. It looks wrong.

**For jobs that have already been sent**

This commit changes the sort order to be based on `processed_at`
instead.

**For upcoming jobs**

If a job doesn’t have a `processed_at` time then it’s scheduled, but
hasn’t started yet. Only in this case should we still be sorting by
`created_at`.
2016-10-10 09:36:53 +01:00
Chris Hill-Scott
74be99e7c7 Let team key send to whitelist
There is an overlap between team key/trial mode/whitelist. But it’s not
a complete overlap. So it’s hard to understand all the different
permutations of which key lets you send to which people when.

This commit tries to reduce the differences between these concepts. So
for a user of the API

**In trial mode**

- You can send to anyone in your team or whitelist, using the team key
- You can simulate sending to anyone, using the simulate key

**When you’re live**

- You can send to anyone in your team or whitelist, using the team key
- You can simulate sending to anyone, using the simulate key
- You can send to anyone with the live key

So doing a `git diff` on that list, the only difference between being in
trial mode and live mode is now:

`+` You can send to anyone with the live key

**(How trial mode used to work)**
- You can send to anyone in your team or whitelist, using the normal key
- You can simulate sending to anyone, using the simulate key
- You can send to _just_ people in your team using the team key
2016-10-07 15:38:36 +01:00
Leo Hemsted
b9ac337c68 Merge pull request #704 from alphagov/concurrency
fix run_scheduled_jobs concurrency bug
2016-10-07 13:32:13 +01:00
Leo Hemsted
bdb4da4976 tests n stuff 2016-10-07 13:08:41 +01:00
Leo Hemsted
d22d055e21 only process jobs if they're pending
help prevent issues where scheduled jobs are processed twice. note this is NOT
a watertight solution - it holds no locks, and there is no guarantee that the
status won't have updated between asserting that its status is 'pending' and
updating it to be 'in progress'
2016-10-07 12:54:11 +01:00
Leo Hemsted
27c7a08523 use assert rather than relying on mock functions
mocks create any property you access, so calling functions on them is
inherently risky due to typos quietly doing nothing. instead assert
`.called is False`, which will fail noisily if you typo
2016-10-07 12:48:58 +01:00
Leo Hemsted
16dd16c026 move updating into the dao fn
this helps manage the transaction by keeping it inside one function in the dao,
so after the function completes you know that the transaction has been released
and concurrent processing can resume
2016-10-07 12:35:08 +01:00
Martyn Inglis
897ad6a957 prevent race conditions in run_scheduled_jobs queuing jobs multiple times
we were running into issues where multiple beats queue up the
run_scheduled_jobs task at the same time, and concurrency issues with selecting
scheduled jobs causes both tasks to trigger processing of the job.

Use with_for_update, which calls through to the postgres SELECT  ... FOR UPDATE
which locks other SELECT FOR UPDATES (ie other threads running same code) until
the rows are set to pending and the transaction completes - so the second
thread will not find any rows
2016-10-07 12:35:02 +01:00
Rebecca Law
fff74bb4f7 Merge pull request #703 from alphagov/fix-job-status
Fix for the job status
2016-10-06 12:03:42 +01:00