Commit Graph

6739 Commits

Author SHA1 Message Date
David McDonald
ba80d5b7cd Introduce abstraction for s3 metadata
S3 metadata only supports ascii characters. Whenever we save data to it
we need to make sure we encode it to save it and then decode it to
display it again to users. This abstraction will act as the place for
that decoding to happen so the rest of the code in our views doesn't
need to care about the encoding abstraction.
2020-05-18 16:13:31 +01:00
Chris Hill-Scott
e79ea0e383 Merge pull request #3439 from alphagov/previous-financial-years
Show 2 previous financial years on usage page
2020-05-11 15:15:00 +01:00
Chris Hill-Scott
8215022725 Show 2 previous financial years on usage page
From a question on cross-government Slack:

> re the Usage tab - currently it shows 3 financial years - last year,
> this year and next year. is it possible to replace the "next year" tab
> with something more useful? its always going to be blank! I was
> thinking it would be good to have 2 financial years ago, 1 financial
> year ago and this financial year.

This seems like a reasonable idea, and is something we’ve talked about
before. The original intention[1] was that seeing your (unchanged) free
allowance for next year would be useful, but that doesn’t really seem to
be a user need.

***

1. See https://github.com/alphagov/notifications-admin/pull/1094
   > so that you can check what your SMS allowance is going to be before
   > you actually get into it
2020-05-07 16:50:19 +01:00
karlchillmaid
f4f9cf3fdd Revert change 2020-05-07 16:42:32 +01:00
karlchillmaid
d5e02df97f Update content
Update descriptions of pages and services. Shorten one of the link titles.
2020-05-07 16:38:13 +01:00
Chris Hill-Scott
77b7e4b8ea Merge pull request #3436 from alphagov/limit-search-50
Don’t show pagination links when searching
2020-05-07 10:09:58 +01:00
Chris Hill-Scott
8655e519aa Change logic around to be clearer
Think this is a clearer expression of what the intent it.
2020-05-07 09:50:03 +01:00
Chris Hill-Scott
f30187b529 Don’t show pagination links when searching
The search form makes a post request, so that phone numbers and email
addresses don’t show up in logs or browser history.

At most the API will return 50 results, with some pagination links. We
can’t easily give you links to click in the admin app, because links can
only perform get requests.

Because the value of seeing more than 50 results feels quite low (users
will probably make their search more specific before scrolling through
all 50) let’s just show a message saying only the first 50 results are
displayed.
2020-05-06 17:33:19 +01:00
David McDonald
b6935a3c6c Fix bug with letter job CSV downloads
We were throwing an exception when instantiating a LetterImageTemplate
as we weren't giving it all the arguments it needed.

 Now we give it all the correct parameters and add a
test for the method. Ideally we would add a unit test for the flask
route for downloading a letter job CSV (which is currently lacking) but
I did the minimal to be confident I've fixed the bug as I think this
whole code may be fresh for a bit of a rewrite according to Chris.

Original error:
```
File "/Users/davidmcdonald/.virtualenvs/notifications-admin/lib/python3.6/site-packages/notifications_utils/template.py", line 669, in __init__
    raise TypeError('image_url is required')
TypeError: image_url is required
```
2020-05-06 14:44:37 +01:00
Chris Hill-Scott
3e6d9a564b Add interstitial page before using email auth token
Some email clients will pre-fetch links in emails to check whether
they’re safe. This has the unfortunate side effect of claiming the token
that’s in the link.

Long term, we don’t want to let the link be used multiple times, because
this reduces how secure it is (eg someone with access to your browser
history could re-use the link even if you’d signed out).

Instead, this commit adds an extra page which is served when the user
clicks the link from the email. This page includes a form which submits
to the actual URL that uses the token, thereby not claiming the token as
soon as the page is loaded.

For convenience, this page also includes some Javascript which clicks
the link on the user’s behalf. If the user has Javascript turned off
they will see the link and can click it themselves. This is going on the
assumption that whatever the email clients are doing when prefetching
the link doesn’t involve running any Javascript.

This Javascript is inlined so that:
- it is run as fast as possible
- it’s more resilient – even if our assets domain is unreachable or the
  connection is interrupted, it will still run
2020-05-04 15:53:27 +01:00
Chris Hill-Scott
ae2f8f9887 Add a second URL for the email auth endpoint
We’re going to add an interstitial page that redirects to this new URL.
But we don’t want that redirect to 404 while the change is deploying,
because some boxes will have the new URL and some won’t. So let’s deploy
the new URL to all the boxes first, then the redirect page can safely
take over the new one.

The new URL is going to be `post` not `get` because that feels more
HTTP-y, so we need to make sure that’s part of this change too.
2020-05-04 14:09:01 +01:00
Chris Hill-Scott
4cf218f5c8 Add error messages for bad international addresses
Template preview started putting these in the metadata of the S3 object
in this pull request: https://github.com/alphagov/notifications-template-preview/pull/445

Specific error key is defined here:
800b48fce5/app/precompiled.py (L558)
2020-05-04 10:14:16 +01:00
Chris Hill-Scott
53724dacd1 Tell template preview whether a letter can be sent internationally
If a service has permission to send international letters then the admin
app should tell template preview, so that template preview knows what
rules to apply when it’s validating the address of the letter.

We don’t need to wait for template preview to start looking at this
query string argument – it will just ignore it for now.
2020-05-01 15:43:54 +01:00
Chris Hill-Scott
0ef076f59e Merge pull request #3416 from alphagov/validate-3-lines-csv
Allow all the new address goodness in spreadsheets
2020-05-01 15:37:08 +01:00
Chris Hill-Scott
4892b2db77 Merge pull request #3425 from alphagov/tidy-up-platform-admin
Tidy up the platform admin pages
2020-04-30 14:42:55 +01:00
Chris Hill-Scott
06108de0f7 Allow international addresses in spreadsheets
For services with permission, they can now put international addresses
into their spreadsheets without getting a postcode error.

This also means they can start using address line 7 instead of postcode,
since it doesn’t make sense to put a country in a field called
‘postcode’. But this will be undocumented to start with, because we’re
not giving any real users the permission.

It does now mean that the number of possible placeholders (7 + postcode)
is greater than the number of allowed placeholders (7), so we have to
account for that in the one-off address flow where we’re populating the
placeholders automatically. We’re sticking with 6 + postcode here for
backwards compatibility.
2020-04-29 16:19:57 +01:00
Chris Hill-Scott
84dbae6e39 Use tabular numbers for dashboard banner counts
We use tabular (not lining) figures everywhere else that we display counts, so that they don’t shift around as the AJAX updates the numbers.

There’s a good explanation of the difference here: https://www.fonts.com/content/learning/fontology/level-3/numbers/proportional-vs-tabular-figures
2020-04-29 15:17:12 +01:00
Chris Hill-Scott
5f0cfc4070 Merge pull request #3424 from alphagov/bump-wtforms
Bump WTForms to 2.3.1
2020-04-29 11:31:59 +01:00
Chris Hill-Scott
51bcf05f6e Merge pull request #3420 from alphagov/search-letters
Let users search for letters
2020-04-28 10:13:36 +01:00
Chris Hill-Scott
832445774b Add postal address row errors
Context:
- postal addresses can be made from any of the 7 address lines now, and
  the postcode can be in any one of the 7
- we can put errors across a whole row now, not just on individual cells

This commit put errors to do with the postal address as a whole across
the whole row now, rather than tying them to any one cell.
2020-04-27 16:47:50 +01:00
Chris Hill-Scott
f5649d72c9 Explain 3 required address columns
Our rules about address columns are relaxing, so that none of them are
mandatory any more. Instead you just need any 3 of the 7 to make a valid
address.

This commit updates our error messaging to reflect that.
2020-04-27 16:47:49 +01:00
Rebecca Law
347209f5c0 Fix typo 2020-04-27 13:52:37 +01:00
Rebecca Law
8c7495ea45 Update the pricing page 2020-04-27 13:51:29 +01:00
Pea M. Tyczynska
33786fc3d9 Merge pull request #3423 from alphagov/update-healthcheck-page
Update _status page - remove references to Travis
2020-04-24 14:37:41 +01:00
Chris Hill-Scott
f79527bfd9 Merge pull request #3413 from alphagov/delay-initial-ajax-call
Delay the initial AJAX call by 2 seconds
2020-04-24 12:06:19 +01:00
Pea Tyczynska
652b627312 Update healthcheck page and remove all travis references from the repository 2020-04-24 11:54:26 +01:00
Chris Hill-Scott
986f2752e0 Let users search for letters
Like we have search by email address or phone number, finding an
individual letter is a common task. At the moment users are having to
click through pages and pages of letters to find the one they’re looking
for.

Users of the API will also be able to search by reference, same as for
emails and text messages. But we only show this hint text to users who
have some API keys.
2020-04-23 16:44:41 +01:00
Chris Hill-Scott
ae8dd8e8cd Tidy up the platform admin pages
This commit does two things:
- brings the ‘All organisations’ page back within the platform admin
  part of the site (because it’s hard to find otherwise)
- makes the layouts of all the pages within platform admin a bit closer
  to the service-specific pages in terms of heading sizes, spacing, etc
  so that moving between them doesn’t feel so jumpy
2020-04-23 13:50:36 +01:00
Chris Hill-Scott
65bb72ef2f Bump WTForms to 2.3.1
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to subclass it – it can just be its own
self contained thing. Then we don’t need to add the extra dependency.

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. https://github.com/wtforms/wtforms/pull/429
2. https://github.com/wtforms/wtforms/issues/238
3. https://design-system.service.gov.uk/components/radios/#error-messages
2020-04-23 12:57:10 +01:00
Chris Hill-Scott
bc4f2166cd Merge pull request #3422 from alphagov/fix-sms-preview-activity
Fix preview of text messages on activity page
2020-04-23 11:30:28 +01:00
Chris Hill-Scott
0d92664fc8 Fix preview of text messages on activity page
Also beefs up the tests a bit so we can be more confident that the right
thing is getting displayed.

Depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/725
2020-04-22 16:10:40 +01:00
Katie Smith
ffdcda02bf Show error when user cannot be archived
A user can't be archived if they are the only member of their service
with `manage_settings` permission. `notifications-api` returns a `400`
and an error message if that is the case, however this PR to remove the
`400` error handler
https://github.com/alphagov/notifications-admin/pull/3320 stopped the
error message from showing. This meant that instead of seeing a message
about why a user couldn't be archived, we would just show a `500` error
page instead. This change checks the response from `notifications-api`
and shows an error banner with a message if the user can't be archived.
2020-04-21 18:35:36 +01:00
David McDonald
f91aba212d Merge pull request #3419 from alphagov/sms-sender-length
Reduce min sender length from 4 to 3
2020-04-21 14:53:52 +01:00
David McDonald
9f557dd086 Reduce min sender length from 4 to 3
This is now supported at the network and aggregator level
2020-04-21 12:51:54 +01:00
Chris Hill-Scott
e56c2d28b0 Fix letter branding preview
Template preview requires `template_type` to be passed in now.
2020-04-21 11:21:02 +01:00
Chris Hill-Scott
788edc46f2 Merge pull request #3415 from alphagov/normalise-2fa-code-input
Allow spaces and dashes in the two factor code
2020-04-21 10:14:19 +01:00
Chris Hill-Scott
b0cf36e1c7 Allow spaces and dashes in the two factor code
I noticed when using the dication software that saying ‘one two three
four five’ got dictated as `123 45`. This tripped the validation,
because the space character isn’t a digit.

So this commit normalises out spaces (and other spacing characters like
dashes and underscores) before validating the code and sending it to the
API.

I can also imagine that some people might like to space out the code to
make it easier to transcribe (like you might do with a credit card
number).
2020-04-17 16:16:52 +01:00
Chris Hill-Scott
e2d1401b54 Show error across the whole row
Errors with messages being too long or empty aren’t specific to a single
cell of the uploaded spreadsheet, they’re the results of combining all
the cells with the template.

Previously we could only show errors against a specific cell. This
commit makes it possible to add a super-row which spans all the cells,
into which we can put errors.

The index (header) column then spans both these rows, to show that they
are both associated with the same row of input.

Depends on:
- [x] https://github.com/alphagov/notifications-utils/pull/719
2020-04-17 11:06:34 +01:00
Chris Hill-Scott
f37137cdb3 Convert list table to mapping table
A list table takes a list of input, and assumes one row of output. In
order to show errors that span multiple rows we need to output two rows
for one item of input.

The list table inherits from the mapping table; using the mapping table
directly gives us the flexibility we need.
2020-04-17 11:06:33 +01:00
Chris Hill-Scott
202d4cdb5a Merge pull request #3414 from alphagov/moj-bank-holidays
Remove hard-coded bank holidays
2020-04-17 11:04:27 +01:00
Chris Hill-Scott
e68f9c6db9 Remove hard-coded bank holidays
Looks like someone in the Ministry of Justice has made a nice little
Python package of them.

I’ve configured it to use the cached holidays that come with the
package, rather than going to the GOV.UK website every time we start the
app. This should be more reliable, and means we’ll only get updates when
we do a version bump (PyUp should keep an eye on this for us).
2020-04-16 15:06:54 +01:00
Chris Hill-Scott
8da16468ff Delay the initial AJAX call by 2 seconds
At the moment the first AJAX call is triggered as soon as the page
loads. We then look at its response time to work out how long to wait
until making the next call.

This isn’t great because:
- stuff is unlikely to have changed straight away, so it’s a waste of a
  call
- while the DOM is being updated it seems to introduce a delay in
  clicks on links, which is either more pronounced or more noticeable
  when it’s happening straight away, making the UI feel less snappy

I chose a value of 2 seconds as a rough proxy for the minimum time we’d
expect to see a notification go from created to delivered. Median
time-to-delivered was 2.9 seconds when we analysed it for
https://github.com/alphagov/notifications-admin/pull/2974#discussion_r286101286
2020-04-16 13:21:24 +01:00
Chris Hill-Scott
88734bb74f Bump utils to bring in recent changes to Template classes
The main things we have to account for are:
- `WithSubjectTemplate` has gone
- every template dictionary must have `template_type` set
2020-04-15 17:58:57 +01:00
Chris Hill-Scott
157ab82fea Fix back link on check notifications page
It wasn’t using the same logic around placeholders and address lines as
the rest of the send one off steps.
2020-04-15 15:42:25 +01:00
Chris Hill-Scott
f773a6ed71 Factor out skip link to reduce complexity
The code was too complex and Flake8 was complaining.

While this code isn’t related to the change we’re making it is easy
enough to factor out.
2020-04-14 15:20:03 +01:00
Chris Hill-Scott
d31c244363 Don’t send users back to a page that will send them forward again
If you’re on a page with a normal placeholder and the previous
placeholder is one that’s also in the address block then going back to
the previous page will send you immediately forward to the current page
again.

This commit makes the back link a bit smarter by skipping over pages
where it can see that they relate to a placeholder from the address
block.

If it gets all the way to the start of the list of placeholders without
finding any non-address ones then it will default to generating a link
that will redirect the user to filling in the address block again.
2020-04-14 15:20:03 +01:00
Chris Hill-Scott
b68dd569fc Skip over placeholders if they’re in the address
We don’t really want you modifying lines of the address after you’ve
entered it. Especially when it might not be obvious that modifying the
address line placeholder will modify the address you’re sending the
letter to.
2020-04-14 15:19:29 +01:00
Chris Hill-Scott
6c7e6fa64e Remove the code to handle optional address placeholders
Optional address placeholders aren’t a thing for one-off letters any
more, so we can tidy up the code a bit by removing the parts of the flow
that are accounting for them.
2020-04-14 15:19:29 +01:00
Chris Hill-Scott
53918f8d9f Don’t go back to address if address placeholder in letter
If you have an placeholder from the address block elsewhere in your
letter then you currently get redirected to the address block page
instead of being offered to fill that placeholder in. This commit
tightens up the check to only do this when the placeholder is in the
first 7 placeholders, which is where we store the address placeholders.
2020-04-14 15:19:29 +01:00
Chris Hill-Scott
23e1682260 Make dynamic attributes of model introspectable
`dir(object)` is a useful Python function that tells you what attributes
and methods an object has. It’s also used by tools like iPython and IDEs
for code completion.

Some of the attributes of a `JSONModel` are dynamic, based on what
fields we expect in the underlying JSON. Therefore they don’t
automatically end up in the result of calling `dir`. To get around this
we can implement our own `__dir__` method, which also returns the names
of the fields we’re expecting the the JSON.

Inspired by this Raymond Hettinger tweet:

> #python tip:  If you add attributes to an API with __getattr__() or
> __getattribute__(), remember to update __dir__() to make the extension
> introspectable.

— https://twitter.com/raymondh/status/1249860863525146624
2020-04-14 09:44:38 +01:00