Commit Graph

179 Commits

Author SHA1 Message Date
Chris Hill-Scott
c2999ed5ad Use pycodestyle instead of PEP8
PEP8 was renamed to pycodestyle; this issue explains why:
https://github.com/PyCQA/pycodestyle/issues/466

This commit changes our tests to use pycodestyle instead of pep8.

It also means:
- making a couple of whitespace changes to appease the linter
- disabling warnings for bare `Except`s (ie `Except` instead of `Except
  ValueError`) – this seems like a sensible thing to catch but I’m not
  going to make meaningful code changes in this commit
2017-02-01 09:19:32 +00:00
Rebecca Law
701851118e Update templates.process_type to be normal and set the column as not null. 2017-01-16 11:15:48 +00:00
Rebecca Law
6c79ddbe41 This is the first deploy in series of deploys to give certain templates priority in processing.
If the template is marked as priority the notification will be sent using the `notify` queue.
The `notify` queue is a low volume queue, messages here will not be queue behind a large job and should be delivered with in a more consistent time frame.

- Added templates.process_type and templates_history.process_type column.
- Added a template_process_type table to handle the enum for templates.process_type, initial values are normal and priority

https://www.pivotaltracker.com/story/show/135429147
2017-01-13 12:14:34 +00:00
Leo Hemsted
f1899c6d53 add updated_at to provider_details
it's set to utcnow from dao_update_provider_details
2016-12-19 17:45:46 +00:00
Leo Hemsted
9d1b1328af add version to provider_details and _history
set all existing rows to have a version of 1 (also copy across values
to populate the new provider_details_history table in the upgrade
script)

in dao_update_provider_details bump the provider_details.version by 1
and then duplicate into the history table as a new row
(done manually as opposed to the decorator used in template_history
since this is only edited in this one place and the decorator is icky)
2016-12-19 17:13:10 +00:00
Leo Hemsted
a197754906 add new provider_details_history table
* to be used for auditing changes to provider details
* not hooked in yet
* also made provider_details.active non-nullable. set all existing null
  provider_details.active to FALSE. none are set false on live so
  should hopefully be fairly uncontroversial
* refactored NotificationHistory.from_notification and update from noti
  to share with provider_details_history
2016-12-19 17:13:10 +00:00
minglis
9c161df2b6 Merge pull request #771 from alphagov/fix-missing-template-id
Fix for missing template IDs.
2016-12-16 14:41:54 +00:00
Martyn Inglis
2924f01f95 Fix for missing template IDs.
- Problem was that on notification creation we pass the template ID not the template onto the new notification object
- We then set the history object from this notification object by copying all the fields. This is OK at this point.
- We then set the relationship on the history object based on the template, which we haven't passed in. We only passed the ID. This means that SQLAlchemy nulls the relationship, removing the template_id.
- Later we update the history row when we send the message, this fixes the data. BUT if we ever have a send error, then this never happens and the template is never set on the history table.

Fix:
Set only the template ID when creating the history object.
2016-12-15 16:59:03 +00:00
Rebecca Law
7a623de171 Added boby and subject to the get_notifications schema 2016-12-15 16:19:55 +00:00
Paul Craig
9b1375ba84 URLs in API responses have full URL 2016-11-28 11:13:11 +00:00
Paul Craig
268e19bb76 Fix ServiceWhiteList __repr__
Apparently this code was unreachable.
2016-11-25 16:58:46 +00:00
Paul Craig
57a0d7295d Rewrite failed statuses
There are no more notifications whose statuses are "failed", as
the "failed" status has now been replaced with statuses that are
more specific about the nature of the failure.

However, we still want to be able to filter by failing
notifications. (ie "/v2/notifications?status=failed").

Created a `.substitute_status()` method which takes a status
string or list of status strings and, if it finds 'failure',
replaces it with the other failing status types.

This way, calling for nottifications with "?status=failed" is
internally treated as
"status = ['technical-failure', 'temporary-failure', 'permanent-failure']"
2016-11-25 15:23:46 +00:00
Paul Craig
7d009915a4 Group 'completed' notification statuses
Some notification statuses assume that a notification has been
updated (ie, it cannot have been created in that state).

This caused a bug in our sample notification fixture when trying
to create a notificaiton in a 'complete' status.

This commit groups the completed statuses in a list, the way other
statuses have been grouped together so that they're more portable.
Also fixed the sample_notification fixture.
2016-11-25 15:23:04 +00:00
Paul Craig
640f51fc0a Add tests for getting back lists of notifications 2016-11-25 15:23:04 +00:00
Paul Craig
1fce30aaa7 Cost savings
The "cost" value was flawed for a couple of reasons.

1. Lots of messages are free, so in those instances the "cost"
   doesn't tell you anything
2. The query to get the rate was expensive and we don't have
   an obvious way to get it back very efficiently for large numbers
   of notifications.

So we scrapped it.
2016-11-25 15:23:03 +00:00
Imdad Ahad
9b6584c8a1 Make result of notification.cost() into a float
Cost was returning a `Decimal`, which jsonify doesn't like.
Making it a float fixes the problem.

[Relevant issue on github](https://github.com/pallets/flask/issues/835).
2016-11-22 17:58:16 +00:00
Paul Craig
9758b96a2b Create 'v2' get notification route
The new 'v2' API wants to return less data than the previous one,
which was sending back tons of fields the clients never used.

This new route returns only useful information, with the JSON
response dict being built up in the model's `.serialize()` method.

Note that writing the test for this was a bit painful because of
having to treat loads of keys differently. Hopefully we think this
is a good way to write this test, because if we don't, we should
start thinking of a better way to check the values are what we
expect.
2016-11-21 15:41:49 +00:00
Paul Craig
fddb1653ac Add .cost() to notification model
In the V2 API, the GET response for an individual notification
returns a 'cost' value, which we can get by multiplying the
billable units by the per-message rate of the supplier who
sent the message.
Any notifications with billable units > 0 but without a
corresponding `ProviderRates` entry will blow up the application,
so make sure you've got one.
2016-11-18 17:50:39 +00:00
Rebecca Law
bc434f1736 Create new column in notifications and notification_history to store the client_reference because I remembered that reference is used for email providers. 2016-11-17 13:42:34 +00:00
Rebecca Law
c00eb0f5a4 Remove from_request method on the Notification db model, was not needed anymore.
Use Notifications.query.one(), rather than assert count is 1 and query for all and get first item in list.
2016-11-14 14:41:32 +00:00
Rebecca Law
8f0a96c76c Merge branch 'master' into refactor-for-code-reuse 2016-11-11 16:51:18 +00:00
Rebecca Law
c45d1f63a7 Use the same method to persist a notification.
Refactored the send_sms task to use this method.
2016-11-11 14:56:33 +00:00
Leo Hemsted
195f3615e6 add test that if we have an exception, nothing is committed 2016-11-11 14:40:25 +00:00
Leo Hemsted
9ae6e14140 move deactivate functionality into one database transactions
this means that any errors will cause the entire thing to roll back

unfortunately, to do this we have to circumvent our regular code, which calls commit a lot, and lazily loads a lot of things, which will flush, and cause the version decorators to fail. so we have to write a lot of stuff by hand and re-select the service (even though it's already been queried) just to populate the api_keys and templates relationship on it
2016-11-11 11:20:41 +00:00
Rebecca Law
eafbbd9809 Refactor send_sms and send_email to use common code to persist the notificaiton. 2016-11-11 10:41:39 +00:00
Leo Hemsted
e8c3a5cdde add check for inactive services to auth handler
cleaned up some auth code to marginally improve efficiency of error checking
and hopefully make it easier to read

fixed some incorrect auth headers in the deactivate tests
2016-11-10 11:07:12 +00:00
Leo Hemsted
b2149bf02a undo unnecessary change to models 2016-11-10 10:38:36 +00:00
Leo Hemsted
da2fa5b4bc move sqlalchemy defaults from booleans to SQL constructs
booleans aren't actually allowed, and quietly do nothing

also default Services.active to true
2016-11-08 17:10:28 +00:00
Rebecca Law
e32978b72a Merge branch 'master' into post-sms-v2 2016-11-02 09:08:26 +00:00
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
Leo Hemsted
a45c62d41d add can_send_letters flag to services
defaults to false
2016-10-26 13:01:40 +01:00
Rebecca Law
6f83258004 Update Template.version and TemplateHistory.version nullable=False to match the db 2016-10-04 10:47:34 +01:00
Imdad Ahad
f9b539d71e Fix conflict 2016-09-27 16:54:00 +01:00
Imdad Ahad
af2cbaa9c5 Fix PEP8 issues 2016-09-27 14:16:35 +01:00
Imdad Ahad
8184eff15a Update ServiceWhitelist to conform to new data model 2016-09-27 13:44:29 +01:00
Leo Hemsted
d3c0c48401 fix dao_get_jobs_by_service_id
statuses now defaults to correct val
2016-09-23 17:05:42 +01:00
Leo Hemsted
fb6cb5f236 add statuses filter to GET /service/{}/job
can now pass in a query string `?statuses=x,y,z` to filter jobs based on
`Job.job_status`. Not passing in a status or passing in an empty string is
equivalent to selecting every filter type at once.
2016-09-23 16:34:13 +01:00
Leo Hemsted
c475bd03ce improved service whitelist endpoints
* changed POST to PUT - we are modifiying an already present resource
* improved error handling on PUT
  - return 400 if bad
  - rollback the delete of the previous whitelist on error
* return 204 if PUT succeeds ( NO CONTENT )
2016-09-23 12:21:00 +01:00
Leo Hemsted
2e16be18bc Merge branch 'master' of github.com:alphagov/notifications-api into service-whitelist 2016-09-23 10:14:42 +01:00
Leo Hemsted
5c5ca26630 Add ServiceWhiteList model with corresponding tests 2016-09-22 11:58:51 +01:00
Leo Hemsted
3d0df9b5a7 add new service whitelist table
services can have a whitelist of phone numbers and email addresses that they
can send to in addition to team members when in trial mode. email_address
and mobile_number are nullable and app level checks will be in place to
prevent inserting blank rows. they have a created_at date so that we can
[potentially] delete them a week later to avoid keeping personally identifying
data any longer than necessary
2016-09-22 10:32:32 +01:00
Martyn Inglis
9ee5c661b0 Changed as per @chs comment. Using cls based not explicity calling type 2016-09-08 09:21:32 +01:00
Martyn Inglis
99250b2248 Adds a builder method to the notification object.
This is used to construct a notification from the sorts of data an API call provides. This is used in both the db-email / db-sms tasks and the notifications rest endpoint to construct the notification DB object.
2016-09-07 13:44:56 +01:00
Chris Hill-Scott
be9fd96d03 Merge pull request #656 from alphagov/add-cancel-job-endpoint
Add an endpoint to cancel a job
2016-09-06 12:11:32 +01:00
Chris Hill-Scott
4a7267be8b Add an endpoint to cancel a job
If you schedule a job you might change your mind or circumstances might
change. So you need to be able to cancel it. This commit adds a `POST`
endpoint for individual jobs which sets their status to `cancelled`.

This also means adding a new status of `cancelled`, so there’s a
migration…
2016-09-02 12:27:02 +01:00
Martyn Inglis
6488feaeec Remove the status column from jobs, and update the new job status column with the previous values 2016-08-31 10:23:34 +01:00
minglis
4a078e3c61 Merge pull request #635 from alphagov/scheduled-delivery-of-jobs
Scheduled delivery of jobs
2016-08-30 12:48:48 +01:00
Martyn Inglis
5012d20d58 Merge branch 'master' into remove-contested-writes 2016-08-25 14:37:51 +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