Commit Graph

3312 Commits

Author SHA1 Message Date
Leo Hemsted
1bed87b67d Merge pull request #4206 from alphagov/daily-sms-vols-reports
add new daily sms provider volumes report
2022-04-12 15:48:36 +01:00
Leo Hemsted
b3f5bb6435 add new daily sms provider volumes report
nearly identical to the daily-volumes-report but sms only, and split up
by provider
2022-04-11 14:40:31 +01:00
Ben Thorner
355a74d202 Make SMS provider inputs easier to interpret
In response to: [^1].

[^1]: https://github.com/alphagov/notifications-admin/pull/4205#discussion_r847204574
2022-04-11 14:02:04 +01:00
Ben Thorner
264bf8302f Remove redundant sorting when editing SMS ratios
This is irrelevant since we no longer pick a "first" provider.
2022-04-07 14:05:04 +01:00
Ben Thorner
dd0022968c Remove redundant constraint on multiple providers
We can now handle a single provider (with a priority of 100%).  I
don't think we need to handle the case of no providers.
2022-04-07 14:05:03 +01:00
Ben Thorner
55e89b3f12 Add validation for provider SMS percentages
We could alternatively put the "add up to 100%" error on the page
using form-level errors [^1] and a custom flash message. Putting
the error on each field is slightly simpler and does make it clear
the issue is with all of the fields together.

[^1]: 22636b55ed
2022-04-07 14:05:01 +01:00
Ben Thorner
7f333ba5fe Rewrite SMS ratio form to cope with 3 providers
This replaces the slider with an integer input for each provider.
Unfortunately showing a variable number of inputs isn't easy to
achieve in WTForms [^1], but we think this is the least worst way
to do it vs e.g. not using WTForms at all.

[^1]: https://github.com/wtforms/wtforms/issues/736
2022-04-07 14:05:00 +01:00
Ben Thorner
8655ab7dea Stop showing priorities for other provider types
This isn't used and showing priorities when we only have a single
provider or where they have no effect is unnecessarily confusing.
Removing the form makes it clearer that there's only one way to
adjust priorities for domestic SMS providers.

If we add another email or international SMS provider in future,
we would need to rewrite the form here anyway as the priorities
need to be adjusted in tandem, not individually.
2022-04-07 14:04:57 +01:00
Ben Thorner
66335d20c2 Return to main provider page after editing ratio
Staying on the edit page is atypical behaviour for an edit form,
especially now it no longer shows the version history.
2022-04-07 13:43:56 +01:00
Ben Thorner
a3231effb1 Remove version history from provider ratio page
This doesn't work with 3 providers. You can still see the version
history for each provider on their dedicated page.
2022-04-07 13:43:54 +01:00
Katie Smith
b5fa270cd2 Bump all test dependencies
This results in some new errors from flake8-bugbear:
```
B020: Loop control variable overrides iterable it iterates
```
I can't see an issue with the places that we do this, so have ignored
these warnings. If we keep getting these and they look fine, we can
create a global rule to ignore B020.
2022-04-06 12:17:09 +01:00
Ben Thorner
59f6b0b5d8 Replace "primary", etc. with "first", etc.
Using "primary" made sense when the other "secondary" provider was
new, but today we see them as equivalent and the terminology is a
bit confusing. In future we may add a third provider as well.
2022-04-05 15:55:06 +01:00
Ben Thorner
55e2a2f96b Stop reversing the order of SMS providers
This makes no functional difference but does make it easier to read.
2022-04-05 15:55:05 +01:00
Ben Thorner
9355c4f8d1 Only show active providers when changing priority
This fixes a bug where a third inactive provider would (potentially)
appear in place of one of the two active ones, depending on the order
of its identifier compared to the other two.

In future we may look at simplifying this to cope with more than two
active providers. For now, the existing UI will continue to work when
we add a new, inactive SMS provider for Reach.
2022-04-05 15:55:04 +01:00
Ben Thorner
6030e9e5bb Decouple the set of org types from their labels
In response to: [^1].

[^1]: https://github.com/alphagov/notifications-admin/pull/4196#discussion_r838383086
2022-03-30 17:46:53 +01:00
Ben Thorner
332c240b01 Use "get_email_choices" directly in branding view 2022-03-30 17:46:44 +01:00
Ben Thorner
b4b1c91fb9 Remove redundant "something else" branding check
This is always allowed and there was no test for it.
2022-03-30 17:46:43 +01:00
Ben Thorner
1cc5413f96 Move and clarify "NHS_BRANDING_ID" constant
This is specific to email branding [^1]. Using the name to match
the current branding is more error-prone.

[^1]: a165f62b60
2022-03-30 17:46:41 +01:00
Ben Thorner
8f55972aae Split "get_available_choices" by branding type
We already had different functionality for email branding and will
soon be adding more for email branding pools.

Note that the "get_available_choices" class method was only used for
email branding - we can do it in the constructor for letters.
2022-03-30 17:46:39 +01:00
Ben Thorner
f022836f4d Move letter-specific logic down to its form class
For letters we still have the conditional reveal on the radio form
for the "something else" option.
2022-03-30 17:46:38 +01:00
Ben Thorner
352cdb80fa Remove remaining uses of ChooseBrandingForm
This was missed in a previous commit.
2022-03-30 17:46:37 +01:00
Pea Tyczynska
7d5ca324d0 Merge pull request #4166 from alphagov/allow_user_delete_mobile_number
Let users on email auth delete their mobile numbers
2022-03-25 16:02:38 +00:00
Pea Tyczynska
99682db7bf Change conditional for consistency 2022-03-22 17:55:55 +00:00
Ben Thorner
d1d3a6a6c3 Merge pull request #4182 from alphagov/refactor-email-branding-181415991
First set of refactorings for branding
2022-03-22 13:43:10 +00:00
Ben Thorner
6a2367bb72 Merge pull request #4184 from alphagov/simplify-session-clear
Simplify "activate_user" to clear session earlier
2022-03-15 13:07:53 +00:00
Ben Thorner
f02c2b0b1d Rename other "Admin" forms consistently
I've also tweaked some of the names to make them clearer e.g. that
the form is used to apply a change to a service.

I've constrained the scope of this change to avoid forms that may
be accessible by non-admins in the future.
2022-03-15 11:47:22 +00:00
Ben Thorner
fa3e6435a6 Fix small issues identified in PR review
In response to: [^1], [^2], [^3], [^4], [^5] and [^6].

[^1]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825824485
[^2]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825824805
[^3]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825857745
[^4]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825859850
[^5]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825859982
[^6]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r826001823
2022-03-15 11:47:21 +00:00
Ben Thorner
2fc0a105f4 Move branding choices logic into utility module
This was a lot of code to be in a form and it's going to get even
more complicated with email branding pools. Moving it out means we
can also simplify the tests that target this code.
2022-03-15 11:47:16 +00:00
Ben Thorner
a04ed3eca5 Use separate classes for branding option forms
These are about to become a lot less similar to each other when we
add email branding pools. Note that the optional *args and *kwargs
weren't used anywhere.
2022-03-15 11:47:15 +00:00
Ben Thorner
26d1222f1c Rename branding forms to clarify who they're for
I've often struggled to find the form associated with a particular
page due to the overlapping names e.g. "SetEmailBranding" sounds
more like the radio button form a user sees than "BrandingOptions".

Almost every form in forms.py also ends with "Form", so this also
makes the branding forms consistent with that naming convention.
2022-03-15 11:47:14 +00:00
Chris Hill-Scott
9a1a328aca Format auth_type in a consistent way in the UI
On the ‘find user’ page it says ‘sms_auth’ instead of ‘Text message
code’.

This commit fixes that, and adds a handy formatter so it’s easier to do
the right thing in the future.
2022-03-14 14:55:31 +00:00
Ben Thorner
34c2c3b47c Merge pull request #4176 from alphagov/replay-falsey-values
Replay falsey values in input fields
2022-03-14 09:53:02 +00:00
Rebecca Law
de46fb6477 Merge pull request #4183 from alphagov/volume_reports
Report for total notifications sent per day for each channel.
2022-03-09 15:15:03 +00:00
Rebecca Law
c6e67d1690 Fix column names
Add unit test
2022-03-09 15:02:52 +00:00
Rebecca Law
971cb745c9 Report for total notifications sent per day for each channel.
Daily volumes report: total volumes across the platform aggregated by whole business day (bst_date)
Volumes by service report: total volumes per service aggregated by the date range given.

NB: start and end dates are inclusive
2022-03-07 14:30:11 +00:00
Ben Thorner
81d9c73543 Bump -utils to 55.0.0
This renames "delete_cache_keys_by_pattern" to match the new method
name, which will also catch exceptions if Redis is down [1].

Note that this also includes a change to RecipientCSV [2], which has
no effect because the new default is the same as the old behaviour.

[1]: https://github.com/alphagov/notifications-utils/pull/949
[2]: https://github.com/alphagov/notifications-utils/pull/947/files#diff-a8a994bf655634f89dc7439880708b4ff0d780ac1bd8033827d8aaa2692a8e0fR373
2022-03-07 13:53:57 +00:00
Ben Thorner
21452649fd Fix ignoring submitted data that was falsey
This was causing some tests for the "estimate_volume" endpoint to
fail due to the surprising way that form handles "''":

- The form is the exclusive user of the ForgivingIntegerField [^1].
- The field secretly/silently converts "''" to the integer 0 [^2].

If the validations fail, we don't want to surprise the user with a
"0" when they didn't enter one. The field already handles this by
massaging the values in the __call__ method that generates the HTML
for the form [^3]. However, there are two scenarios:

- User submits field with '' - converted to integer 0.
- User submits field with '0' - remains as a string.

In the case where "value" is "''", the parent class will use the
converted value from form.data instead [^4]. This seems to be an
oversight and so we get either the integer 0 (from form.data) or
the string '0' (from the value kwarg). Complicado!

Previously it was a fluke that we avoided replaying the integer 0
to the user; the previous commit removes the fluke. This fixes the
conditional to always use the data in the "value" kwarg if it has
been provided, as it's meant to override "form.data".

[^1]: 9f63449384
[^2]: a22b8cf684/app/main/forms.py (L364)
[^3]: a22b8cf684/app/main/forms.py (L393)
[^4]: a22b8cf684 (diff-a1c8d24b22d4478fe71f75fd43b71b18dd82aae97bc63de84473a6da1902909bR215)
2022-03-07 12:55:38 +00:00
Ben Thorner
f827a825a1 Merge pull request #4180 from alphagov/dedup-something-else-181415991
Link directly to email branding "something else"
2022-03-07 11:33:11 +00:00
Ben Thorner
8d5974eb47 Simplify "activate_user" to clear session earlier
A snippet of old code [^1] in "activate_user" was forcing us to
keep "user_details" in the session until the very last moment with
a "try / finally" combo. But "activate_user" already knows the ID
of the user: it's the argument we pass to the function.

None of the functions called by "activate_user" require the session
to have that key either i.e. it's definitely redundant.

It's unclear if we need to pop the key from the session in both
"verify" methods - there are no tests covering this behaviour. For
now, we can at least make the flow clearer by adjusting where we do
the "pop" and the assignment.

[^1]: bbc7b173f0 (diff-d12384ece5ad90e9b66063fd3ab170453788d36b7e0babf49ee016f0a880f251L71)
2022-03-07 11:08:19 +00:00
Pea Tyczynska
ae4fc977c1 Apply suggestions from code review
Co-authored-by: Ben Thorner <benthorner@users.noreply.github.com>
2022-03-03 17:02:26 +00:00
Pea Tyczynska
8112930e24 Do not verify sms for pending users with email auth
This is to fix a bug where a user creates an account but doesn't
complete registration, then they are invited to a service that
changes their auth to email_auth, and then when they try to
complete registration they are still asked for sms code.

It should save users some pain, and reduce number of support tickets.
2022-03-03 17:02:26 +00:00
Pea Tyczynska
08f0393553 Allow platform admins to change user auth in the UI
So we do not have to go into the db when we need to change user
auth.

We do not allow this for users who use webauthn. We do not want to
enable security downgrade for those users.
2022-03-03 13:44:13 +00:00
Ben Thorner
8da8b167c9 Merge pull request #4169 from alphagov/downgrade-existing-letter-error
Downgrade error log for expected exception
2022-03-03 11:27:48 +00:00
Ben Thorner
33c6ca0989 Link directly to email branding "something else"
Previously we duplicated the "something else" email branding form
on its own page and embedded in the choices form (if it was the
only option). See [^1] for how this looks - it's inconsistent.

This DRYs-up the "something else" form by bypassing the choices
form when "something else" is the only option. I've also tweaked
the "Back" button to be consistent with this behaviour.

Making this change also simplifies the choices form, which we'll
be adding pool options to shortly. I'd like to make the letters
form consistent, but let's see how emails pan out first.

Note that the choices form will now show a single radio button if
"something else" is the only option. I think that's OK as nothing
will link to the page, and the form still works.

[^1]: https://github.com/alphagov/notifications-admin/pull/4163#issuecomment-1050088088
2022-03-03 10:18:58 +00:00
Ben Thorner
09899eb99d Replay falsey values in input fields
Currently an integer of 0 doesn't get shown because it fails the
truthiness check in the govuk-frontend template [^1]. Note that
we can't just do str(value) as for None this would be "None".

[^1]: fd4952f1c0/src/govuk/components/input/template.njk (L51)
2022-03-01 13:57:56 +00:00
Ben Thorner
35e7e5e957 Downgrade error log for expected exception
Previously we weren't sure if the cause of this exception was what
the comment below suggested [1]. I've now verified this from:

        Letter not found for service 0bd1d970-f11c-40e1-8319-4baefe6239d7 and file aa07ed06-3161-4795-93b3-b45d7c576af9

I checked that aa07ed06-3161-4795-93b3-b45d7c576af9 exists already
as a notification i.e. the comment is correct and we're not sending
users to a 404 page. It's possible there are other scenarios where
the comment is wrong, but I don't think it's worth keeping the error.

[1]: https://github.com/alphagov/notifications-admin/pull/4159
2022-02-25 14:00:02 +00:00
Katie Smith
9dc3252079 Allow free allowance to be set to 0
We want to be able to set the free allowance for a service to 0, but the
form was not allowing this - it gave an error message of `Cannot be
empty`. This can be fixed by changing the WTForms validator from
`DataRequired` (which coerces 0 to falsey) to the `InputRequired`
validator.
2022-02-25 11:27:56 +00:00
Katie Smith
05b8fd7c01 Merge pull request #4163 from alphagov/branding-previews
Show a preview of GOV.UK and NHS email branding and apply straight away
2022-02-24 11:31:53 +00:00
Ben Thorner
f94c6ded5c Merge pull request #4158 from alphagov/catch-missing-recipient
Fix 500 error due to inconsistent recipient check
2022-02-24 10:17:03 +00:00
Ben Thorner
468e42a12e Merge pull request #4159 from alphagov/catch-missing-letter
Catch error if letter does not exist on send
2022-02-24 10:16:54 +00:00