Commit Graph

326 Commits

Author SHA1 Message Date
Ken Tsang
8e3e31faaf Updated service DAO and API end points 2017-05-25 17:47:21 +01:00
Leo Hemsted
554a193cff separate service deserialization from validation
Marshmallow validates and deserialises - BUT, when it deserialises,
it explicitly sets `sms_sender=None`, even when you haven't passed
sms_sender in. This is problematic, because we wanted to take advantage
of sqlalchemy's default value to set sms_sender to `GOVUK` when the
actual DB commit happens.

Instead, still use marshmallow for validating, but manually carry out
the json deserialisation in the model class.

This fixes a bug that only manifested when the database was upgraded,
but the code hadn't updated. 🎉
2017-05-24 16:27:12 +01:00
Martyn Inglis
03346f467f updated cache to store map not single value, to accommodate the billable units and the total cost. 2017-05-24 09:59:37 +01:00
Martyn Inglis
78a55bafe0 Added new cost field to yearly billable sms endpoint. 2017-05-24 08:57:41 +01:00
Martyn Inglis
119f0532ab Renamed the API method/url 2017-05-22 10:06:34 +01:00
Martyn Inglis
f0395e7496 New endpoint to get the count of billable SMS units. 2017-05-19 16:43:05 +01:00
Chris Hill-Scott
2d4f10bd22 Comma-format number when emailing live services
250,000 is easier to read than 250000.
2017-05-16 12:33:01 +01:00
Imdad Ahad
d993e1a43e Don't send notification if other service attrs changed 2017-05-15 15:02:01 +01:00
Imdad Ahad
5eb02a45a5 Send go live email when service goes live 2017-05-12 14:07:06 +01:00
Rebecca Law
a564b9aeb0 Update /service/{}/notifications to look for a "to" query string, if it exists call the search notifications_by_to_field method. 2017-05-08 17:20:21 +01:00
Rebecca Law
d252dc8976 New endpoint to search by "to" field of the notification.
The query ignores case and spaces.
2017-05-05 14:12:50 +01:00
Rebecca Law
1a64509186 Change the resultset from the yearly and monthly billing data queries.
Fix some formatting of the return objects.
2017-04-28 10:10:49 +01:00
Rebecca Law
a186fc95be Added new endpoints to return the yearly-usage and monthly-usage for a given financial year and service id.
Since the response has changed I have created new endpoints so that the deployments for Admin are more managable.

Removed print statements from some tests.
2017-04-28 10:10:48 +01:00
Ken Tsang
5f945ab30e Refactored code, changed now to utcnow in test 2017-03-29 11:47:41 +01:00
Ken Tsang
c94b4f1b46 Removed unused import 2017-03-29 11:05:31 +01:00
Ken Tsang
af78efd137 Fix get_detailed_services BST 2017-03-29 11:03:28 +01:00
Rebecca Law
78242812ef Register a before_request event for all blueprints, that defines the authentication requirement.
There are three authentication methods:
 - requires_no_auth - public endpoint that does not require an Authorisation header
 - requires_auth - public endpoints that need an API key in the Authorisation header
 - requires_admin_auth - private endpoint that requires an Authorisation header which contains the API key for the defined as the client admin user
2017-03-16 18:15:49 +00:00
Rebecca Law
fd00351ad2 Testing out adding a admin authentication requirement per blueprint. 2017-03-15 16:52:44 +00:00
Imdad Ahad
520c588d56 Add endpoint to retreive stats for service by template per month 2017-03-08 12:01:38 +00:00
Chris Hill-Scott
cffd0c2c54 Remove weekly stats endpoints
The weekly stats endpoint wont be used once
https://github.com/alphagov/notifications-admin/pull/1109 has been
merged.

It has been replaced with a new monthly endpoint in
https://github.com/alphagov/notifications-api/pull/807
2017-02-08 13:16:41 +00:00
Rebecca Law
30ca9e7e78 Merge pull request #811 from alphagov/check-service-is-active
Check service is active
2017-02-02 11:59:28 +00:00
Leo Hemsted
855a412c90 Merge pull request #812 from alphagov/plat-adm-dates
make sure we convert strings to dates before we use them
2017-01-31 16:24:30 +00:00
Leo Hemsted
cd47dbd36b make sure we convert strings to dates before we use them
fixes 500 on platform admin page
2017-01-31 16:12:46 +00:00
Rebecca Law
dab89969cc If the service is inactive at the time of sending the notification to the provider, the notification is marked as technical-failure.
Removed the /service/<id>/deactivate endpoint, now using /service/<id>/archive
2017-01-31 14:28:25 +00:00
Chris Hill-Scott
56ba653f48 Add endpoint for breakdown of activity by month
This endpoint will eventualy replace the weekly breakdown one. By month
for a given financial year is better, because it gives us consistency
with the breakdown of financial usage (and eventually consistency with
the template usage).

The code to do this is a bit convoluted, in order to fill out the counts
for months and statuses where we don’t have notifications.

This will make the admin side of this easier, because we can rely on
there always being numbers available. The admin side will deal with
summing the statuses (eg `temporary-failure` > `failed`) because this
is presentational.

This commit also modifies the usage count to use `.between()` for
consistency.
2017-01-31 14:16:34 +00:00
Rebecca Law
907a1e91ac Removed the need for 2 return statements.
Update tests to fix copy/paste errors, use freezetime to ensure there is never a random failing test.
2017-01-31 11:33:36 +00:00
Rebecca Law
87556687ab This is the first PR in the story to create a suspend service feature.
- Renaming /service/<id>/deactivate to /service/<id>/archive to match language on the UI.
  - Will need to update admin before deleting the deactive service method
- Created dao and endpoint methods to suspend and resume a service.
- I confirm the use of suspend and resume with a couple people on the team, seems to be the right choice.

The idea is that if you archive a service there is no coming back from that.
To suspend a service is marking it as inactive and revoking the api keys. To resume a service is to mark the service as active, the service will need to create new API keys.
It makes sense that if a service is under threat that the API keys should be renewed.

The next PR will update the code to check that the service is active before sending the request or allowing any actions by the service.
2017-01-30 16:32:44 +00:00
imdadahad
eec7564475 Merge pull request #804 from alphagov/feat-add-perf-platform-client-and-job
Add client and job to update the performance platform daily
2017-01-27 17:03:38 +00:00
Rebecca Law
c87d0a37f3 Refactor the get_midnight functions to return the date in UTC but for the localised time.
So in June when we are in BST June 16, 00:00 BST => June 15 23:00 UTC
2017-01-27 15:57:25 +00:00
Chris Hill-Scott
8ad0236f28 Allow filtering of billing info by financial year
We already filter the usage-by-month query by financial year. When we
show the total usage for a service, we should be able to filter this
by financial year.

Then, when the two lots of data are put side by side, it all adds up.
2017-01-27 11:13:22 +00:00
Rebecca Law
0ec84ff5e8 Refactor the get_detailed_services so that the start and end date are not defaulted to None.
Set the start and end date to today's date if they are not set in the request.args
2016-12-29 13:50:41 +00:00
Rebecca Law
1de022f005 Update the query to execute immediately.
Fix indent.
Left a comment as to why start and end date are not set.
2016-12-29 13:28:55 +00:00
Rebecca Law
8ad078b663 Added a date range filter for the get all services end point.
When the start_date and end_date query argruments exists in the request,
the query will return the results from the NotificationHistory table for the given date range.
We will need to check the performance of this query, but this will only be used by the platform admin page.
2016-12-28 15:39:55 +00:00
Jenny Duckett
d2649aebc8 Add include_from_test_key parameter to /service
We want to be able to toggle the numbers on the platform admin page between
including and excluding notifications sent using test keys, so that we can see
both real use of the platform and all load on it.

This parameter defaults to True, which is the existing behaviour.
2016-12-05 17:50:52 +00:00
Leo Hemsted
95764af6ea Merge pull request #723 from alphagov/active-service
deactivate a service
2016-11-11 15:25:32 +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
Leo Hemsted
b0e240267a add only_active flag to get services functionality 2016-11-09 15:07:23 +00:00
Leo Hemsted
d4a300ec7a add only_active flag to GET /services/
does what it says on the tin
2016-11-09 11:45:39 +00:00
Leo Hemsted
089ac099f3 POST /service/{id}/deactivate deactivates a service:
* set active=False on the service
* renames service to "_archived_{old_name}"
* archives all templates for the service
* revokes all api keys for the service
2016-11-08 17:10:28 +00:00
Imdad Ahad
461d8a9b2c Add separate endpoint to update a single user attr 2016-11-07 17:42:23 +00:00
Chris Hill-Scott
def1d253aa Add endpoint to get billable units/financial year
`/services/ef7a665d-11a4-425a-a180-a67ca00b69d7/billable-units?year=2016`

Pretty much just passes through to the DAO layer. Validates that year
is:

- present (there’s no need for unbounded queries on this endpoint)
- an integer
2016-10-03 15:50:55 +01:00
Imdad Ahad
1222a6ddf3 Refactor to increase readability for getting whitelist objects 2016-09-28 10:16:10 +01:00
Imdad Ahad
f9b539d71e Fix conflict 2016-09-27 16:54:00 +01:00
Imdad Ahad
f29c6c0bb2 Update to return 404 if invalid service id 2016-09-27 13:47:53 +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
0b8c385de1 add remove_whitelist tests 2016-09-23 10:45:12 +01:00
Chris Hill-Scott
d7bb83fadf Optionally get notifications created w/ test key
This is only for the method that the admin app uses; it doesn’t affect
the public get notifications endpoint.
2016-09-23 10:40:33 +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
af0dbd14be correct service_whitelist dao/rest functionality
additionally added dao tests
2016-09-22 17:17:34 +01:00
Chris Hill-Scott
4217bd2108 Optionally get only notifications created by API
This commit adds the `include_jobs` filter to the
`GET /services/…/notifications` endpoint. It defaults to `True` (ie show
all notifications) but makes it possible to only return notifications
created by _any_ API key.

This is so that we can show a log of all notifications sent through the
API in the admin app.

It does not expose this list to the public `GET /notifications` endpoint
because this would violate our rules about keys only being able to get
notifications created with keys of the same type.
2016-09-22 11:17:46 +01:00