Commit Graph

11368 Commits

Author SHA1 Message Date
Rebecca Law
007fa5fa19 Merge pull request #3855 from alphagov/set-annual_billing-in-the-api
Let the API handle setting the default free allowance.
2021-04-20 07:17:57 +01:00
Rebecca Law
0ffcdf692c Merge pull request #3861 from alphagov/dont-add-sender-id-for-letter-jobs
If the job is for letters do not add the sender_id.
2021-04-20 07:17:41 +01:00
Rebecca Law
ac0b8ed95c If the job is for letters do not add the sender_id.
How this happens: a user starts to send a letter job, then in another tab starts a SMS
or email job, the sender_id is set in the session. Then the user goes
back to the letter job tab and creates the job. The sender_id is set in
the metadata of the csv file, and causes an exception when trying to persist
the letter notification.

This PR adds a check to ensure the sender_id is not set for letter jobs.

This will catch a small use case where the user has multiple tabs open
and has started sending an SMS or email job, then tries to send a letter
job.
2021-04-15 13:51:48 +01:00
David McDonald
2871d4cb04 Merge pull request #3858 from alphagov/pyup-scheduled-update-2021-04-12
Scheduled weekly dependency update for week 15
2021-04-14 17:41:09 +01:00
David McDonald
8a930c0ab6 make freeze requirements 2021-04-14 17:28:24 +01:00
Chris Hill-Scott
46d0e73e99 Freeze requirements 2021-04-14 17:24:31 +01:00
pyup-bot
ce2b83cab2 Update xlrd from 1.2.0 to 2.0.1 2021-04-14 17:24:30 +01:00
pyup-bot
5c31d3bbf4 Update prometheus-client from 0.9.0 to 0.10.1 2021-04-14 17:24:29 +01:00
pyup-bot
e3ad749131 Update phonenumbers from 8.12.20 to 8.12.21 2021-04-14 17:24:29 +01:00
pyup-bot
b1fe29f8e8 Update idna from 2.10 to 3.1 2021-04-14 17:24:28 +01:00
pyup-bot
902667021f Update docutils from 0.15.2 to 0.17 2021-04-14 17:24:27 +01:00
pyup-bot
277f80a811 Update dnspython from 1.16.0 to 2.1.0 2021-04-14 17:24:26 +01:00
pyup-bot
3354cd4aa4 Update colorama from 0.4.3 to 0.4.4 2021-04-14 17:24:25 +01:00
pyup-bot
0864d560e5 Update botocore from 1.20.44 to 1.20.49 2021-04-14 17:24:24 +01:00
pyup-bot
f22ea11e11 Update boto3 from 1.17.44 to 1.17.49 2021-04-14 17:24:23 +01:00
pyup-bot
60ac229983 Update awscli from 1.19.44 to 1.19.49 2021-04-14 17:24:22 +01:00
pyup-bot
64d103dfa8 Update humanize from 3.3.0 to 3.4.0 2021-04-14 17:24:21 +01:00
pyup-bot
dea6a4dbe9 Update humanize from 3.3.0 to 3.4.0 2021-04-14 17:24:20 +01:00
Chris Hill-Scott
00f9df7606 Merge pull request #3860 from alphagov/search-templates-by-id
Allow users of the API to search templates by ID
2021-04-14 10:44:17 +01:00
Chris Hill-Scott
e32fc7c606 Use template-list-item selector
For consistency with other assertions
2021-04-14 10:30:00 +01:00
Chris Hill-Scott
e32726f692 Merge pull request #3859 from alphagov/use-rtreelib
Use pure Python Rtree library
2021-04-13 16:05:39 +01:00
Chris Hill-Scott
559c400e84 Add override from future GOV.UK Frontend version
We need to duplicate it until we upgrade.
2021-04-13 15:43:03 +01:00
Chris Hill-Scott
c95b2ef8b3 Allow users of the API to search templates by ID
For someone who has retrieved a template ID from their system the only
way to find it in Notify is:
- hack the URL
- click through every template, visually inspecting the ID shown on the
  page until you find the right one

Neither of these is ideal.

This commit adds searching by ID, for those services who have an API
integration. This means we don’t need to confuse teams who aren’t using
the API by talking about IDs.

This is similar to how we let these teams search for notifications by
reference[1]

1. https://github.com/alphagov/notifications-admin/pull/3223/files
2021-04-13 15:24:29 +01:00
sakisv
bfa8dfe95e Fix import order 2021-04-13 16:31:06 +03:00
Chris Hill-Scott
e7aad61220 Use pure Python Rtree library
The Python rtree library we are using to build RTrees has a dependency
on the C package libspatialindex. This package is not installed on PaaS,
so it’s hard for us to use it.

This commit changes the code to use a library called rtreelib instead.

rtreelib doesn’t have a built in way to serialise the index it builds,
so I’ve had to implement that using pickle.
2021-04-13 12:43:28 +01:00
Chris Hill-Scott
69ed9e965a Merge pull request #3844 from alphagov/calculate-phones-custom-areas
Calculate the estimated number of phones in an arbitrary polygon
2021-04-13 09:55:00 +01:00
Chris Hill-Scott
83c521915c Estimate number of phones in an arbitrary polygon
We want to know how many phones are in a user-supplied polygon, so we
can show the impact of a broadcast, in the same way that we do when
users pick areas from our library.

We already know how many phones are in each electoral ward. But there
are challenges with an arbitrary polygon:
- where it does overlap a ward, the overlap could be partial
- it could overlap more than one ward
- finding out which wards it overlaps by brute force (looping through
  all the wards and seeing which ones intersect with our polygon) would
  be way to slow to do in real time

Instead we can use a data structure called an R-tree[1] to build an
index which provides a much, much faster way of looking up which
polygons overlap another. We can build this tree in advance and save it
somewhere, which means there’s a lot of computation we don’t need to do
in real time.

The R-tree returns a set of objects (ward IDs) which we can go and look
up in our library of electoral wards. These wards will be the ones that
might have some overlap with our custom polygon.

Once we have this small set of wards which might overlap our ward, we
can look at the size of the area of overlap (relative to the size of the
whole ward) and multiply that by the known count of phones in that ward
to get an approximation of the count of phones in the overlap area.
Summing these approximations give an estimate for the whole area of the
custom polygon.

1. https://en.wikipedia.org/wiki/R-tree
2021-04-12 15:45:48 +01:00
Katie Smith
04d051df6b Merge pull request #3856 from alphagov/401-fix
Fix sign in link on 401 page
2021-04-09 08:53:30 +01:00
Chris Hill-Scott
11ded9e828 Merge pull request #3801 from alphagov/show-rejected-broadcasts-on-previous
Show rejected broadcasts on ‘Previous alerts’ page
2021-04-08 14:34:13 +01:00
Chris Hill-Scott
06f2c7eaaa Remove verbs from old alerts
Now we’ve split the old alerts onto two pages the verbs (‘Broadcast’ and
‘Rejected’) will always be the same for each alert – so they’re not
adding any differentiation.

The specifics of what the datetime means is available on the page for
each alert.

Removing the verbs makes the page a bit less cluttered and makes it
easier to scan down the right hand column.
2021-04-08 14:19:36 +01:00
Chris Hill-Scott
4da38e42e3 Make alert page work for rejected broadcasts
The code for this page was making assumptions about properties which
aren’t present on rejected broadcasts.

This commit accounts for those properties and presents the relevant
elements on the page.
2021-04-08 14:19:36 +01:00
Chris Hill-Scott
9b256de4a9 Refactor to reduce duplication
> Rule of three ("Three strikes and you refactor") is a code refactoring
> rule of thumb to decide when similar pieces of code should be
> refactored to avoid duplication. It states that two instances of
> similar code don't require refactoring, but when similar code is used
> three times, it should be extracted into a new procedure

– https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming)
2021-04-08 14:19:36 +01:00
Chris Hill-Scott
dc4db4951a Add a separate page for rejected alerts
We don’t want to mix these up with alerts that actually went out.
2021-04-08 14:19:36 +01:00
Chris Hill-Scott
9977028a83 Make Jinja template generic
This will let us reuse the same code for displaying pages of previous
and rejected alerts.
2021-04-08 13:38:54 +01:00
Leo Hemsted
856a667dcf Merge pull request #3857 from alphagov/prom-pin
pin prometheus-client to 0.9.0
2021-04-08 11:30:51 +01:00
Leo Hemsted
8954dc2fae skip prometheus-client 0.10.0
we saw exceptions on prod that I think might have caused a worker that
is being terminated to die ungracefully. While I'm not sure if this is
an actual problem that changed behaviour (app instances crashing and
restarting), at the very least it definitely polluted the logs and
obscured any actual issues we were having.

https://github.com/prometheus/client_python/releases/tag/v0.10.0

see the pending fix for this problem here:
https://github.com/prometheus/client_python/pull/644
2021-04-08 11:09:45 +01:00
Leo Hemsted
5d2b18e501 bump pip-tools when freezing dependencies
to stop big diffs from change in formatting of reqs.txt
2021-04-08 11:09:39 +01:00
Chris Hill-Scott
0bdd5cab2d Show rejected broadcasts on ‘Previous alerts’ page
Two reasons to not hide rejected broadcasts:
- if a broadcast was rejected by mistake then it’s useful to have an
  audit of who did that
- it means you can still see old broadcasts without having to leave
  in pending-approval, which is dangerous because they might
  accidentally be approved
2021-04-08 10:51:01 +01:00
Katie Smith
b1848b3216 Fix sign in link on 401 page
We've seen someone getting a `500` when trying to visit the `/metrics`
endpoint. This is because the metrics endpoint is not in the `main`
blueprint, so we can't use url_for with a relative endpoint.

Although only bots visit '/metrics' without authorisation, this stops
the odd `500`.
2021-04-08 08:42:02 +01:00
Chris Hill-Scott
2c8fc4d523 Merge pull request #3852 from alphagov/pyup-scheduled-update-2021-04-05
Scheduled weekly dependency update for week 14
2021-04-07 17:01:04 +01:00
Rebecca Law
b1d78ada83 Let the API handle setting the default free allowance.
The API has a method to handle setting the default SMS free allowance. This will save a call to the API and remove some code duplication between the two apps.

Needs to be merged after https://github.com/alphagov/notifications-api/pull/3197
2021-04-07 09:32:18 +01:00
Chris Hill-Scott
caf4ddacaa Freeze requirements 2021-04-06 16:43:03 +01:00
David McDonald
e454a24e3d Merge pull request #3853 from alphagov/unknown-event-doer
Don't show user as unknown for service history
2021-04-06 16:33:29 +01:00
David McDonald
4acca3de4d Don't show user as unknown for service history
A commit was added:
600e3affc1

In it, it falls back to the string 'Unknown' for actions done by those
not belonging to the service.

This commit changes the behaviour such that if the user is not in the
list of active users for a service, it will go get the user from the DB
(or redis). This should be fine to do as redis will protect us from most
calls as most of these cases are for platform admins.

This will mean we can now see which user platform admin put a service
live rather than seeing 'Unknown'.
2021-04-06 11:36:54 +01:00
pyup-bot
1c741bb0c1 Update xlrd from 1.2.0 to 2.0.1 2021-04-05 14:55:10 +01:00
pyup-bot
65d11952dd Update s3transfer from 0.3.4 to 0.3.6 2021-04-05 14:55:09 +01:00
pyup-bot
0f4dc6323c Update phonenumbers from 8.12.19 to 8.12.20 2021-04-05 14:55:09 +01:00
pyup-bot
e3a03c7dde Update idna from 2.10 to 3.1 2021-04-05 14:55:09 +01:00
pyup-bot
9e501a0c30 Update docutils from 0.15.2 to 0.17 2021-04-05 14:55:08 +01:00
pyup-bot
25f7288f9a Update dnspython from 1.16.0 to 2.1.0 2021-04-05 14:55:08 +01:00