Commit Graph

12598 Commits

Author SHA1 Message Date
Chris Hill-Scott
ded87706c7 Upgrade xlrd to version 2
xlrd is a library for reading data and formatting information from
Excel files in the historical .xls format.

Version 2 of xlrd no longer supports anything other than .xls files.

We were using it to also support reading .xlsm files (old Excel files
with macro support).

We could keep using the old version of this dependency, but hopefully
this niche version of an ancient file format is obscure enough that
no-one is using it, and we can drop support, keeping our dependencies
up to date.
2022-05-12 15:48:12 +01:00
Ben Thorner
5641ce2c15 Merge pull request #4243 from alphagov/fix-usage-api-181935935
Fix keys used to render monthly usage
2022-05-11 13:56:16 +01:00
Ben Thorner
4abb6110c8 Fix keys used to render monthly usage
These were out-of-sync with the API.
2022-05-11 13:28:33 +01:00
Ben Thorner
84dde0f824 Merge pull request #4229 from alphagov/monthly-usage-multirate-181935935
Support multiple rates in monthly SMS usage
2022-05-11 11:26:44 +01:00
Chris Hill-Scott
5c4b361345 Merge pull request #4240 from alphagov/humanize-4.1.0
Update humanize from 4.0.0 to 4.1.0
2022-05-11 10:06:48 +01:00
Ben Thorner
bb0fb73bc8 Minor tweaks in response to PR comments
In response to [^1] and [^2].

[^1]: https://github.com/alphagov/notifications-admin/pull/4229#discussion_r869181152
[^2]: https://github.com/alphagov/notifications-admin/pull/4229#discussion_r869186063
2022-05-10 17:00:51 +01:00
Ben Thorner
9ac33f7baf Merge pull request #4242 from alphagov/fix-missing-audit-task-182116071
Fix missing audit task in package.json
2022-05-10 13:25:25 +01:00
Ben Thorner
51f9b0cef0 Fix missing audit task in package.json
This was intended to go in [^1] but I think it got lost in a rebase.

[^1]: https://github.com/alphagov/notifications-admin/pull/4237
2022-05-10 11:33:24 +01:00
Chris Hill-Scott
478f222419 Merge pull request #4238 from alphagov/whitespace-api-key-js
Remove whitespace around API key in JS templates
2022-05-10 11:08:47 +01:00
Chris Hill-Scott
6f856fdece Make terminology around visually hidden prefix clearer and more consistent
Co-authored-by: Ben Thorner <benthorner@users.noreply.github.com>
2022-05-10 10:33:27 +01:00
Chris Hill-Scott
381bd2cd1c Update humanize from 4.0.0 to 4.1.0 2022-05-10 10:13:12 +01:00
Ben Thorner
d5f2f913d8 Merge pull request #4237 from alphagov/add-npm-audit-181889734
Add better-npm-audit to check production packages
2022-05-09 15:08:10 +01:00
Chris Hill-Scott
e82970d490 Remove whitespace around API key in JS templates
We removed whitespace in the HTML of the copy to clipboard component
in https://github.com/alphagov/notifications-admin/pull/4236/files

When the Javascript on the page loads it re-renders the component,
using HTML which is embedded in the .js file.

This means we also need to apply the same change to the .js file
to remove any extraneous whitespace.
2022-05-09 12:38:18 +01:00
Ben Thorner
b348e8ed03 Add better-npm-audit to check production packages
This is the same as [^1].

[^1]: https://github.com/alphagov/document-download-frontend/pull/120
2022-05-09 12:05:42 +01:00
Chris Hill-Scott
4ce1bf436d Merge pull request #4236 from alphagov/fix-whitespace-copy
Remove whitespace from copy to clipboard component
2022-05-09 12:01:43 +01:00
Ben Thorner
efb45c0baa Merge pull request #4235 from alphagov/regroup-npm-packages-181889734
Fix incorrect group for NPM dependencies
2022-05-06 15:42:00 +01:00
Ben Thorner
d97ed69f0b Turn off NPM auditing on installation
This isn't useful as it mostly pertains to dev dependencies, where
we're not concerned about vulnerabilities as they run in isolation.
2022-05-06 12:31:52 +01:00
Ben Thorner
da7dd3a852 Fix incorrect group for NPM dependencies
This means we can use tools like "npm audit" to look for security
vulnerabilities we definitely need to fix as they could pose a
direct risk to users. I've checked each of them with @tombye and
also against an external set of principles [^1].

Note: I've skimmed through the package-lock.json to check the only
changes are to add "dev: true", as well as a few integrity hashes.

[^1]: https://betterprogramming.pub/is-this-a-dependency-or-a-devdependency-678e04a55a5c
2022-05-06 12:31:10 +01:00
Chris Hill-Scott
4d825ece9f Merge pull request #4231 from alphagov/allow-editing-pending-users
Allow editing of pending users
2022-05-06 12:29:13 +01:00
Chris Hill-Scott
f2bcc79dbd Merge pull request #4233 from alphagov/update-some-core-dependencies
Update minor and patch versions of some core dependencies
2022-05-06 11:36:58 +01:00
Chris Hill-Scott
1dd8b2513d Merge pull request #4232 from alphagov/update-test-dependencies
Update test dependencies to latest versions
2022-05-06 11:36:52 +01:00
Tom Byers
532289e677 Merge pull request #4234 from alphagov/fix-alert-area-list
Fix alignment regression error with area lists
2022-05-06 10:20:30 +01:00
Chris Hill-Scott
c6fb0e6694 Remove whitespace from copy to clipboard component
If there is whitespace in the element containing the value to be copied
then Firefox[1] includes that space in the value it puts in the clipboard.

This is obviously annoying since `foo-bar` might be a valid API key where
`foo-bar ` is not.

This commit fixes that by using the `-` in Jinja to gobble whitespace.

I also looked at doing this in the Javascript, but the browser API for
selecting some text and copying it doesn’t give an obvious place for
using `String.prototype.trim()`.

1. Tested with Firefox 100.0 on Mac OS 12.2.1
2022-05-05 15:42:05 +01:00
Ben Thorner
b6321ef4ae Remove unused "del" package
This was added in [^1] and later removed in [^2].

[^1]: e1dc6ddaef
[^2]: https://github.com/alphagov/notifications-admin/pull/3198
2022-05-05 14:51:19 +01:00
Tom Byers
65d337959d Fix alignment regression error with area lists
When we changed the layout for each alert on the
current/past/rejected alerts pages to use flexbox,
we added a fallback for older browsers that set
text-align: justify on the container:

https://github.com/alphagov/notifications-admin/pull/4171

This has led to items in the list of areas an
alert will be sent to being laid out as justified
content when they were left-aligned.

These changes set the correct alignment.
2022-05-05 14:49:52 +01:00
Chris Hill-Scott
6f95e4e0ca Pin Werkzeug to below 2.1.x
We can’t upgrade to Werkzeug 2.1.0 because the `BaseResponse` class
has been renamed. The old version of Flask we are using tries to import
`BaseResponse` causing an error.

    See https://github.com/pallets/werkzeug/issues/1963
2022-05-05 14:13:24 +01:00
Chris Hill-Scott
75a57568b6 Pin Jinja to below 3.1.x
We can’t upgrade to Jinja 3.1.0 because the `escape` module has been
moved to the `markupsafe` library. The old version of Flask we are
using tries to import `escape` from `jinja2`, causing an error.

See https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-0
2022-05-05 14:12:48 +01:00
Chris Hill-Scott
7a0ba988bb Update flake8 error code
flake8-print moved its namespace from `T0*` to `T2*` as a breaking
change in version 5.0.0 – see https://github.com/jbkahn/flake8-print#500---2022-04-30
2022-05-05 13:50:54 +01:00
Chris Hill-Scott
80ad40f587 Update minor and patch versions of some core dependencies 2022-05-05 13:45:42 +01:00
Chris Hill-Scott
1794344306 Update test dependencies to latest versions 2022-05-05 13:40:24 +01:00
Chris Hill-Scott
c6dc0d513e Allow editing of pending users
At the moment if a user is pending we don’t show the ‘change’ link.

This is unhelpful because:
- there’s no way to remove this user
- there’s no way to change their phone number, if the reason that
  they are still pending is because they’ve been unable to receive
  the two factor code at the number they first provided
2022-05-05 09:42:14 +01:00
Chris Hill-Scott
c5d4bfd8ef Refactor to avoid direct string comparison
Direct string comparison in multiple places is prone to typos. It
also means that a consumer of the class needs to know that whether
a user is pending or active is held in the `state` property, which
is an implementation detail.
2022-05-05 09:39:32 +01:00
Chris Hill-Scott
5ac6efc580 Refactor logic out of Jinja before making more complicated
To keep the conditionals in the Jinja template more readable, this
commit moves the logic into a method on the model, where it can
be split over multiple statements and lines.
2022-05-05 09:38:40 +01:00
Chris Hill-Scott
b4b7ecb2aa Merge pull request #4230 from alphagov/fix-broadcast-counties-page
Fix focus and spacing on counties page
2022-05-04 16:14:13 +01:00
Chris Hill-Scott
b2113fba39 Merge pull request #4228 from alphagov/remove-old-sms-price
Clean up old text message price
2022-05-04 16:01:23 +01:00
Tom Byers
77ac7b80ed Fix focus and spacing on counties page
We fixed a problem with the focus styles of list
items in this pull request:

https://github.com/alphagov/notifications-admin/pull/4141

This missed out pages for areas with counties in
them. This adds the fix to those pages.

These changes also include some extra spacing
between the end of the list and the button which
is lost by the new styles we're giving the list
items.
2022-05-04 15:06:13 +01:00
Chris Hill-Scott
a136b92078 Rename constant for clarity 2022-05-04 15:04:06 +01:00
Ben Thorner
3449ccd923 Support multiple SMS rates per month on usage page 2022-05-03 16:01:13 +01:00
Ben Thorner
75e0d53e76 Simplify test for only showing historic months
This goal wasn't clear from the original test, which was checking
the entire return value, even though this is covered implicitly by
tests of the usage page itself.
2022-05-03 16:01:12 +01:00
Ben Thorner
c05502835b Simplify monthly letter breakdown ordering test
This doesn't need to test variable rates for every postage class,
which is more an aspect of grouping. It only needs to check that
some out-of-order usage gets reordered appropriately.
2022-05-03 16:01:11 +01:00
Ben Thorner
63c35ec3d9 Remove redundant test for letter usage breakdown
This is covered sufficiently by the main "test_usage" assertions,
which prove the usage is broken down by postage.

I don't think we need to explicitly test the usage is broken down
by month as we already prove this for SMS and we also check the
usage is associated with the correct month in the "ordering" test.
2022-05-03 16:01:10 +01:00
Ben Thorner
91e902bc2c Tidy up "format" method for monthly letter usage
This did more than it said and had some unconventional behaviour:

- It modified the input data. We can avoid this by computing the
postage group on-the-fly and using "sorted" instead of "sort".

- It defined a custom, named tuple. This isn't necessary as Jinja
allows us to access elements by qualification (".") already.

We can also use the same lambda function to group and sort items,
since the sort predicate is the same one we use to group them.
2022-05-03 16:01:09 +01:00
Ben Thorner
fb7c116046 Finish migration from billing_units to API fields
This is now only used for letters and represents the number sent
[^1].  We could use the chargeable_units field, but using "_sent"
is more consistent with the annual attributes [^2].

In fact, chargeable_units isn't actually used anywhere, but I've
kept it in the test data as it is part of the real API and helps
clarify the other values for SMS - free vs. charged.

Note: for SMS I've used an arbitrary "1234" for "chargeable_units"
to indicate it's not used and may be different to the number sent -
for SMS it's related to the number of fragments.

[^1]: bb62d22f25/app/dao/fact_billing_dao.py (L339)
[^2]: 3a1ac189ff/app/main/views/dashboard.py (L339)
2022-05-03 16:01:08 +01:00
Ben Thorner
c0ee24ff19 Migrate letter cost calculation to use API field
The values in the tests are calculated manually from other fields
in the mocked API response.
2022-05-03 16:01:07 +01:00
Ben Thorner
d798a0d60f Replace manual SMS monthly calculations with API
This starts using the sms_{cost, charged, free_allowance_used}
fields in the new API to replace the "get_free_paid_breakdown"
function we had before, which could not support multiple rates.

In order to use "get_free_paid_breakdown" the calling method had
to store a "cumulative" variable to calculate the free allowance
used so far, which is now done by the API.

To calculate the data for conftest.py, I had to start from the
bottom ("April") and manually calculate the free allowance used
to emulate the API - this is what "cumulative" used to do.
2022-05-03 16:01:06 +01:00
Ben Thorner
f6dc30665f Reorder monthly usage assertions (group by month)
This also removes an extremely confusing assertion of "40" free
messages, which was passing because we have "140" free messages.
2022-05-03 16:01:04 +01:00
Ben Thorner
ce8bdea9be Fix inaccurate test data for monthly usage API
It has never been possible to get multiple rows for the same month
and rate. This was making it hard to switch to the new API fields,
which will require some manual calculations. I've added the billing
units together in the remaining data so the tests still pass.

I've also moved the "April" row to the end as it was out-of-order
with all the others: it's the _start_ of the financial year.
2022-05-03 16:01:03 +01:00
Ben Thorner
4ab795ad68 Replace "sum_billing_units" with inline code
This is also an opportunity to DRY-up the filtering of usage by
month, which we will reuse in the following commits. Doing a sum
is simple enough that it can be done inline, avoiding indirection.
2022-05-03 16:01:02 +01:00
Ben Thorner
246356649f Rename monthly usage attributes to match API
This should make the subsequent changes to use the new API fields
a bit clearer, and also matches the annual usage attributes [^1].

[^1]: 3a1ac189ff/app/main/views/dashboard.py (L343-L350)
2022-05-03 16:01:01 +01:00
Ben Thorner
215a688250 Reuse helper function to filter usage rows
I've also dispensed with the "units" terminology here, which didn't
represent the "rows" returned by the API.
2022-05-03 16:01:00 +01:00