Commit Graph

8192 Commits

Author SHA1 Message Date
Ben Thorner
2ff187400d Merge pull request #3234 from alphagov/increase-sms-fail-thresh
Increase warning threshold for SMS failures
2021-05-06 10:52:38 +01:00
Ben Thorner
bd45d788c0 Increase warning threshold for SMS failures
Second attempt [1]. This increases the threshold so:

- It's a more substantial amount of money lost (£16).

- It's 10% of the minimum free allowance for a service.

- It's greater than the threshold we have for TV numbers (500).

Having a higher threshold for this alert will help prevent wasted
effort investigating more negligible failures, and reduces the
ambiguity of whether we should take action: we should.

[1]: https://github.com/alphagov/notifications-api/pull/3221
2021-05-05 17:54:43 +01:00
Ben Thorner
4bbba69e0b Merge pull request #3232 from alphagov/rewrite-migration-readme
Rewrite migration README
2021-05-05 14:46:07 +01:00
Ben Thorner
618ce14842 Rewrite migration README
This clarifies how we generate migration filenames, and points to
the official docs and help commands, instead of repeating them.
2021-05-05 14:27:05 +01:00
Rebecca Law
0161adca06 Merge pull request #3228 from alphagov/sqlalchemy-update
SQLAlchemy update
2021-05-04 14:03:05 +01:00
Rebecca Law
590f29b28a SQLAlchemy 1.4 requires SQLALCHEMY_DATABASE_URI to use postgresql rather than postgres for the connection uri to the database.
When deploying to paas the database postgres environment variables are set using VCAP_SERVICES provided by PaaS. When we start up the app and set the properties we need to replace the postgres string with postgresql for the app to start up properly.
This wasn't caught locally or with the unit tests because we were setting this property with postgresql.
2021-04-29 13:49:37 +01:00
Rebecca Law
424796bdcc Add unit test for archiving a template with a template folder 2021-04-29 13:32:36 +01:00
Rebecca Law
4f196316aa Change the query to get the services to purge to use query on the db.Model rather than db.session.query.
`service_ids_to_purge` is a list of `row` object rather than a list of `UUID`.

NOTE: db.session.query(Service).filter(Service.id.notin_(services_with_data_retention)).all() would have also worked. It seems that only selecting attributes from the db.Model has caused the change.
2021-04-29 13:32:36 +01:00
Rebecca Law
68d28aa83b The update of SQLAlchemy 1.4.10 has caused some conflicts in our code. This PR fixes most of those conflicts.
- sqlalchemy.sql.expression.case must include an else statement.
- clearly define list of columns for inbound_sms_history insert, getting the list from InboundSmsHistory.__table__.c was causing data type errors.
- remove relationships when not needed, the foreign key relationship is established in the creation of the column. This will get rid of the warnings referenced here: http://sqlalche.me/e/14/qzyx.
- update queries now that he user relationship in ServiceUser db model has been removed.
- move the check that a template is archived to the view instead of the dao method. The check was clearing the session before the version history could be done.

Deleting notifications in the night tasks still needs to be
investigated. The raw sql is causing an error.
2021-04-29 13:32:36 +01:00
Pea Tyczynska
df19a91b7f Update error messages after SQLAlchemy version update 2021-04-29 13:32:36 +01:00
Pea Tyczynska
317ae5dbd4 Apply requirements update 2021-04-29 13:32:36 +01:00
pyup-bot
022c3bf178 Update sqlalchemy from 1.3.23 to 1.4.10 2021-04-29 13:32:36 +01:00
Ben Thorner
23f4ae32df Merge pull request #3214 from alphagov/check-broadcast-suspended
Enforce service suspension for broadcasts
2021-04-28 15:01:11 +01:00
Rebecca Law
d6b7b07767 Merge pull request #3226 from alphagov/revert-3219-pyup-scheduled-update-2021-04-21
Revert "Scheduled weekly dependency update for week 16"
2021-04-28 10:36:18 +01:00
Rebecca Law
85895a9e8b Revert "Scheduled weekly dependency update for week 16" 2021-04-28 10:17:16 +01:00
Rebecca Law
10b0554784 Merge pull request #3219 from alphagov/pyup-scheduled-update-2021-04-21
Scheduled weekly dependency update for week 16
2021-04-28 09:20:35 +01:00
David McDonald
2d345afab8 Merge pull request #3223 from alphagov/earlier-alerts
Make check-if-letters-still-in-created run at 7am
2021-04-27 17:29:12 +01:00
David McDonald
5b053d645b Merge pull request #3224 from alphagov/make-help
Add make help commands for commonly used tasks
2021-04-27 17:28:40 +01:00
Rebecca Law
be797ea513 Merge pull request #3215 from alphagov/add-unique-key-annual-billing
Add unique key on annual_billing for service_id + financial_year_start.
2021-04-27 14:14:10 +01:00
Ben Thorner
c716f5327d Merge pull request #3222 from alphagov/inject-request-id-send-task
Move request_id injection into send_task override
2021-04-27 12:51:19 +01:00
Rebecca Law
dcd08a0e45 Add unit test for archiving a template with a template folder 2021-04-27 12:30:50 +01:00
David McDonald
70c573ae08 Add make help commands for commonly used tasks
if you run `make help` or just `make` then you get a nice list of the
tasks that you can run (or at least, the ones with help text added to
them.

We were missing these for some of the key commands that a developer
would want to know about.

By adding help text to them, they will now show up in `make` or `make
help` and saves a developer needing to go either look in the README or
go look in the Makefile to figure out what commands are available.

Note, there is no particular convention around which commands have help
comments. I don't think we need to figure out this but at the least, the
ones which developers may want to run locally I think should show up.
2021-04-27 12:00:53 +01:00
David McDonald
f194231d87 Make check-if-letters-still-in-created run at 7am
If this alert goes off in the morning, it usually means we need to do
something, ideally quite quickly as it indicates a potential problem
with the sending of letters over to DVLA the night before.

Given this goes off at 9am at the moment, but actually some people start
work earlier, if we alert at 7am it means it will likely be looked at
earlier in the day and we can potentially fix any problems with letters
sooner than later.
2021-04-27 11:26:18 +01:00
Ben Thorner
99bc29418e Move request_id injection into send_task override
This applies the same change we made in other apps [1][2]. Adding
the override here is special, though, because it means the others
will now get triggered, since this app is the start of the chain
of tasks for a request. We will also retain existing request_id
tracing for tasks within this app, since "apply_async" calls the
"send_task" method internally, which is the one we're overriding.

[1]: 6f3c118a1e
[2]: 2e08b7aa95
2021-04-27 10:35:21 +01:00
Rebecca Law
f941768d8c Change the query to get the services to purge to use query on the db.Model rather than db.session.query.
`service_ids_to_purge` is a list of `row` object rather than a list of `UUID`.

NOTE: db.session.query(Service).filter(Service.id.notin_(services_with_data_retention)).all() would have also worked. It seems that only selecting attributes from the db.Model has caused the change.
2021-04-27 08:36:34 +01:00
Rebecca Law
5f26d16915 Merge pull request #3218 from alphagov/precomplied-letter-transation
Introduce transaction for precompiled letters
2021-04-26 13:10:31 +01:00
Rebecca Law
1b070d69a1 The update of SQLAlchemy 1.4.10 has caused some conflicts in our code. This PR fixes most of those conflicts.
- sqlalchemy.sql.expression.case must include an else statement.
- clearly define list of columns for inbound_sms_history insert, getting the list from InboundSmsHistory.__table__.c was causing data type errors.
- remove relationships when not needed, the foreign key relationship is established in the creation of the column. This will get rid of the warnings referenced here: http://sqlalche.me/e/14/qzyx.
- update queries now that he user relationship in ServiceUser db model has been removed.
- move the check that a template is archived to the view instead of the dao method. The check was clearing the session before the version history could be done.

Deleting notifications in the night tasks still needs to be
investigated. The raw sql is causing an error.
2021-04-26 11:50:30 +01:00
Pea Tyczynska
e1a626855d Update error messages after SQLAlchemy version update 2021-04-23 16:48:36 +01:00
Rebecca Law
490efad97a To avoid any table locks and contention on the production database we
are going to add the unique index concurrently. This only works if we
execute a commit first.
2021-04-23 15:16:18 +01:00
Chris Hill-Scott
b031b69bfa Merge pull request #3220 from alphagov/fix-broadcast-length-validation
Normalise broadcast content before validating length
2021-04-23 11:20:41 +01:00
Chris Hill-Scott
f8bca5765d Validate length of broadcast templates on creation
This is a belt-and-braces check because the admin app already checks
this. But since we do it for SMS already it makes sense to replicate it
for broadcast templates.
2021-04-22 17:11:31 +01:00
Pea Tyczynska
66127f3800 Apply requirements update 2021-04-22 16:59:15 +01:00
Chris Hill-Scott
7c6ae40034 Normalise broadcast content before validating length
This changes the content length validation of the internal API to match
the validation of the public broadcast API[1].

This removes the length check from JSONSchema, which isn’t sophisticated
enough to deal with things like normalising newlines or handling
different encodings.

The admin app should catch these errors before they’re raised here, but
it’s best to be belt and braces.

1.7ab0403ae7/app/v2/broadcast/post_broadcast.py (L53-L63)
2021-04-22 14:42:54 +01:00
Rebecca Law
cb8ec9a4f7 Wrap the saving the notification and uploading the precompiled letter to
s3 in a transation.

If the upload to s3 fails the notification will not be saved to the
database.
2021-04-22 13:39:41 +01:00
pyup-bot
c07e991c0a Update sqlalchemy from 1.3.23 to 1.4.10 2021-04-21 14:00:02 +01:00
Katie Smith
7ab0403ae7 Merge pull request #3216 from alphagov/bcast-logging
Add detail to broadcast logging messages
2021-04-21 09:03:38 +01:00
Rebecca Law
fbd231cefd Merge pull request #3179 from alphagov/add-international-firetext-api-key
Add international API key for firetext
2021-04-21 08:49:11 +01:00
Katie Smith
e6357c91c9 Add more details to messages in send_broadcast_provider_message task
This ensures that the log messages both contain broadcast_event id and
broadcast_provider_message id. It also removes the broadcast_event
reference since this isn't particularly useful in helping to find an
event.
2021-04-20 15:34:49 +01:00
Katie Smith
c9c4bd8b44 Clarify log line when sending a link test
It wasn't clear what the ID in the message was. It's not possible to add
more details to the message - we don't create a broadcast message or
event for a link test.
2021-04-20 14:54:53 +01:00
Pea Tyczynska
38af26cc78 Merge pull request #3199 from alphagov/admin-cancel-broadcast
Allow platform admins to cancel broadcasts.
2021-04-20 14:47:45 +01:00
Rebecca Law
f3fdd3b09b Add internation api key for firetext.
We want to start using Firetext for sending international SMS. They
require us to use a different API key for international SMS because it
requires a new code path to switch the sender ID to something that the
country will accept.
This PR does not include switching the sender of international SMS to
Firetext but sets us up to do so.
2021-04-20 13:58:55 +01:00
Rebecca Law
a637c8eb92 Add unique key on annual_billing for service_id + financial_year_start.
This is an extra precaution for the table to ensure data integrity. Since we only update/insert the data using the annual_billing_dao methods the integrity is in tact. I've check the data on preview, staging and prod there are no violations of this unique key.
2021-04-20 13:42:20 +01:00
Pea Tyczynska
fce6a2d8dc Allow platform admins to cancel broadcasts.
Also update error message for when someone does not have permissions.

The message referenced approving broadcasts specifically, whereas
people would also see it if they try to cancel or reject
broadcast without permission.

Why we allow platform admins to cancel broadcasts:
we do this so they can react quickly if a broadcast was
approved by accident.
2021-04-20 12:27:38 +01:00
Rebecca Law
f2167aae2b Merge pull request #3213 from alphagov/set-annual_billing-to-default-if-missing
Set free allow to default if row is missing when calling GET
2021-04-20 08:02:04 +01:00
Ben Thorner
0507e8d9ad Raise 403 when broadcasting on a suspended service
This mirrors the approach we take for jobs [1].

[1]: 3d71815956/app/job/rest.py (L146)
2021-04-19 17:13:16 +01:00
Ben Thorner
a2af8b052a Split up authorisation vs. sequencing checks
While both of these are integrity errors (since we should never
reach this point in the code + data), this just means the original
method comment is still relevant to what immediately follows it.
2021-04-19 17:13:15 +01:00
Ben Thorner
936c9ebdfe Test sanity checks by calling top-level task
Since the checks are only performed in one place we can easily take
extra care to ensure this in the tests, noting that we don't need to
do any additional setup, except if no exception is raised - I've left
these tests as-is, to avoid doing more setup.

Note that we still check the happy path for when a provider message is
already sending - just in a different test [1].

[1]: 3d71815956/tests/app/celery/test_broadcast_message_tasks.py (L263)
2021-04-19 17:13:14 +01:00
Ben Thorner
ee52e3e2c9 Mirror integrity checks from the API
It makes sense to have these checks [1] here, since in future we may
add other ways of creating a broadcast event and omit them.

[1]: 3d71815956/app/broadcast_message/rest.py (L198)
2021-04-19 17:13:13 +01:00
Ben Thorner
0070473f31 Check for suspension before sending a broadcast
This mirrors the check we do for jobs, which are also a high-impact
task [1]. While this shouldn't be possible, just like other checks
we're adding it here to be doubly certain.

[1]: 3d71815956/app/celery/tasks.py (L74)
2021-04-19 17:13:12 +01:00
Ben Thorner
b2398fcaf4 Rename CBCProxyFatalException
We only actually use this when the data we're working with is in an
unexpected state, which is unrelated to the CBC Proxy. Using this
name also means we can re-use this exception in the next commits.

Note that we may still care if a broadcast message has expired, since
it's not expected that someone would send one in this condition.
2021-04-19 17:13:05 +01:00