Commit Graph

3929 Commits

Author SHA1 Message Date
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
Katie Smith
4e409f7d93 Show preview of current branding
This adds a preview of the current branding to users on the page where
they can select which new branding they want. Also includes a tiny
content change to match the new content doc for this story.
2022-02-22 14:57:49 +00:00
Katie Smith
5ada431da9 NHS and GOV.UK email branding pages now show preview and apply branding
The pages you were redirected to if you selected either GOV.UK branding
or NHS branding used to give information about the branding and have a
button that submitted a Zendesk ticket. Now, we show a preview of the
new branding and the button applies it.
2022-02-22 13:18:21 +00:00
Katie Smith
d75c1ea398 Split out the govuk and govuk_and_org branding templates
The `.email_branding_govuk` and `.email_branding_govuk_and_org` routes
shared a template since the content was the same - the only difference
was in the action of the button. However, since the pages will no longer
be so similar (e.g. the govuk page will show a preview) this splits them
up to use separate templates.

It may be the case that when the branding work is complete these pages
are fairly similar and we decided that one template between the two
endpoints is the best option again.
2022-02-22 11:39:53 +00:00
Ben Thorner
ebbfd20472 Make it easy to clear cache for all key formats
Having to submit the form for each choice separately slowed us down
during an incident where Redis was unavailable and came back with
stale data, which we had to clear manually.

Note: we don't want to use the "flush" feature in case there are other
keys in Redis, which may not be safe to remove.
2022-02-21 15:09:03 +00:00
Ben Thorner
16a14cd642 Rewrite test for clear cache radio buttons
This was missing an existing option to clear for broadcasts.
2022-02-21 14:11:53 +00:00
Ben Thorner
8396412ce1 Report all cache keys that were deleted
This will make it easier to add another test / feature to clear all
the cache keys. It's debatable which of "sum" and "max" is useful:

- "max" is a better (although still not accurate) indicator of the
number of "things" affected e.g. templates, services, etc.

- "sum" makes sense in places where "max" doesn't e.g. when we clear
the "organisations" group, which doesn't equate to individual orgs.

Using "sum() ... across" seems like a reasonable compromise and makes
it clear that we're iterating over different kinds of keys.

While the pluralisation is nice, I don't think it's worth the effort
to make it work for both "object(s)" and "format(s)".
2022-02-21 14:11:49 +00:00
Ben Thorner
4fef2861c6 Catch error if letter does not exist on send
This repeats the pattern we already have for previewing a letter,
where we assume the error is because the notification has already
been sent and redirect the user to see it.

I've improved the original pattern a bit:

- I've DRYed-up the low-level boto code and moved the error handler
there so it can be reused.

- I've introduced a custom exception, which the calling code can
choose to log.

- I've introduced the moto library, which we use elsewhere, to make
it easier to test S3 code.

I've used an error level log when sending a notification - now that
we have a more descriptive log, we can verify the assumption is true
and then make an informed decision to downgrade the log.

In future we may want to merge this handler with the similar code
in utils [1], but we'll need to be careful as the utils handler is
superficial - it doesn't check the reason for the error.

[1]: bce0f4e596/notifications_utils/s3.py (L52)
2022-02-18 14:52:27 +00:00
Ben Thorner
a30a317153 Fix 500 error due to inconsistent recipient check
This strengthens the initial check of what's in the session to make
sure it contains some kind of recipient. Without this, we get:

    Traceback (most recent call last):
      File "/home/vcap/deps/0/python/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
        rv = self.dispatch_request()
      File "/home/vcap/deps/0/python/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/home/vcap/app/app/utils/user.py", line 26, in wrap_func
        return func(*args, **kwargs)
      File "/home/vcap/app/app/main/views/send.py", line 1041, in send_notification
        recipient=session['recipient'] or InsensitiveDict(session['placeholders'])['address line 1'],
      File "/home/vcap/deps/0/python/lib/python3.9/site-packages/notifications_utils/insensitive_dict.py", line 41, in __getitem__
        return super().__getitem__(self.make_key(key))
    KeyError: 'addressline1'

I'm not sure how to reproduce this, but this should at least give
the user a better experience, instead of a 500 page.
2022-02-18 12:44:01 +00:00
Katie Smith
a7a593fd8b Make separate endpoints for GOV.UK email branding options
The endpoint to change the email branding to "GOV.UK" branding and
"GOV.UK and organisation" branding was the same but with a query string
used to determine which of the two options had been selected. This makes
them two separate endpoints, which makes the code a bit simpler and
hopefully means there is less chance of things not working as expected.
2022-02-03 11:31:25 +00:00
Katie Smith
c5db847543 Change both existing branding URLs
This changes the URLs for someone to request new email or letter
branding to match the new URLs we've agreed for the new email branding
changes. The old URLs are still in place for now too to keep backwards
compatibility.
2022-02-03 09:59:21 +00:00
Katie Smith
f92167de71 Only show branding description pages if branding allowed for service
It shouldn't be possible to view the page to confirm that you want a
particular type of email branding if that branding is not allowed for
your service. Although we don't show banned branding options on the
branding form, it would have been possible to visit the relevant URLs
directly.

We now give a `404` status page if you visit a page to select branding
that isn't allowed.
2022-02-03 09:59:21 +00:00
Katie Smith
f9c551a558 Add and use textarea component from GOV.UK Frontend
For the "Something else" branding form we want the form label to be the
title. This brings in the textarea component from GOV.UK Frontend in
order to do this since that contains code to set a the textarea label as
the page heading in an accessible way.

The rest of the textarea fields have not been switched to use the new
component yet.
2022-02-03 09:59:21 +00:00
Katie Smith
92f76638c8 Split up email branding form into separate pages
We were showing the form to request email branding with a button which
submits your choice immediately. Now, we only submit the form
immediately if "Something else" is the only branding option available to
you. If you select any other radio button (or select "Something else"
when it's not the only option) we take you to another page which either
contains more information or a textbox to fill in the details for the
branding you want.

There is currently some duplication between the new pages and their
tests, but these will be changed in future versions of the work so will
start to differ more.
2022-02-03 09:59:21 +00:00
Katie Smith
d45265fcce Split out existing tests related to submitting branding
The existing tests were parameterized to contain the cases both where
the branding form is successfully submitted and those where it isn't. We
were using `pytest.mark.xfail` to check that the tests fail as expected
if there were errors on the form. However, since I'll be changing how
the form validation works, I want to make sure that these tests were
actually failing because of the form validation and not because of
another reason, such as a slight difference in Zendesk ticket output.

This creates separate tests for cases where data entered in the form
is invalid.
2022-02-03 09:59:21 +00:00
Katie Smith
4226193346 Split up the branding_request endpoint
The endpoint used to handle both email and letter branding, but this
replaces `.branding_request` with `.email_branding_request` and
`.letter_branding_request` instead. This is in preparation for changing
how email branding works.

The `from_template` arg was only possible for letter branding, so I've
removed that from the `.email_branding_request` endpoint.
2022-02-03 09:59:21 +00:00
Chris Hill-Scott
caccbb98d8 Merge pull request #4150 from alphagov/pass-admin-url-reset-password
Pass admin URL to API when resetting password
2022-02-03 09:20:35 +00:00
Chris Hill-Scott
70186dbe9f Pass admin URL to API when resetting password
This follows the pattern for invite emails where the admin app tells the
API which domain to use when generating the link.
2022-02-02 16:55:44 +00:00
Rebecca Law
453a1a699f Merge pull request #4107 from alphagov/mark-letter-invalid-if-over-10-sheets-169209742
Show validation-failed status for templated letters over 10 pages
2022-02-02 07:58:34 +00:00
Pea Tyczynska
ffb8549a21 Merge pull request #4137 from alphagov/rename_column_in_billing_report
Rename sms_fragments to sms_chargeable_units
2022-02-01 17:01:03 +00:00
Chris Hill-Scott
4f672cb5dc Make logo CDN domain into simple config
Having this as a function which does string parsing and manipulation
surprised me a bit when I was trying to figure out why something wasn’t
working.

It’s more in line with the way we do other config like this (for example
`ASSET_PATH`) to make it a simple config variable, rather than trying to
be clever and guess things based on other config variables.

It’s also less code, and is explicit enough that it doesn’t need tests.
2022-01-27 10:33:05 +00:00
Pea Tyczynska
2224eacf6b Merge pull request #4135 from alphagov/display_broadcast_cancelled_by_api
Display if broadcast was cancelled via API
2022-01-21 14:04:18 +00:00
karlchillmaid
97a0b15b0b Merge pull request #4130 from alphagov/add-anchors
Add anchor IDs to headings on GOV.UK Notify
2022-01-20 17:38:25 +00:00
Chris Hill-Scott
862b95751b Fix links which point at text message status anchor 2022-01-20 15:08:02 +00:00
Pea Tyczynska
78681eb452 Display if broadcast was cancelled via API
If broadcast_message has no value under cancelled_by_id, display
in the view that it was cancelled by an API call.
2022-01-19 11:01:03 +00:00
Pea Tyczynska
f1d5c33fda Rename sms_fragments to sms_chargeable_units
This field caused some confusion and lots of unnecessary work
to our colleague because of unclear name.

The field was named sms_fragments, where in fact the value of
the field is: those sms fragments that go above free allowance
multiplied by the rate multiplier.

The new name was chosen through consultation with colleagues
who use billing report the most.
2022-01-18 18:05:07 +00:00
Leo Hemsted
a602ffceb9 fix bug where job reports showed before jobs finished
for a job to be finished there are two requirements:

* the status to be "finished"
* the percentage complete to be 100%

The job status is set to finished when the process_job task finishes
(even though not all process_row may have finished). The
percentage_complete is calculated by comparing the number of
notifications in the database with the number of rows in the
spreadsheet.

This was inadvertently changed from an "and" to an "or" clause two years
ago. This meant that people could download a report when the status was
finished but not all notifications were present in the database. Lets
change it back.

7d52ac97f1 (diff-44b012cad205379c481bed244ddb2294bae5ee85dcd01f4aee932a2bd85b67b2L86-R100)
2022-01-14 15:48:04 +00:00
Katie Smith
f3baacfb56 Stop showing link for cancelled org users 2022-01-13 14:08:37 +00:00
Katie Smith
daed4a7f7f Move org tests between files
This deletes the `test_view_team_members` test since it is now
duplicated by a new test. It also moves a test relating to org
invites to test_organisation_invites.py and one that wasn't related to
invites from that file to test_organisations.py.
2022-01-13 14:08:37 +00:00
Katie Smith
de2afb2f1a Add hidden text next to the 'Cancel invitation' link
This matches what we do on the service team members page.
2022-01-13 14:08:37 +00:00
Katie Smith
d166c6382c Add link next to org team members allowing them to be removed
This adds a link next to the organisation team members which lets
them be removed from the organisation. Service team members have
their own page and the link to remove them appears there. For
organisation team members, we don't currently have any other
information we want to show or any  other actions to perform. As
a result, this change uses the 'Team members' page to show the
confirmation banner.

The endpoint called 'edit_user_org_permissions' was renamed to
'edit_organisation_user' and some of the existing code around deleting
org users (which didn't work) was changed.
2022-01-13 14:08:37 +00:00
Katie Smith
5b658d924c Tweak and add test for OrganisationsClient.remove_user_from_organisation
This stops adding the current user to the data sent to the API when
removing a user from an organisation. API only needs to know the
organisation_id and the id of the user we want to remove from
the organisation, so we don't need to pass through the id of the
current user too.

The other change made is to clear the user cache of the user who has
been removed from the org. We don't need to clear any of the organisation
caches, since these values don't contain lists of users for the orgs.
2022-01-13 14:08:37 +00:00
Chris Hill-Scott
3ab30f27b6 Remove checks for renaming without changes
When checking the service or organisation name for uniqueness before
changing it, it would be necessary to exclude the current name from
this check. However now we are changing it immediately we don’t need
to guard around this behaviour of the uniqueness check.

So this commit removes the guard for both renaming a service and an
organisation.
2022-01-13 10:29:01 +00:00
Chris Hill-Scott
b998b6bb20 Remove methods for checking service/org name uniqueness
We don’t use these now – instead we try to update the name and see if
it works or not.
2022-01-13 10:16:07 +00:00
Chris Hill-Scott
a09af2acc8 Remove update_organisation_name model method
It’s weird to have a method just for updating one attribute. I think
the reason for doing this was to only invalidate the
`organisation-{}-name` cache when absolutely necessary, but:
- we don’t need a separate method to check whether it’s the name being
  updated
- it was easy to get around this by calling
  `OrganisationsClient.update_organisation` directly, leaving a stale
  value in the cache
2022-01-13 10:16:06 +00:00
Chris Hill-Scott
c630faf3b4 Remove re-enter password step from rename organisation
Note that this is copied from the same change made to the rename service
page:
1190e4541b

The original idea behind was to always ask users to re-enter their
password any time:
- we want them to be sure that they want to do what they’re about to do
- we want to be sure it’s really the user trying to do the thing (and
  not someone malicious)

In reality we:
- removed this from the initial place it was added (a descendent of the
  ‘suspend service’ feature)
- only ever added it to the ‘rename service’ and ‘rename organisation’
  features

So in reality it’s not a pattern we have persisted with. Arguably there
are several things you can now do in the admin app without re-entering
your password which are much more high consequence than changing the
service name.

Also, with browser autofill there’s a lot less chance that forcing
someone to re-enter a password really gives much defence against an
unattended laptop, for example.

So this commit removes the need to re-enter your password when renaming
an organisation.
2022-01-13 10:16:03 +00:00
Chris Hill-Scott
d4ec4bf9f4 Don’t error if organisation name is unchanged
If you submit the rename organisation form without making any changes
you will get an error saying that the name is currently in use. This is
true because it’s being used by the current organisation.

However your intention is probably not to actually change anything, so
we can just redirect back to the settings page.

This is the same thing we do when renaming services:
60f5b74904/app/main/views/service_settings.py (L99-L100)
2022-01-13 10:14:17 +00:00
Chris Hill-Scott
6540701aa7 Replace uses of client to set request context
Some tests use the `client` fixture but don’t call any of its methods.
The reason for doing this is because the test depends on something in
the request context.

This commit replaces all those instances with `client_request`, which
also sets the request context.

These tests are the last ones that still use the `client` fixture. By
replacing it with `client_request` we will be able to say that no tests
should be using the `client` fixture directly.
2022-01-10 14:39:46 +00:00
Chris Hill-Scott
7e707db4b2 Replace uses of client.get and client.post
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

Lots of our tests still use an older fixture called `client`. This is
not as good because it:
- returns a raw `Response` object
- doesn’t do the additional checks
- means our tests contain a lot of repetetive boilerplate like `page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')`

This commit converts all the tests which had a `client.get(…)` or
`client.post(…)` statement to use their equivalents on `client_request`
instead.

Subsequent commits will remove uses of `client` in other tests, but
doing it this way means the work can be broken up into more manageable
chunks.
2022-01-10 14:39:45 +00:00
Chris Hill-Scott
07318b2d11 Replace instances of client.login with client_request
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

Lots of our tests still use an older fixture called `client`. This is
not as good because it:
- returns a raw `Response` object
- doesn’t do the additional checks
- means our tests contain a lot of repetetive boilerplate like `page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')`

This commit converts all the tests which had a `client.login(…)`
statement to use `client_request` (which is already logged in by
default).

Subsequent commits will remove uses of `client` in other tests, but
doing it this way means the work can be broken up into more manageable
chunks.
2022-01-10 14:39:45 +00:00
Chris Hill-Scott
8b93a977a0 Remove temporary raw_response argument
We added a new argument to `client_request.get` and
`client_request.post` to specify that it should return a raw `Response`
object rather than an instance of `BeautifulSoup`.

This is useful because sometimes we need to look at stuff like the
response headers.

However it turns out we already have a separate method for this, so
rather than invent something new I think it’s better to stick with the
thing we already have.
2022-01-10 14:39:45 +00:00
Chris Hill-Scott
c37258fd0d Stop using logged_in_client_with_session fixture
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

A few of our tests still use an older fixture called
`logged_in_client_with_session`. It’s not clear how this is different
from `logged_in_client`, which we have replaced with `client_request`.

So this commit goes ahead and converts all the tests using
`logged_in_client_with_session` to use `client_request` instead.
2022-01-10 14:39:45 +00:00
Chris Hill-Scott
0706664be4 Stop using logged_in_client fixture
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

Lots of our tests still use an older fixture called `logged_in_client`.
This is not as good because:
- it returns a raw `Response` object
- doesn’t do the additional checks
- means our tests contain a lot of repetetive boilerplate like `page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')`

This commit converts all the tests using `logged_in_client` to:
use `client_request` instead.
2022-01-10 14:39:44 +00:00
Chris Hill-Scott
50eae6f935 Stop using platform_admin_client fixture
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

For most tests of a platform admin view we used `platform_admin_client`
instead. This is not as good because it returns a raw `Response` object
and doesn’t do the additional checks.

This commit converts all the tests using `platform_admin_client` to:
use new `client_request` and log in as `platform_admin_user` before
making any requests.

This is also nice because it makes any test easy to parametrize with
additional users, for example to test differences in behaviour dependant
on being platform admin or not.
2022-01-10 14:39:40 +00:00
Chris Hill-Scott
0fd79bb500 Merge pull request #4122 from alphagov/no-text-in-svg
Don’t allow <text> elements in letter logos
2022-01-10 11:13:09 +00:00
Chris Hill-Scott
75f8c16071 Convert test to use client_request fixture
This is to avoid merge conflicts with
https://github.com/alphagov/notifications-admin/pull/4118/files
2022-01-06 17:39:01 +00:00
Chris Hill-Scott
291906e9fd Don’t allow <text> elements in letter logos
To render text in an SVG consistently the system rendering the SVG must
have the fonts specified by the SVG installed.

If the fonts are not installed then the renderer will fall back to a
system font and the text will look different. This is especially bad
news for branding where the right font is an integral part of any brand.

To fix this, the text should instead be converted to `<path>` elements.
This process is sometimes called ‘outlining’.

A few of our logos had this problem, and I’ve fixed most of them by
hand. Adding this validation will stop the problem, coming up again.
2022-01-06 17:39:01 +00:00