Commit Graph

7432 Commits

Author SHA1 Message Date
Katie Smith
8e1fa6ab50 Merge pull request #2940 from alphagov/bump-eventlet
Bump eventlet
2020-07-31 10:51:26 +01:00
Katie Smith
baebc5bdaf Bump eventlet
dnspython had been changed from 1.16.0 to 2.0.0 in a previous commit,
but this was not compatible with eventlet 0.25.2. This bumps eventlet to
a later version, which has the effect of downgrading dnspython again.
2020-07-31 10:36:09 +01:00
Katie Smith
475678a5e5 Merge pull request #2938 from alphagov/more-letter-validation
Check for invalid characters in letter addresses
2020-07-31 09:10:00 +01:00
Katie Smith
c9f663fe76 Check for invalid chars in letter addresses when sending through the API
This uses the new method in notifications-utils to validate for invalid
characters in address blocks.
2020-07-31 08:58:56 +01:00
Katie Smith
4931fc396c Bump utils to 40.6.0
This brings in validation for invalid characters in address lines.
2020-07-31 08:58:56 +01:00
Rebecca Law
fbdae0ce30 Merge pull request #2937 from alphagov/indexes-for-notification_history
This migration will bring all environments in line with the prod
2020-07-30 08:28:35 +01:00
Rebecca Law
180ed86a27 This migration will bring all environments in line with the prod.
There are a few indexes that we still need to drop from prod notification_history. Indexes on prod can take too long to run in a migration so we need to run them manually.
2020-07-30 07:46:51 +01:00
Leo Hemsted
1adb460f5c Merge pull request #2936 from alphagov/broadcast-event-model
add broadcast_event table
2020-07-28 15:03:20 +01:00
Leo Hemsted
df2ec8d99f update comments in models.py 2020-07-28 12:10:18 +01:00
Leo Hemsted
bdf221a421 add tests for get_earlier_events_for_broadcast_event 2020-07-28 12:10:18 +01:00
Leo Hemsted
3dd15841a5 create get_dt_string_or_none string
mostly to quash flakle8 warnings
2020-07-28 12:10:18 +01:00
Leo Hemsted
36ae5fadf6 add broadcast_event table
It's clear that we need a way to track updates to a broadcast message.
It's also clear that we'll need some kind of audit log that captures
exactly what was sent out in a message.

This commit adds a new database table, `broadcast_event`, which maps 1:1
with CAP XML sent to the CBCs. We'll create one of these just before
sending out.

The main driver for this was that cancel and update messages need to
contain a list of references of all previous messages that they're
amending. This is of format `{sender},{identifier},{sent_timestamp}`,
and the identifier itself needs to be unique for each message.
2020-07-28 12:10:18 +01:00
Leo Hemsted
5dc8b43242 Merge pull request #2932 from alphagov/broadcast-crud-validation
Broadcast crud validation
2020-07-28 12:09:43 +01:00
Leo Hemsted
fb2910fb08 replace abort with raise InvalidRequest
it's slightly clearer that it will immediately raise an exception and
back out of the current function
2020-07-27 15:54:31 +01:00
Leo Hemsted
6302c74565 allow draft -> broadcasting
we haven't built pending_approval functionality yet
2020-07-27 15:51:16 +01:00
Leo Hemsted
483221df7d add broadcast message status transition map
be explicit about which transitions we allow. this is not necessarily an exhaustive list of everything we'll allow
2020-07-27 15:51:16 +01:00
Leo Hemsted
4043e8fa5e reject approvals from people outside your service
even if they're a platform admin
2020-07-27 15:51:16 +01:00
Leo Hemsted
b8e6689f62 allow platform admins to approve their own messages
makes development a lot easier. we should remove this when we go live
2020-07-27 15:51:16 +01:00
Leo Hemsted
0c870e8dcd enforce kwargs when creating user in tests
spent WAY too long trying to figure out why my user wasn't being created
in tests. the user isn't created if their email already exists in the
system, but email isn't a required field when creating!

Note: I tried just removing the check to see if the user already exists,
but 16 tests try and create duplicate users. I'm of the belief we should
just fix all those tests but I didn't have the energy for it right now
2020-07-27 15:51:15 +01:00
Leo Hemsted
8af112d885 refactor status updating into its own function
before it gets mega complex
2020-07-27 15:51:15 +01:00
Leo Hemsted
8dda1a5123 forbid editing after broadcast message goes live
only allow editing while in:

* draft
* pending-approval
* rejected (not too sure if/how this'll be used, so easier to include it
 for now)
2020-07-27 15:51:15 +01:00
Chris Hill-Scott
bc0cfed468 Merge pull request #2855 from alphagov/contact-list-used-property
Add property to contact lists to say if they’ve ever been used
2020-07-27 11:42:54 +01:00
Rebecca Law
80e4dc8af8 Merge pull request #2935 from alphagov/remove-jobs-incomplete-error
Stop raising error in scheduled task
2020-07-24 07:49:35 +01:00
Pea M. Tyczynska
a2f911b253 Merge pull request #2924 from alphagov/add-contact-block-to-serialize-template
Add contact block to serialize template for v2
2020-07-23 15:42:17 +01:00
Rebecca Law
dd126df122 We have a scheduled task to check that all the jobs have completed, this will catch if an app is shut down and the job is complete yet, we only wait 10 seconds before forcing the app to shut down.
The task was raising a JobIncompleteError, yet it's not an error the task is performing it's task correctly and calling the appropriate task to restart the job.
Also used apply_sync to create the task instead of send_task.
2020-07-22 17:00:20 +01:00
Toby Lorne
ec5eeac0aa Merge pull request #2933 from alphagov/stub-cbc-urls
Isolated CBC stubs
2020-07-21 16:55:13 +01:00
Chris Hill-Scott
313b69f95c Make property methods into proper properties
Since these methods only take `self` as an argument they can be
properties. And this means we don’t need to follow the semi-convention
we have of indicating an attribute is a method by starting its name with
`get_`.

The other advantage of using `@property` to indicate a getter is that it
will raise an exception if someone tries to set the attribute, eg by
doing `contact_list.has_jobs = False`. This is because we (rightly)
haven’t defined a setter.
2020-07-21 15:12:44 +01:00
Chris Hill-Scott
dbbff3ba64 Add property to contact lists to say if they’ve ever been used
At the moment we return a count of recent jobs for contact lists, where
recent is defined as being within the service’s data retention period.

This lets us write nice bits of UI copy like ‘used 3 times in the last
7 days’. But it’s hard to write the copy for when the count is 0,
because this could be for one of two reasons:
- the contact list has never been used
- the contact list has been used, but not within the data retention
  period for that channel

At the moment we can’t know which of those reasons is the case, so we
can’t write nice clear content like ‘never been used’.

This commit adds a property to contact lists which says whether they’ve
ever been used.

It also renames the existing, as-yet-unused property to make clear that
it’s only counting within the data retention (so can still be 0 even if
`has_jobs` is `True`).
2020-07-21 15:08:05 +01:00
Toby Lorne
fd389d5c76 cbc: use one stub cbc per environment
so we can break preview without breaking staging or production

related https://github.com/alphagov/notifications-cbc-proxy/pull/7

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-07-21 13:39:10 +01:00
Katie Smith
5b401eaf8d Merge pull request #2929 from alphagov/int-letter-rate-fix
Fix international letter rate start dates
2020-07-16 10:35:42 +01:00
Rebecca Law
c9831b0a44 Merge pull request #2930 from alphagov/change-mmg-firetext-ratio
Change MMG Firetext ratio
2020-07-15 14:23:58 +01:00
Rebecca Law
8bba04e1ce Update the MMG/Firetext ratio to 70/30 as requested. 2020-07-15 14:07:19 +01:00
Katie Smith
7c12c6c8f0 Fix international letter rate start dates
These were not taking timezones into account before.
2020-07-15 10:23:54 +01:00
Katie Smith
3fa25272b6 Merge pull request #2888 from alphagov/international-letter-rates
Add international letter rates
2020-07-15 08:36:59 +01:00
Katie Smith
da8eaaed44 Update letter data for usage-for-all-services report
Usage for all services is a platform admin report that groups letters by
postage. We want it to show `europe` and `rest-of-world` letters under a
single category of `international`, so this updates the query to do
that and to order appropriately.
2020-07-14 10:22:30 +01:00
Katie Smith
5d47e1cf06 Migration to add international letter rates
New rows giving the prices of letters with a post_class of `europe` and
`rest-of-world` have been added to the `letter_rates` table. All rates
are currently the same for international letters.
2020-07-14 10:22:30 +01:00
Pea M. Tyczynska
fbdfa6416f Merge pull request #2921 from alphagov/remove-statsd-http-api-decorators
Remove statsd http api decorators and turn statsd back on for celery apps
2020-07-14 10:16:44 +01:00
Pea Tyczynska
f6f88750b5 Add contact block to serialize template for v2
This attribute has been requested by a user, and we have not been
serializing it so far.
2020-07-13 17:04:01 +01:00
David McDonald
e6578e80d0 Merge pull request #2926 from alphagov/more-logging
Add better logging to starting collate-letter-pdfs-to-be-sent
2020-07-10 11:46:42 +01:00
David McDonald
ef551247b5 Add better logging to starting collate-letter-pdfs-to-be-sent
This will help us better understand how far through the task has got if
it gets interrupted halfway (as was the case this morning and we
struggled to understand).
2020-07-10 11:32:03 +01:00
David McDonald
247b926bde Merge pull request #2920 from alphagov/bump-gds-metrics
Fix risk of uncaught exceptions due to gds metrics
2020-07-10 10:45:52 +01:00
David McDonald
34538bcad8 Fix risk of uncaught exceptions due to gds metrics
Similar to https://github.com/alphagov/notifications-admin/pull/3510

Because of https://github.com/alphagov/gds_metrics_python/pull/8
2020-07-10 10:37:09 +01:00
Leo Hemsted
4de75b8c56 Merge pull request #2925 from alphagov/send-broadcast
Send broadcast
2020-07-10 09:22:21 +01:00
Leo Hemsted
8b4a954f2b move schema import in to function level
solves `AttributeError: 'DummySession' object has no attribute 'query'`

if you don't do this you get really hard to diagnose errors in unrelated
tests, due to strange import order problems or something
2020-07-09 20:10:34 +01:00
Leo Hemsted
403885722e trigger send_broadcast_message task when user approves
lets leave the cancellation can of worms alone for now
2020-07-09 18:23:30 +01:00
Leo Hemsted
eca37d0853 add send_broadcast_message task
task takes a brodcast_message_id, and makes a post to the cbc-proxy
for now, hardcode the url to the notify stub. the stub requires template
as the admin/api get it, so use the marshmallow schema to json dump it.
Note - this also required us to tweak the BroadcastMessage.serialize
function so that it converts uuids in to ids - flask's jsonify function
does that for free but requests.post doesn't sadly.

if the request fails (either 4xx or 5xx) just raise an exception and let
it bubble up for now - in the future we'll add retry logic
2020-07-09 18:23:30 +01:00
Leo Hemsted
fb64cbe621 Merge pull request #2923 from alphagov/fix-quick-typo-bug
set finishes_at correctly
2020-07-09 15:58:43 +01:00
Leo Hemsted
6b5e2af497 set finishes_at correctly
whoops
2020-07-09 15:36:08 +01:00
Leo Hemsted
a71530fe06 Merge pull request #2917 from alphagov/broadcast-crud
Broadcast Message CRUD endpoints
2020-07-09 15:16:57 +01:00
Leo Hemsted
efa2e75e56 add broadcast message tests
sorry for big unhelpful test commit
2020-07-09 14:19:58 +01:00