Commit Graph

7236 Commits

Author SHA1 Message Date
David McDonald
82cb1593b8 Merge pull request #2859 from alphagov/bump-utils
Bump utils to 39.4.2 to fix whitespace strip bug
2020-06-01 11:58:02 +01:00
David McDonald
a497f1b945 Bump utils to 39.4.2 to fix whitespace strip bug
https://github.com/alphagov/notifications-utils/pull/742

We had been seeing phone numbers making it through in jobs containing
this no-break space which were then causing errors as we could not
process the job as it thought it was an invalid number. This should
solve the problem and strip that special character.
2020-06-01 11:12:05 +01:00
Leo Hemsted
5bd400da7d Merge pull request #2858 from alphagov/more-timings
add raw request timings to provider send functions
2020-05-29 15:27:54 +01:00
Leo Hemsted
f2f2509c9b add raw request timings to provider send functions
we're using statsd to monitor how long provider requests are taking.
However, there's lots of busy work that happens inside our statsd
metrics timing window. Things like json dumping and loading, building
headers, exception handling, etc.

for firetext/mmg, the response object from requests has an elapsed
property [1], which captures from sending raw data to parsing the
response headers. for ses, it's a bit trickier, but boto3 exposes a few
event hooks [2]. it's hard to find them without stepping through the
code, but the interesting ones are before-call, after-call,
after-call-error, request-created, and response-received. The
before-call and after-call involve some marshalling, built-in retrying,
etc, while request-created and response-received are much lower level.
They might be called more than once per ses request, if boto3 itself
retries the request on 5xx, 429 and low level socket errors [3].

Add these as new `raw-request-time` metrics rather than overwriting to
avoid changing the meaning of an existing metric, and to let us compare
the metrics to see if there's a noticeable difference at all

[1] https://requests.readthedocs.io/en/master/api/#requests.Response.elapsed
[2] https://boto3.amazonaws.com/v1/documentation/api/latest/guide/events.html
[3] https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html#legacy-retry-mode
2020-05-29 14:04:46 +01:00
Leo Hemsted
5462087f21 Merge pull request #2840 from alphagov/api-failwhale
add api-paas-failwhale
2020-05-28 13:49:42 +01:00
Chris Hill-Scott
b404e2ca67 Merge pull request #2852 from alphagov/bump-utils-letter-timings
Bump utils to 39.4.0
2020-05-26 11:30:29 +01:00
Chris Hill-Scott
cac24bfc5e Bump utils to 39.4.1 2020-05-26 11:20:15 +01:00
Chris Hill-Scott
14d5db58f4 Bump utils to 39.4.0
Adds delivery estimates for letters posted to Europe or the rest of the
world.
2020-05-26 11:20:14 +01:00
Katie Smith
29caa362a3 Merge pull request #2851 from alphagov/archive-service
Allow service to be archived if service with the same name has already been archived
2020-05-22 11:12:32 +01:00
Katie Smith
b1d9fd3ee9 Merge pull request #2853 from alphagov/dependency-upgrades
Dependency upgrades
2020-05-22 11:12:23 +01:00
Katie Smith
f22483a1ab Delete unused Marshmallow schemas 2020-05-22 10:49:59 +01:00
Katie Smith
e770108ec4 Update sqlalchemy from 1.3.13 to 1.3.17 2020-05-22 10:43:29 +01:00
Katie Smith
20e97bf78a Update psycopg2-binary from 2.8.4 to 2.8.5 2020-05-22 10:41:16 +01:00
Katie Smith
ba38a2d5dd Update marshmallow from 2.20.5 to 2.21.0 2020-05-22 10:38:27 +01:00
Katie Smith
8c72dabbe8 Update marshmallow-sqlalchemy from 0.22.3 to 0.23.0 2020-05-22 10:36:21 +01:00
Katie Smith
bd0ba67889 Update eventlet from 0.25.1 to 0.25.2 2020-05-22 10:34:13 +01:00
Katie Smith
eae99f7504 Update flask from 1.1.1 to 1.1.2 2020-05-22 10:31:15 +01:00
Katie Smith
d06c7adb82 Update flask-migrate from 2.5.2 to 2.5.3 2020-05-22 10:29:16 +01:00
Katie Smith
64cd8f39c2 Add the date to the service name and email_reply_to when archiving
This copies what we do to a user's email address when archiving the user
by prefixing it with `_archived_{date}`. We already prefixed the
service name and email_reply_to with `_archived`, but this didn't allow
a service with the same name to be archived more than once.
2020-05-22 09:37:45 +01:00
Katie Smith
13f7fecd5b Move function to get archived email address value
This function will be used when archiving services too, so it has been
renamed and moved to `app/utils.py`.
2020-05-22 09:36:07 +01:00
Katie Smith
6e18250fe4 Merge pull request #2849 from alphagov/revert-postage-constraint-2
Revert the new postage constraints
2020-05-20 18:45:37 +01:00
Katie Smith
0b28766442 Reverts the new postage constraints
Reverts https://github.com/alphagov/notifications-api/pull/2843 and https://github.com/alphagov/notifications-api/pull/2848
2020-05-20 18:31:25 +01:00
Katie Smith
5f46d7ba3e Merge pull request #2848 from alphagov/add-commit-migration
Adding a commit at the end of each migration file.
2020-05-20 16:59:26 +01:00
Rebecca Law
fa7d2c2c3f Adding a commit at the end of each migration file.
The assumption that a commit is issued in between migration files was false. This will force the db connection to commit, the alter table commands will complete and the alembic version updated.
2020-05-20 16:50:46 +01:00
Katie Smith
4116affe7f Merge pull request #2843 from alphagov/update-postage-constraint-take-2
Update postage constraint (take 2)
2020-05-20 14:41:44 +01:00
Chris Hill-Scott
95a779c649 Merge pull request #2841 from alphagov/jobs-by-contact-list
Allow jobs to be grouped by contact list
2020-05-20 11:49:25 +01:00
Katie Smith
6d89b01f1e Update JSON schema postage validation for new values 2020-05-19 16:04:36 +01:00
Katie Smith
7fd52017d0 Update postage db constraints for international letters
The `notifications`, `notification_history`, `templates` and `templates_history`
tables all had a check constraint on the postage column which specified
that the postage had to be `first` or `second` if the notification or
template was a letter. We now have two more options for postage -
`europe` and `rest-of-world`.

It's not possible to alter a check constraint, so the constraints have
to be dropped then recreated. We are not recreating the constraint on
the `notification_history` table since values here are always copied
from the `notifications` table.

The constraints get added as `NOT VALID` at first - this stage will lock
the tables, so updating the `notification` table and `templates` and
`templates_history` are done in separate migrations so that we don't lock
all tables at the same time. In a third migration we then run
`VALIDATE CONSTRAINT` for all tables - this will lock a row at a time,
not the whole table.
2020-05-19 16:04:36 +01:00
Chris Hill-Scott
c7f914122a Merge pull request #2839 from alphagov/group-letter-uploads
Group letter uploads by printing day
2020-05-19 11:05:14 +01:00
David McDonald
f87793d094 Merge pull request #2846 from alphagov/purge-command
Purge command
2020-05-19 10:20:49 +01:00
David McDonald
2f0b3a9636 Fix edge case in func test data purging for created_by_id
When running the purge command I found about 4 users who could not be
deleted because their user id was still referenced in the services table
as they had created the service yet they were not a member of that
service anymore.

I have fixed this by checking that if they are not a member but created
the service then we also delete the service for them.

Note, I've followed the previous convention of no tests for this
function. I've run it locally and executed the code path so there should
be no major flaws in the code. There is a small chance I wasn't able to
exactly replicate the state that existed in preview on my local but
hopefully it was close enough to be accurate.
2020-05-18 10:30:28 +01:00
David McDonald
df5ccae4c5 Add in positive logging case for purge command
This is useful so we can see that it's doing things, which case is being
hit and know that an empty terminal for an hour isn't a bad thing
2020-05-15 17:34:30 +01:00
David McDonald
dbb2dfa502 Merge pull request #2836 from alixedi/add-csv-support
Add support for CSV files
2020-05-15 12:16:16 +01:00
Rebecca Law
fb2bfd30dc Merge pull request #2844 from alphagov/ignore-dateformat-error
Ignore Parse error in receive notifications endpoint
2020-05-13 10:51:57 +01:00
Rebecca Law
aecf17fef1 This morning we raise a ParseError for a bad date format for the DateReceived attribute on the /notifications/receive/mmg request.
This PR tries to parse the date, if that throws an error return now as the datereceived. This will at least allow the message to be persisted. Typically the DateReceived, provider_date, and the created_at date in the inbound_sms table are within a second of each other.
2020-05-13 10:37:41 +01:00
Chris Hill-Scott
cce153eee8 Return 400 for bad date argument
It’s more of a bad request, because the input is bad, rather than
something on our side being not found.
2020-05-13 08:56:54 +01:00
Chris Hill-Scott
c61f7e70c2 Add comments to explain time intervals 2020-05-13 08:53:40 +01:00
Leo Hemsted
51511450a2 add api-paas-failwhale
for use when we don't want API to serve any traffic, but paas is still
running. It's a simple nginx_buildpack app that is pushed separately,
and then two makefile commands that toggle the routes (and also
stop/start the nginx app).

For all endpoints/methods it returns a 503, with the response body.

```
{
    "status_code": 503,
    "errors": [
        {
            "error": "PlannedMaintenanceError",
            "message": "We’re performing some essential updates. Notify will be back shortly. Please check https://status.notifications.service.gov.uk/ for more details"
        }
    ]
}
```

NB: If you hit `/` it'll still return 404 - as this is defined in the
paas-proxy instance on aws.
2020-05-12 16:04:18 +01:00
Chris Hill-Scott
c8cd3c2b70 Return template name in job response
If you’ve sent a bunch of jobs from the same contact list then a handy
way to differentiate between them will be date sent, but also template
name (in effect the message you sent).

This commit extends the job response to include template name, using the
same pattern as for template type.
2020-05-12 13:10:39 +01:00
Chris Hill-Scott
3ed1700231 Count how many times a contact list has been used
Because we’ll be grouping jobs under their parent contact lists it will
be useful to have a way of showing how many times a contact list has
been used. This will give the right information scent to indicate that
clicking into a contact list is where you go to see its jobs. This means
that the API needs to return a count of jobs for each contact list.

Putting this code feels very non-idiomatic for our API. So suggestions
about how to better architect it welcome…
2020-05-12 13:00:54 +01:00
Chris Hill-Scott
18ffccf8c9 Allow jobs to be filtered by contact list
Rather than showing all jobs that have been ‘copied’ from a contact list
I think it makes more sense to group them under the contact list. This
way it’s easier to see what messages have been sent to a given group of
contacts over time.

Part of this work means the API needs to return only jobs that have been
created from a given contact list, when asked.
2020-05-12 12:58:39 +01:00
Chris Hill-Scott
27a0ba1a65 Reformat arguments for readability
We want to add another argument here, and doing so would make the line
length too long with all the arguments on one line.

Also uses the * operator to enforce keyword-only arguments.
2020-05-12 12:57:54 +01:00
Pea M. Tyczynska
2f8947afde Merge pull request #2832 from alphagov/move-pdf-creation-on-a-template-preview-task
Move pdf creation onto a template preview task
2020-05-11 16:18:58 +01:00
Pea Tyczynska
5d6f2da155 Rename task from create_letters_pdf to get_pdf_for_templated_letter
In a separate PR we will have to delete vestigial create_letters_pdf
tasks that now only redirects to get_pdf_for_templated_letter.
2020-05-11 13:33:05 +01:00
Pea Tyczynska
879d15b736 Test logging and error message 2020-05-11 13:33:04 +01:00
Pea Tyczynska
131372bdd8 Parametrize testing of letter branding to avoid repeating ourselves 2020-05-11 13:33:04 +01:00
Pea Tyczynska
3a00c19390 Polish and test the small task that updates billable units for letter 2020-05-11 13:32:09 +01:00
Pea Tyczynska
24a89c1c19 Modify tasks for getting letter pdf and updating billable units
So that they talk with new template preview task for pdf creation
2020-05-11 13:30:59 +01:00
Chris Hill-Scott
864c6772b3 And an endpoint to get uploaded letters for a day
Because we won’t be showing uploaded letters individually on the uploads
page any more we need a way of listing them. This should be by printing
day, to match how we’re grouping them on the uploads page.

The response matches a normal `get_notifications` response so we can
reuse the same code in the admin app.
2020-05-11 10:51:40 +01:00
Chris Hill-Scott
421c1aac96 Group uploaded letters by day of printing
Some teams have started uploading quite a lot of letters (in the
hundreds per week). They’re also uploading CSVs of emails. This means
the uploads page ends up quite jumbled.

This is because:
- there’s just a lot of items to scan through
- conceptually it’s a bit odd to have batches of things displayed
  alongside individual things on the same page

So instead this commit starts grouping together uploaded letters. It
does this by the date on which we ‘start’ printing them, or in other
words the time at which they can no longer be cancelled.

This feels like a natural grouping, and it matches what we know about
people’s mental models of ‘batches’ and ‘runs’ when talking about
printing.

The code for this is a bit gnarly because:
- timezones
- the print cutoff doesn’t align with the end of a day
- we have to do this in SQL because it wouldn’t be efficient to query
  thousands of letters and then do the timezone calculations on them in
  Python
2020-05-11 10:51:33 +01:00