Commit Graph

3246 Commits

Author SHA1 Message Date
Leo Hemsted
09d6c60ff1 punycode encode emails before sending
amazon SES only accepts domains encoded in punycode, an encoding that
converts utf-8 into an ascii encoding that browsers and mailservers
recognise.

We currently just send through emails as we store them (in full
unicode), which means any rogue characters break SES and cause us to
put the email in technical-failure. Most of these appear to be typos
and rogue control characters, but there is a small chance that it could
be a real domain (eg https://🅂𝖍𝐤ₛᵖ𝒓.ⓜ𝕠𝒃𝓲/🆆🆃🅵/).

We should encode to and reply-to-address emails as punycode to make
sure that they can always be sent. The chance that anyone actually uses
a unicode domain name for their email is probably pretty low, but we
should allow it for completeness.
2019-08-12 13:53:22 +01:00
Katie Smith
355fb07eb2 Revert "Change email status to permanent-failure if SES raises InvalidParameterValue"
This reverts commit 51716fbaf8.

Instead of relying on catching SES errors we will convert all emails to
punycode before sending instead.
2019-08-12 13:51:24 +01:00
Katie Smith
3b670a0dbe Delete unused delivery blueprint 2019-08-12 10:54:11 +01:00
Katie Smith
51716fbaf8 Change email status to permanent-failure if SES raises InvalidParameterValue
If SES raised an `InvalidParameterValue` error (because an email address
was wrong) we were logging an exception and setting the email status to
`technical-failure`. We now set it to `permanent-failure` instead and
change the log level to `info` - setting it to `permanent-failure` means
that people will know not to retry the message.
2019-08-12 10:24:59 +01:00
Katie Smith
e449e234db Retry deliver_sms task immediately if sending fails
If the `deliver_sms` catches an exception when trying to send an SMS, we
want the first retry to happen immediately (because we will have
switched providers), then every retry after that to happen at the
standard intervals.
2019-08-08 09:34:38 +01:00
Rebecca Law
16fd12be6a If a job was created 7 days ago but scheduled to send 2 days later, the csv file will be deleted from S3 two days early.
For example if a file is uploaded on Aug 1, but scheduled for Aug 3, the csv file will be deleted 2 days before the notifications.
This will cause an error for on the jobs pages if the download report link is clicked.
2019-08-07 16:54:04 +01:00
Leo Hemsted
2c2eb2abad handle 405s
Handle werkzeug http errors separately. Also, improve the generic
`Exception` handler to be more flexible when exceptions don't look
like http errors.

note: because they're 405s the route isn't matched, so the v2 error
handlers don't trip properly. this might be an issue because the
internal endpoints expect a different return format. Might have to
think about how to handle this.
2019-07-26 13:26:20 +01:00
Pea (Malgorzata Tyczynska)
359016de6a Merge pull request #2565 from alphagov/migrate_org_types
Migrate org types
2019-07-26 10:51:42 +01:00
Pea Tyczynska
38bb2c1cf6 Simpify org types migration script and introduce foreign key
Don't transform org types on prod
2019-07-24 17:55:56 +01:00
Katie Smith
b4a6aecbb9 Add endpoint to return monthly notification stats per service
This will be used by notifications-admin to create a CSV report.
2019-07-23 10:00:50 +01:00
Katie Smith
81de71dc1f Add dao function that gets the required data 2019-07-23 10:00:50 +01:00
Pea Tyczynska
5b256fa64e Migrate all orgs and services onto new organisation types
Remove all mentions of generic 'nhs' organisation type.
2019-07-22 14:58:41 +01:00
Pea (Malgorzata Tyczynska)
da61bb3b06 Merge pull request #2557 from alphagov/more_org_types
Introduce new organisation types and organisation_types db table
2019-07-22 14:55:30 +01:00
Pea (Malgorzata Tyczynska)
c0966ad90d Merge pull request #2563 from alphagov/change_content_cancel_letter_job
Change content of error messages when letter job can't be cancelled.
2019-07-22 13:28:11 +01:00
Pea (Malgorzata Tyczynska)
957cf46748 Change apostrophes to prettier ones
Co-Authored-By: Chris Hill-Scott <me@quis.cc>
2019-07-22 10:48:34 +01:00
Chris Hill-Scott
da1219fadf Let services have no default letter contact blocks
If they delete the default we’ll treat ‘Blank’ as the default on the
frontend.
2019-07-22 10:40:18 +01:00
Chris Hill-Scott
dd225fbc6e Dissociate letter contact blocks before archiving
Otherwise you can’t archive it.
2019-07-19 15:40:28 +01:00
Pea Tyczynska
aa88252cf7 Drop making crown not nullable on downgrade as it would fail anyway 2019-07-18 17:05:24 +01:00
Pea Tyczynska
d89ef0594f nhs_central is crown org and also we do not update org type while
updating service anymore.
2019-07-18 17:05:24 +01:00
Pea Tyczynska
e4cb56b5d3 Emergency service instead of emergency services 2019-07-18 17:05:23 +01:00
Pea Tyczynska
8a3ac8400f Update service type and crown when service is added to organisation 2019-07-18 17:05:23 +01:00
Pea Tyczynska
9dfc550f46 Add org types table 2019-07-18 17:05:22 +01:00
Rebecca Law
996dcdd88c Increase the number of days we rebuild the tables for 2019-07-18 16:45:27 +01:00
Pea Tyczynska
e9de84beb0 Change content of error messages when letter job can't be cancelled.
This content was first done without help of content designer so
now it is improved with the help of one. New content is more
in line with the content in the admin app and more human-readable
and following GOV.UK standard.
2019-07-18 16:38:08 +01:00
Rebecca Law
ed611f982c We found a problem with the report tasks that populate the fact tables (or statistic tables). It is possible that the notification status can change for notifications after 4 days.
This PR updates those queries to look in either Notification or NotificationHistory. Since the data does not exist in both tables at the same time we can do with and not worry about the data retention.
The query will iterate over each service, then each notification type and query the data if no results then try the history table.
2019-07-18 15:29:54 +01:00
Katie Smith
1671221642 Set org_type of a service when adding/updating org org type
The organisation_type of a service should match the organisation_type of
the service's organisation (if there is one). This changes
dao_update_organisation and dao_add_service_to_organisation to set the
organisation_type of any services when adding / updating an org.
2019-07-12 16:43:37 +01:00
Leo Hemsted
a0c0dec429 add tests
include dynamically loading the template contents from the alembic upgrade file itself
2019-07-12 15:14:13 +01:00
Chris Hill-Scott
3e11d2492a Merge pull request #2552 from alphagov/create-update-org-extra-fields
Add extra fields to create/update organisation
2019-07-12 15:03:56 +01:00
Chris Hill-Scott
4a2e906dfb Merge pull request #2540 from alphagov/remove-old-fields-from-organisations-and-services
Remove old fields from organisations and services
2019-07-10 11:02:26 +01:00
Pea (Malgorzata Tyczynska)
e3fdfff29b Merge pull request #2543 from alphagov/cancel-letter-job
Cancel letter job
2019-07-04 14:25:17 +01:00
Pea Tyczynska
8588d00657 Move tests closer to the code:
test can_letter_job_be_cancelled closer to the code
test dao_cancel_letter_job closer to the code
Mock out calls in cancel_letter_job to test just that method
2019-07-04 14:12:11 +01:00
Chris Hill-Scott
a4ae534f87 Add extra fields to create/update organisation 2019-07-03 16:46:01 +01:00
Katie Smith
1ebd147ad0 Merge pull request #2551 from alphagov/fix-0-billable-units
Fix 0 billable units on provider callback
2019-07-02 09:12:55 +01:00
Pea Tyczynska
090769a069 Pull cancellable job statuses from utils and fix tests 2019-07-01 15:45:03 +01:00
Pea Tyczynska
da65ba0c91 Return specific error messages if job cannot be cancelled
Also move checking if job can be cancelled to the endpoint
2019-07-01 15:44:39 +01:00
Pea Tyczynska
cc966b1cf0 More checks and tests for cancelling a letter job 2019-06-28 15:57:39 +01:00
Rebecca Law
663b260777 Adding a cancel-letter-job endpoint to cancel a letter job. 2019-06-28 15:57:39 +01:00
Rebecca Law
6565c19a9b Adding new method to cancel a letter job. 2019-06-28 15:57:39 +01:00
Rebecca Law
b45db5cab3 Merge pull request #2538 from alphagov/fix-team-recipient-check
Update to unit tests
2019-06-28 14:40:16 +01:00
Katie Smith
4f7cde3452 Fix 0 billable units on provider callback
We occasionally get an SMS with 0 `billable_units` if the `delivery-sender-worker`
is stopped in the middle of processing a notification - we have to fix
these manually. This change checks the billable units when we get the response from
our SMS provider and sets the correct billable units if it's 0.
2019-06-28 12:19:21 +01:00
Pea (Malgorzata Tyczynska)
ccfa1c8228 Revert "Ensure dao_create_template doesn't clash with new trigger" 2019-06-26 18:01:20 +01:00
Katie Smith
38fb7af2be Merge pull request #2546 from alphagov/bump-utils
Bump utils to add alt text to email branding
2019-06-26 09:35:44 +01:00
Katie Smith
284785a7d7 Bump utils to add alt text to email branding
Utils 33.0.0 adds alt text to email branding - the HTMLEmailTemplate now
initializes slightly differently as a result (with both `branding_name`
and `branding_text`).
2019-06-25 16:53:07 +01:00
Pea (Malgorzata Tyczynska)
e4c90c4bb9 Merge pull request #2536 from alphagov/ensure_no_errors_when_creating_template
Ensure dao_create_template doesn't clash with new trigger
2019-06-25 16:19:48 +01:00
Rebecca Law
35d2e099f7 - Removed unused method parameters.
- Use parametrize for test.
2019-06-25 16:16:50 +01:00
Rebecca Law
b24acfea8f Merge branch 'master' into fix-team-recipient-check 2019-06-25 15:58:40 +01:00
Pea Tyczynska
673cabe6b8 Ensure dao_create_template doesn't clash with new trigger
New trigger creates template_redacted row after insert to template
table

And update tests
2019-06-25 15:40:10 +01:00
Katie Smith
a790acc091 Create a Zendesk ticket for letters in the wrong state
This creates a Zendesk ticket if either the
`check_precompiled_letter_state` or `check_templated_letter_state` tasks
fail.
2019-06-18 10:58:58 +01:00
Katie Smith
c518f6ca76 Add scheduled task to find old letters which still have 'created' status
Added a scheduled task to run once a day and check if there were any
letters from before 17.30 that still have a status of 'created'. This
logs an exception instead of trying to fix the error because the fix
will be different depending on which bucket the letter is in.
2019-06-18 10:58:58 +01:00
Katie Smith
a2f324ad7e Add scheduled task to find precompiled letters in wrong state
Added a task which runs twice a day on weekdays and checks for letters that have
been in the state of `pending-virus-check` for over 90 minutes. This is
just logging an exception for now, not trying to fix things, since we
will need to manually check where the issue was.
2019-06-18 10:58:58 +01:00