Commit Graph

3246 Commits

Author SHA1 Message Date
Leo Hemsted
b80beab76c use ft_notification_status and notifications for job statistics
we previously always read from NotificationHistory to get the
notification status stats for a job. Now, if the job is more than three
days old read from ft_notification_status table, otherwise read from
the notifications table (to keep live updates).
2018-12-12 13:27:19 +00:00
Leo Hemsted
e555a7595b move job rest tests to use db.py instead of conftest directly 2018-12-12 12:59:55 +00:00
Leo Hemsted
63b3a3849f move job dao tests to use db.py instead of conftest directly 2018-12-12 12:59:55 +00:00
Leo Hemsted
bf62d3ad5f infer template/service from job for notification/ft_noti_status in db.py 2018-12-12 12:59:55 +00:00
Rebecca Law
4bb68c3e52 Merge pull request #2249 from alphagov/improve-performance-of-platform-admin-page
Improve performance of platform stats page
2018-12-12 12:20:13 +00:00
Pea Tyczynska
abe01c0bc0 Revert "Switch providers on slow delivery only produces logs"
This reverts commit 6938600ab8.
2018-12-11 15:14:08 +00:00
Pea (Malgorzata Tyczynska)
d7fcd564e0 Merge pull request #2250 from alphagov/switch_providers_update
Update switch providers on slow delivery method and query
2018-12-11 10:27:29 +00:00
Pea Tyczynska
5ed7564066 Remove unused config variables
We don't use FUNCTIONAL_TEST_PROVIDER_SERVICE_ID or
UNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID anymore so we can safely
delete them from config and tests.
2018-12-10 17:25:53 +00:00
Rebecca Law
5b90fd6fb0 Removed unused method 2018-12-10 16:27:59 +00:00
Leo Hemsted
474acc5bba new chillmaid approved error messages
these get shown on the front-end so make sure their content is good
2018-12-10 12:59:16 +00:00
Pea Tyczynska
9a76d6706e Update tests to match the new csv data 2018-12-07 11:24:15 +00:00
Pea Tyczynska
6938600ab8 Switch providers on slow delivery only produces logs 2018-12-05 15:56:16 +00:00
Pea Tyczynska
418060fbdb Update switch provider on slow delivery task to change max once evey 10 minutes 2018-12-05 15:56:16 +00:00
Pea Tyczynska
39ca5b9525 New query for finding if provider is slow
The delivery for provider is slow if more than threshold (currently
we pass in threshold 10%) either took x (for now 4) minutes to deliver,
or are still sending after that time. We look at all notifications
for current provider which are delivered or sending, and are not under
test key, for the last 10 minutes.

We are using created_at to establish if notifications are from last
10 minutes because we have an index on it, so the query is faster.

Also write tests for new is_delivery_slow_for_provider query
2018-12-05 15:51:40 +00:00
Rebecca Law
76ea46bc70 Added test for platform stats using query rather than mock. 2018-12-04 13:55:56 +00:00
Katie Smith
90d9135fcf Return cancelled letters for dashboard
Added cancelled letters to the number of failed letters in the statistics
that get used for the dashboard. At some point, we want to stop
including cancelled letters in the stats, but for now this keeps things
consistent with our current letter failure state, permanent-failure.
2018-12-03 17:51:09 +00:00
Katie Smith
1d67b55b16 Add endpoint for cancelling letters 2018-12-03 17:51:08 +00:00
Rebecca Law
c766febe94 Update /platform-stats to return the data from ft_notification_status, that way the request should not time out for a long date range.
Next steps is to update the query for platform admin stats for all services.
2018-12-03 15:46:44 +00:00
Katie Smith
365c462e93 Update get_notification_by_id to take an optional service_id
It can be useful to get a notification by id while checking that the
notification belongs to a given service. This changes the
get_notification_by_id DAO function to optionally also filter by
service_id so that we can check this.
2018-12-03 12:05:23 +00:00
Katie Smith
902e1b403a Update update_notification_status_by_id DAO function
Replaced `.with_for_lockmode()`, which is now deprecated, with
`.with_for_update() - https://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode

The function should update any statuses that are not 'final', so added
`pending-virus-check` to the list of statuses that the function can
update.
2018-12-03 12:05:23 +00:00
Chris Hill-Scott
f5ea77ffa0 Add reference to one off letters
Letters should always have a reference, because that’s what DVLA use to
tell us when they’ve sent a letter.

If a letter has a reference of `None` then DVLA say they’ve sent a
letter with a reference of `'None'`. This means we can never reconcile
the letter, which means it stays in `created`, which means it never
gets billed.

We don’t think this has affected any real letters yet, just ones that
we’ve sent as tests.
2018-12-03 11:34:14 +00:00
Pea Tyczynska
f941b8b146 Use archived flag to see if job needs deleting from s3 bucket 2018-11-28 14:38:59 +00:00
Pea Tyczynska
fd06924f3a Build a command to archive old jobs 2018-11-28 14:38:59 +00:00
Pea Tyczynska
50811c3b8e Archive job after corresponding file deleted from s3 2018-11-28 14:38:59 +00:00
Pea Tyczynska
be6f37069b Change job selection dao to take flexible retention into account
Also test deleting jobs with flexible data retention

Also update tests for default data retention following logic
change: dao_get_jobs_older_than_data_retention now counts
today at the start of the day, not at a time when function runs
and updated tests reflect that
2018-11-28 14:37:43 +00:00
Rebecca Law
bffa783e8f The ftp app once updated the status of a job, since we no longer call the task we can delete it. 2018-11-27 14:37:36 +00:00
Leo Hemsted
3033015754 Merge pull request #2238 from alphagov/letter-500
look in correct bucket for letters sent after 5:30pm
2018-11-27 13:42:43 +00:00
Leo Hemsted
ba9a774e74 look in correct bucket for letters sent after 5:30pm
use the same function that we use when uploading, to ensure
consistency (that fn is also well tested already)
2018-11-27 12:21:41 +00:00
Katie Smith
ff06d120e8 Bump notifications-utils to 3.7.0
Bumped notifications-utils to 3.7.0. Version 3.7.0 includes the
`convert_utc_to_bst` and `convert_bst_to_utc` functions and the
`LETTER_PROCESSING_DEADLINE` constant, so these have been removed from
this repo and anywhere using these has now been updated to get these
from `notifications-utils`.

Also bumped pytest by a patch version to bring in a bug fix.
2018-11-26 12:53:39 +00:00
Rebecca Law
ac3882900c Merge pull request #2230 from alphagov/delete-run-letter-jobs
Delete run letter jobs
2018-11-20 12:04:28 +00:00
Rebecca Law
7f8a1f64bd Merge branch 'delete-run-letter-jobs' of github.com:alphagov/notifications-api into delete-run-letter-jobs 2018-11-20 11:12:02 +00:00
Rebecca Law
e4783dcfa9 Fix unit test 2018-11-20 11:07:32 +00:00
Rebecca Law
d0cbdce6c4 Update the error message when a service does not have permission to send a notification type. 2018-11-20 11:01:48 +00:00
Rebecca Law
ee0719341f Remove letter_job_ids schema 2018-11-16 13:04:49 +00:00
Rebecca Law
7a16ac35bd Remove letter-jobs api
When we first built letters you could only send them via a CSV upload, initially we needed a way to send those files to dvla per job.
We since stopped using this page. So let's delete it!
2018-11-15 17:24:37 +00:00
Rebecca Law
870b42919a Merge pull request #2227 from alphagov/fix-error-msg
Remove the extra "to" in the message.
2018-11-13 14:35:20 +00:00
Rebecca Law
63c0c68afa Remove the extra "to" in the message. 2018-11-12 16:28:16 +00:00
Alexey Bezhan
89516f95a9 Merge pull request #2225 from alphagov/rename_rename
Change name of update method for template folder
2018-11-12 15:51:47 +00:00
Rebecca Law
83d720bb7b Change error message, the folder id is not useful infomation to the user. 2018-11-12 15:25:48 +00:00
Pea Tyczynska
103033a330 Change name of update method for template folder
It was initialy called "rename" which does not comply with
RESTful CRUD (create, update, read, delete) naming practice.
We remove the 'rename' operation in favour of template folder
resource update endpoint as it allows us to extend it with other
attributes.
2018-11-12 14:28:07 +00:00
Katie Smith
d20e35d075 Get and use sender_id from S3 metadata
The `save_email` and `save_sms` jobs were updated previously to take an
optional `sender_id` and to use this if it was available. This commit
now gets the `sender_id` from the S3 metadata if it exists and passes it
through the the tasks which save the job notifications. This means SMS
and emails sent through jobs can use a specified `sender_id` instead of
the default.
2018-11-12 10:59:48 +00:00
Katie Smith
30fe41fd43 Pass sender_id argument to tasks
Started passing `sender_id` to the `save_email`, `save_sms` and
`process_job` tasks, with a default value of `None`.

If `sender_id` is provided, the `save_email` and `save_sms` tasks will
use it to determine the reply-to email address or the SMS sender for the
notifications in the job. The `process_job` task will start using the
value in another commit.
2018-11-12 10:49:39 +00:00
Katie Smith
4b23075488 Delete unused parameters from the save_email and save_sms jobs
These both had default arguments of `api_key_id` and `key_type` which
were never being passed in, so these have been removed.
2018-11-12 10:49:39 +00:00
Rebecca Law
591a2c897a Fix comments 2018-11-09 16:20:06 +00:00
Rebecca Law
63b305441c Add a check that the folder is not moved into itself.
By the way, the database will not let this happen, but this is a nicer error and is explicit to read as an invalid move.
2018-11-09 16:08:33 +00:00
Rebecca Law
1f86796949 Renamed url to /template-folder/<id>/contents, it's a more restful name.
Updated unit tests
Removed redundant logger
2018-11-09 15:54:39 +00:00
Rebecca Law
5df9a307be Merge branch 'master' into move-folders 2018-11-09 15:26:23 +00:00
Rebecca Law
64f7f4c302 Change status code to 204 when there is no content in response. 2018-11-09 14:55:19 +00:00
Katie Smith
7f918d7c48 Remove relationship to folder when archiving a template
When a template is archived, it should no longer belong to any folder.

If we don’t do this it will make it very hard to delete folders later
(because folders can only be deleted if they have no templates or folders
inside them).

We originally tried to check if the link between a template and folder
should be removed with

`if template.archived and template.folder:`

instead of using `if template.archived:`. However, this caused issues
because checking `template.folder` flushes the session. Since the
session is no longer dirty, the versioning decorator doesn't work as
expected and doesn't create a new row in `TemplateHistory`.
2018-11-08 17:25:45 +00:00
Leo Hemsted
d9aa220aa6 move folders and templates to other folders
new endpoints:
/services/<service_id>/move-to-folder
/services/<service_id>/move-to-folder/<target_template_folder_id>

* takes in a dict containing lists of `templates` and `folders` uuids.
* sets parent of templates and folders to the folder specified in the
  URL. Or None, if there was no id specified.
* if any template or folder has a differen service id, then the whole
  update fails
* if any folder is an ancestor of the target folder, then the whole
  update fails (as that would cause a cyclical folder structure).
* the whole function is wrapped in a single `transactional` decorator,
  so in case of error nothing will be saved.
2018-11-08 17:13:00 +00:00