Commit Graph

5366 Commits

Author SHA1 Message Date
Rebecca Law
4fc004b00a Increase the number of days we calculate billing from 3 to 10 days.
Log exception if the billing counts for letters are different in the dvla response file than what we collected.
2018-07-24 16:28:30 +01:00
Pea (Malgorzata Tyczynska)
1b21a12b83 Merge pull request #1971 from alphagov/add_task_to_send_complaints_on
Add and call task to send complaints on to service callback APIs
2018-07-24 15:07:09 +01:00
Leo Hemsted
d61300accb Merge pull request #1944 from alphagov/research-letter-time
create fake letter response files with variables timestamps
2018-07-20 12:22:44 +01:00
Leo Hemsted
5c4f3e246c make test dvla response file timestamps in a random order
since there'll be a bunch of threads running functional test tasks at
the same time, there's no point always trying to start from the same
second and then stepping back to the same one-second-back file each
time. Also, this leads us to an increased risk of race conditions.

This change takes the same thirty second range, but shuffles it. The
tests, since they're no longer deterministic, now use a new Matcher
object (w/ credit to alexey) to match any filename from within that
thirty second range
2018-07-20 12:09:00 +01:00
Leo Hemsted
0cfed3f514 create fake letter response files with variables timestamps
when a test letter is created on dev or preview, we upload a file to
the dvla ftp response bucket, to test that our integration with s3
works. s3 triggers an sns notification, which we pick up, and then we
download the file and mark the letters it mentions as delivered.

However, if two tests run at the same time, they'll create the same
file on s3. One will just overwrite the next, and the first letter will
never move into delivered - this was causing functional tests to
intermittently fail.

This commit makes the test letter task check if the file exists - if it
does, it moves back one second and tries again. It tries this thirty
times before giving up.
2018-07-20 12:09:00 +01:00
Leo Hemsted
6e87b36303 remove duplication shutdown loggers
also add **kwargs to make it celery4 compatible
2018-07-20 12:09:00 +01:00
Pea Tyczynska
3048c05850 Revert notification_id name change in delivery_status service_callback_task data 2018-07-20 11:22:38 +01:00
Katie Smith
87013d9399 Merge pull request #1970 from alphagov/notification-serialize-includes-sender
Include the notification sender name when serializing notifications
2018-07-20 10:39:48 +01:00
Katie Smith
af5c4d2872 Include the notification sender name when serializing notifications
The `serialize` method of the Notification model now includes the
`created_by_name`. If a notification was sent as a one-off message this
value will now be the name of the person who sent the notification. If
a notification was sent through the API or by a CSV upload we don't
record the id of the sender, so `created_by_name` will be `None`.

This change affects the data that gets returned from these endpoints:
* /v2/notifications/<notification_id>
* /v2/notifications
2018-07-20 09:37:50 +01:00
Pea Tyczynska
812f4d20dd Send complaints on to service callback APIs using an async task 2018-07-19 16:59:39 +01:00
Katie Smith
ff3a71a9ea Merge pull request #1963 from alphagov/get-one-messages-by-default
Add one_off filter when getting all notifications for a service
2018-07-19 10:26:54 +01:00
Katie Smith
b1cfa8942a Add one_off filter when getting all notifications for a service
Added the option to filter by one_off messages to the DAO function
`get_notifications_for_service`. Previously, one-off notifications
were not returned - this has changed so that the default is for
one-off notifications to be returned. Also simplified the `include_jobs`
filter for this function.

The DAO function gets used in 3 places - for the V1 and V2 API endpoints,
which will now start to return one-off messages. It also gets used by
the admin app which needs to pass in `include_one_off=False` to the
`get_all_notifications_for_service` where we don't want one-off
notifications to show, such as the API message log page.
2018-07-18 15:08:06 +01:00
Alexey Bezhan
8d48f41776 Merge pull request #1966 from alphagov/set-callback-history-type
Add callback_type to service callback history records
2018-07-18 14:57:16 +01:00
Alexey Bezhan
778909b189 Add callback_type to service callback history records
We've updated the current service callbacks to add callback types
in #1964, but since the table is versioned we also need to add a
type to the history records.

Even though they're not used anywhere at the moment this might make
it easier to restore from a history callback record in the future.
2018-07-18 13:57:42 +01:00
Pea (Malgorzata Tyczynska)
946e0b2700 Merge pull request #1964 from alphagov/send_complaints_to_service_teams
Send complaints to service teams
2018-07-18 13:19:34 +01:00
Pea Tyczynska
86978c225a Filter 'get_service_callback_api_for_service' to only get status updates
Also rename it to 'get_service_delivery_status_callback_api_for_service'
2018-07-18 11:36:39 +01:00
Pea Tyczynska
e81c395ab1 Assign delivery_status type to existing callbacks 2018-07-18 11:36:39 +01:00
Pea (Malgorzata Tyczynska)
8113d0e48f Merge pull request #1958 from alphagov/send_complaints_to_service_teams
Add callback_type column to service_callback_api table
2018-07-18 10:30:31 +01:00
Pea Tyczynska
183aa160c6 Add callback_type column to service_callback_api table
Also add service_callback_type table with allowed types
2018-07-17 16:54:00 +01:00
Rebecca Law
9c99e45008 Merge pull request #1945 from alphagov/flexible-data-retention
Flexible data retention
2018-07-17 16:03:18 +01:00
Chris Hill-Scott
081c7c7083 Merge pull request #1957 from alphagov/quis-patch-1
Bump utils to fix smart quotes in email addresses
2018-07-17 14:32:28 +01:00
Chris Hill-Scott
222dc3fe95 Use debian jessie instead of stretch until npm is installed differently 2018-07-17 11:59:48 +01:00
Chris Hill-Scott
89d20033a8 Bump utils to fix smart quotes in email addresses
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/500
2018-07-17 11:22:22 +01:00
Pea (Malgorzata Tyczynska)
48d1e816ef Merge pull request #1943 from alphagov/admin_platform_users_search
Add data endpoint for finding users by full or partial email
2018-07-16 15:47:23 +01:00
Alexey Bezhan
cbaa8cceee Merge pull request #1938 from alphagov/pin-all-requirements
Pin all application requirements in requirements.txt
2018-07-16 14:07:08 +01:00
Pea Tyczynska
a69dee5e6d Move code that escapes special chars to helper function and use it
in query get_users_by_partial_email
2018-07-13 15:47:21 +01:00
Pea Tyczynska
782a8ab9e7 Add data endpoint for finding users by full or partial email 2018-07-13 15:47:20 +01:00
Rebecca Law
ab695d24d5 Added new endpoints to get service data retention for a service. 2018-07-13 15:18:27 +01:00
Rebecca Law
e2a1dfeb31 New dao and endpoints to create and update service data retention. 2018-07-11 17:02:49 +01:00
Leo Hemsted
d88003d143 Merge pull request #1940 from alphagov/dashboard-day-limit
Sort out the dashboard day limits
2018-07-11 16:07:31 +01:00
Katie Smith
574305f18d Merge pull request #1939 from alphagov/delete-old-platform-admin-code
Delete old platform-stats route
2018-07-11 14:22:27 +01:00
Rebecca Law
f495a497ae Merge pull request #1937 from alphagov/flexible-data-retention
Create ServiceDataRetention
2018-07-11 10:16:16 +01:00
Rebecca Law
e4cc90e585 Fix merge conflict 2018-07-11 10:09:33 +01:00
Rebecca Law
df0df55402 Added unique constraint for service_id + notification_type
Change updated_at to have onupdate rather than default.
2018-07-11 10:09:33 +01:00
Rebecca Law
b71f6777e9 Create a table SERVICE_DATA_RETENTION to store the number of days the notification is to be kept for. 2018-07-11 10:09:33 +01:00
Rebecca Law
91c7858904 Merge branch 'master' of github.com:alphagov/notifications-api 2018-07-11 10:08:37 +01:00
Rebecca Law
12aa9436e0 Merge pull request #1942 from alphagov/fix-old-jobs
Clean up old, incomplete jobs
2018-07-10 15:54:03 +01:00
Rebecca Law
526831504d Merge branch 'master' of github.com:alphagov/notifications-api 2018-07-10 15:46:49 +01:00
Rebecca Law
b3ab96c60e Merge pull request #1941 from alphagov/revert-1936-fix-old-incomplete-jobs
Revert "Clean up old, incomplete jobs"
2018-07-10 15:44:49 +01:00
Rebecca Law
1c54ef090d Clean up old, incomplete jobs 2018-07-10 15:39:51 +01:00
Rebecca Law
57d684bd0f Revert "Clean up old, incomplete jobs" 2018-07-10 15:37:39 +01:00
Rebecca Law
c1699cd0a5 Merge pull request #1936 from alphagov/fix-old-incomplete-jobs
Clean up old, incomplete jobs
2018-07-10 15:35:23 +01:00
Leo Hemsted
d2d267e5d8 rename limit_days to whole_days on template statistics endpoint
and return data for one more day.

we're not really limiting to 7 days - we're returning 7 entire days,
plus whatever time has elapsed since midnight today. I felt it would be
best to rename the variable to `whole_days` to imply that it's not
"limit this data set to seven days", it's "give me at least seven days".

the endpoint is backwards compatible so we can rename the variable on the front-end later
2018-07-10 15:04:35 +01:00
Katie Smith
0cb9e335b9 Delete old platform-stats route
We no longer need the `/platform-stats` route in the service blueprint,
because admin is using the new `/platform-stats` route in the platform stats
blueprint instead.
2018-07-10 14:59:24 +01:00
Alexey Bezhan
75940c9566 Pin all application requirements in requirements.txt
The list of top-level dependencies is moved to requirements-app.txt,
which is used by `make freeze-requirements` to generate the full
list of requirements in requirements.txt.

This is based on alphagov/digitalmarketplace-api#615, so rationale
from that PR applies here.

We had a problem with unpinned packages on new deployments leading
to failed tests (e.g. alphagov/notifications-admin#2144) which is
why we're implementing this now.

After re-evaluating pipenv again, this still seems like the least
disruptive approach:

* pyup.io has experimental support for Pipfile, but doesn't respect
  version ranges or updating hashes in the lock file
* CloudFoundry buildpack recognizes and supports Pipfiles out of the
  box, but the support is relatively new. For example until recently
  CF would install dev packages during deployment. It's also based on
  generating a requirements file from the Pipfile, which doesn't
  properly support pinning VCS dependencies (eg it doesn't set the
  #egg= version, meaning pip will not upgrade the package if it's
  already installed).
* pipenv has a strict dependency resolution algorithm, which doesn't
  appear to be well documented and can cause some unexpected failures.
  For example, pipenv doesn't seem to be able to install `awscli-cwlogs`
  package at all, believing it to have a version conflict for `botocore`
  (which it doesn't list as a direct dependency) while neither `pip` nor
  `pip-tools` highlight any issues with it.
* While trying out `pipenv install` on our list of dependencies it would
  regularly fail to install utils with a "Will try again." message.
  While the installation succeeds after a retry, this doesn't inspire
  confidence.
* The switch to Pipfile and pipenv-managed virtualenvs requires a series
  of changes to `make` targets and scripts - replacing `pip install` with
  `pipenv`, removing references to requirements files and prefixing
  commands with `pipenv run`. While it's likely to simplify the overall
  process of managing dependencies, it would require time to properly
  implement across our applications and environments (Jenkins, PaaS,
  docker containers, and dev machines).
2018-07-10 14:59:04 +01:00
Katie Smith
07d274c2e6 Merge pull request #1935 from alphagov/new-letter-billing
Migration for new letter pricing
2018-07-10 11:42:09 +01:00
Katie Smith
c57f33a02d Use real letter_rates in tests
Added the letter_rate table to the list of tables which does not get
deleted after each test run and changed the tests to use the real letter
rates.

Also removed the letter rate DAO since this was only being used in
tests, so was no longer needed.
2018-07-10 11:31:18 +01:00
Katie Smith
8f211e00f5 Migration for new letter pricing
We now support letters of up to 5 sheets long, so we need to store the
rates for 4 and 5 sheet letters (both crown and non-crown) in the
`letter_rates` table.
2018-07-10 09:34:42 +01:00
Leo Hemsted
7fda32b7cf dashboard functions should return data for 8 days, not 7
really, it'll be somewhere btween 7 and 8 depending on what time of day
you request it at. But if today is monday, then seven days ago is last
tuesday - but we should return data for last monday as well so that
users see a full week's worth of data

also update/clarify the tests to make sure this is being honored for
all the different widgets on the dashboard
2018-07-09 12:03:53 +01:00
Chris Hill-Scott
d5469a9772 Clean up old, incomplete jobs
We have a few old jobs which don’t have a `processing_started` date.
This means that they always sort to the top of the jobs list in admin,
no matter how old they are. We think this is due to an old bug where
jobs would not be updated if a deploy was in progress.

This commit backfills the `processing_started` data for these jobs,
which will be roughly accurate. Complete accuracy is not the goal;
having these jobs not sort to the top of the list is.

This will affect 5 jobs across 3 services on production:
```sql
select service_id, job_status, created_at, updated_at, processing_started, processing_finished, notification_count, notifications_sent, notifications_delivered, notifications_failed from jobs where processing_started is null and job_status = 'in progress';
```

```
service_id              | job_status  |         created_at         |         updated_at         | processing_started | processing_finished | notification_count | notifications_sent | notifications_delivered | notifications_failed
--------------------------------------+-------------+----------------------------+----------------------------+--------------------+---------------------+--------------------+--------------------+-------------------------+----------------------
d47e5a1b-a04b-4398-8935-c8a266ce1d44 | in progress | 2017-09-29 13:49:41.512356 | 2017-10-01 02:01:05.281162 |                    |                     |              10615 |                  0 |                       0 |                    0
128b91b6-2996-4107-bb65-51b7c24a728d | in progress | 2017-09-29 09:25:39.802623 | 2017-09-29 16:01:02.154291 |                    |                     |              10240 |                  0 |                       0 |                    0
128b91b6-2996-4107-bb65-51b7c24a728d | in progress | 2017-09-29 09:31:52.455919 | 2017-09-29 16:01:01.990054 |                    |                     |               9930 |                  0 |                       0 |                    0
128b91b6-2996-4107-bb65-51b7c24a728d | in progress | 2017-08-22 08:15:39.125999 | 2017-08-22 16:01:07.758805 |                    |                     |               6967 |                  0 |                       0 |                    0
95316ff0-e555-462d-a6e7-95d26fbfd091 | in progress | 2016-05-27 14:44:18.114564 | 2016-06-13 00:18:14.542795 |                    |                     |               2742 |               2238 |                     525 |                 1713
(5 rows)
```
2018-07-09 11:33:15 +01:00