Commit Graph

3154 Commits

Author SHA1 Message Date
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
Leo Hemsted
713980a35e Merge pull request #3410 from alphagov/letter-timing-fix
fix letter notification status around UTC/BST
2020-04-14 14:23:38 +01:00
Leo Hemsted
671d0872c2 fix letter notification status around UTC/BST
timezones grr blah blah blah
2020-04-14 09:52:13 +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
Chris Hill-Scott
a2929ad748 Delay AJAX calls if the server is slow to respond
By default our AJAX calls were 2 seconds. Then they were 5 seconds
because someone reckoned 2 seconds was putting too much load on the
system. Then we made them 10 seconds while we were having an incident.
Then we made them 20 seconds for the heaviest pages, but back to 5
seconds or 2 seconds for the rest of the pages.

This is not a good situation because:
- it slows all services down equally, no  matter how much traffic they
  have, or which features they have  switched on
- it slows everything down by the same amount, no matter how much load
  the platform is under
- the values are set based on our worst performance, until we manually
  remember to switch them back
- we spend time during incidents deploying changes to slow down the
  dashboard refresh time because it’s a nothing-to-lose change that
  might relieve some symptoms, when we could be spending time digging
  into the underlying cause

This pull request makes the Javascript smarter about how long it waits
until it makes another AJAX call. It bases the delay on how long the
server takes to respond (as a proxy for how much load the server is
under).

It’s based on the square root of the response time, so is more sensitive
to slow downs early on, and less sensitive to slow downs later on. This
helps us give a more pronounced difference in delay between an AJAX call
that is fast (for example the page for a single notification) and one
that is slow (for example a dashboard for a service with lots of
traffic).

*Some examples of what this would mean for various pages*

Page | Response time | Wait until next AJAX call
---|---|---
Check a reply to address | 130ms | 1,850ms
Brand new service dashboard | 229ms | 2,783ms
HM Passport Office dashboard | 634ms | 5,294ms
NHS Coronavirus Service dashboard | 779ms | 5,977ms
_Example of the kind of slowness we’ve seen during an incident_ | 6,000ms | 18,364ms
GOV.UK email dashboard | `HTTP 504` | 😬
2020-04-09 12:05:18 +01:00
Katie Smith
83fe0b0be3 Merge pull request #3406 from alphagov/letter-too-long-content
Update letter too long content
2020-04-09 11:29:49 +01:00
Katie Smith
13650b7d4b Update error messages for letters that are too long
To specify the number of sheets as well as pages in case this is not
clear.
2020-04-09 11:03:07 +01:00
Katie Smith
6b055071f4 Specify mimetype for PDF letters to be downloaded
We had a report that when clicking on the 'Download this letter' link on
the notification page the file was not being downloaded as a PDF file
but was given a `.htm` file extension instead. We should be able to stop
that happening by using Flask's `send_file` function with the right mimetype.
This change updates the `view_letter_notification_as_preview` to use
`send_file` and splits out code to get the file data into a separate
function.

Mocks in the tests have been updated and some unused mocks removed.
2020-04-09 10:35:30 +01:00
Chris Hill-Scott
f06ff5f65f Fix API call to send one off letter
As part of making the API call we extra the recipient from the first
line of the address. This code was assuming that the recipient would
always have the key `address line 1`, but we’re no longer guaranteeing
that it will be capitalised and spaced exactly like that.
2020-04-07 12:59:34 +01:00
Chris Hill-Scott
54d7c6fcbd Get ready to error for precompiled letters with bad addresses
Template preview is going to start returning these errors; we need to be
ready to handle them.
2020-04-07 09:09:03 +01:00
Chris Hill-Scott
c646c16067 Add postcode validation check for one-off letters
We’re doing this everywhere else now, so this completes the story.

It uses the same regex as elsewhere and the error messaging is
consistent (but not uniform) with the other places.
2020-04-07 09:08:51 +01:00
Chris Hill-Scott
26f702ebce Refactor to use PostalAddress helper from utils
Since we’re doing normalisation and line-count-checking of addresses in
multiple places it makes sense for that code to be shared. Which is
what happened here:
https://github.com/alphagov/notifications-utils/pull/713

This commit refactors the admin code to make use of the new utils code.

Note about placeholders:
- they now go into the session as `address_line_1` instead of `address
  line 1` because this is the format the API uses, so should be
  considered canonical
- they are now fetched from the session in a way that isn’t sensitive
  to case or underscores (using the `Columns` class)
- the API doesn’t care about case or underscores vs spaces in
  placeholder names because it’s checking an instance of `Template` to
  see if all the required placeholders are present (see
  401c8e41d6/app/notifications/process_notifications.py (L40))
2020-04-07 09:00:55 +01:00
Pea M. Tyczynska
32eef2f203 Merge pull request #3401 from alphagov/tighten-erorr-check
Tighten error check for duplicate reply to email addresses
2020-04-06 11:30:27 +01:00
Pea Tyczynska
aacd96a6b9 Tighten check for reply to address conflict error
The check was made more permissive temporarily as we were changing
error code we are returning form API from 400 to 409.
2020-04-06 10:51:16 +01:00
Chris Hill-Scott
1fe3f1871e Allow underscores in SMS senders 2020-04-02 15:57:46 +01:00
Chris Hill-Scott
047ca8a48c Fix unnecessary call to organisation API endpoint
We’re caching the organisation name, but still talking to the API
to see if the organisation exists.

`Service().organisation_id` only goes to the JSON for the service.

`Service().organisation` makes a separate API call.

We only need the former to know if a service belongs to an organisation.
2020-04-02 15:24:02 +01:00
Pea M. Tyczynska
a709ee4a29 Merge pull request #3397 from alphagov/postcode-validation
Handle postcode validation for precompiled letters
2020-04-02 14:12:39 +01:00
Pea Tyczynska
86ab0a6a0f Add missing test cases for precompiled validation messages 2020-04-02 13:39:40 +01:00
Chris Hill-Scott
0904ac0533 Make fixture for getting service with organisation
Saves repeatedly defining the same mock.
2020-04-02 13:12:06 +01:00
Chris Hill-Scott
51a5a4b559 Remove unused client method
The app is now always getting an organisation by its `id` (or domain),
and never by `service_id`.

This means that the client method and associated mocking can be removed.

I think this must come from a time when the service response didn’t
include `organisation_id`, but now it always does.
2020-04-02 12:07:20 +01:00
Chris Hill-Scott
cc5701e870 Cache organisation name in Redis
A lot of pages in the admin app are now generated entirely from Redis,
without touching the API.

The one remaining API call that a lot of pages make, when the user is
platform admin or a member of an organisation, is to get the name of
the current service’s organisation.

This commit adds some code to start caching that as well, which should
speed up page load times for when we’re clicking around the admin app
(it’s typically 100ms just to get the organisation, and more than that
when the API is under load).

This means changing the service model to get the organisation from the
API by ID, not by service ID. Otherwise it would be very hard to clear
the cache if the name of the organisation ever changed.

We can’t cache the whole organisation because it has a
`count_of_live_services` field which can change at any time, without an
update being made.
2020-04-02 12:07:19 +01:00
Chris Hill-Scott
c448eb8995 Merge pull request #3388 from alphagov/remove-contact-list-hint
Remove line about contact lists from uploads
2020-04-02 11:04:14 +01:00
Chris Hill-Scott
e8b5de533d Fix relative date for returned letters
It was saying ‘16 hours ago’ instead of today. This is because, in
strftime:
- `%M` means minute, not month
- `%D` means short MM/DD/YY date, not day of the month

The test wasn’t catching this because the freeze time and mocked value
from the API were set to the same minute.
2020-04-01 17:38:06 +01:00
Chris Hill-Scott
84e063c901 Merge pull request #3371 from alphagov/flask-login-again
Flask login (but backwards compatible)
2020-04-01 16:14:38 +01:00
Chris Hill-Scott
3752b44ce8 Merge pull request #3369 from alphagov/address-block-part-deux
one off letter address form part deux
2020-04-01 16:14:27 +01:00
Chris Hill-Scott
3895794208 Merge branch 'master' into flask-login-again 2020-04-01 14:29:16 +01:00
Chris Hill-Scott
61d87bf6c0 Let platform admins delete returned letters cache
Just in case there’s ever a problem with something in these caches. We
missed this before.
2020-04-01 10:18:56 +01:00
Chris Hill-Scott
7fb8e1de92 Use statistics for returned letters on dashboard
This should be faster and more accurate than querying all the reports.
2020-04-01 10:18:55 +01:00
Leo Hemsted
3529188968 redirect from address_line_n to address textarea page
if someone starts a new one-off flow they'll get taken to the address
page. However, if someone hits the back button, they'll cycle backwards
through placeholders and will end up on the individual line pages. Lets
redirect them to the correct place.

We'll additionally need to reconstruct the address block from the
various session variables that may or may not be populated
2020-03-31 16:59:48 +01:00
Leo Hemsted
c4d839d4f5 input letter address data in a single block
rather than in multiple placeholders - this is the first step towards
making postcodes non-required, which is the first step towards
international letters.

they still populate address_line_# and postcode fields under the hood -
to keep validation working the same, the last line always goes into
`postcode`.

the form normalises whitespace, removes extra new lines, and enforces
that you have between three and seven lines.

if the letter repeats address placeholders further down (eg "Dear
((address_line_1))"), then it'll fill those in as well. It'll still
prompt you to fill them in, but they'll be pre-filled.
2020-03-30 19:29:26 +01:00
Leo Hemsted
df51bf6f5f small QOL changes in conftest
if we are asserting on a redirect we expect the result to be 302 (you
could still override this to 301 if you want).

also give some function calls kwargs to make them easier to read
2020-03-30 18:05:50 +01:00
Chris Hill-Scott
57ec58ab4e Merge pull request #3377 from alphagov/delete-contact-list
Let users delete a contact list
2020-03-27 16:13:32 +00:00
Chris Hill-Scott
7582b8face Remove line about contact lists from uploads
This line doesn’t make sense now that you can upload a contact list in
advance of having a template.
2020-03-26 17:17:11 +00:00
Chris Hill-Scott
8a093fd34c Merge pull request #3338 from alphagov/remove-permission-checks-uploads
Clean up the codebase after moving everyone to the new uploads page
2020-03-26 17:00:16 +00:00
Chris Hill-Scott
db2d312ba7 Link to ‘who it’s for’ when error creating account
If someone enters an email address from a domain we don’t recognise we
direct them straight to our support channel. This is causing increased
contact from suppliers and members of the public.

Now that we have a page which explains who can use Notify, let’s direct
people there first. Then if they really do need to contact support
(because we don’t recognise their organisation) then they can do so from
that page.
2020-03-26 14:55:51 +00:00
Chris Hill-Scott
41dd7a883b Add who’s its for page
We have a policy about how suppliers are allowed to use Notify. But we
don’t explain it anywhere. Which drives contact to our support form.

This commit that adds a new page that explains the policy.

I’ve moved the related content about who else can use Notify from the
get started page to this page as well, where it doesn’t need to sit in
a details element.
2020-03-26 14:55:51 +00:00
Chris Hill-Scott
d83e7a8e9f Tidy up the jobs template 2020-03-25 15:27:26 +00:00
Chris Hill-Scott
7d57a4d9b8 Redirect the old jobs URL 2020-03-25 13:58:23 +00:00
Chris Hill-Scott
2ca32019e4 Go back to triage page if you’ve come from there 2020-03-25 12:21:51 +00:00
Chris Hill-Scott
8335de1432 Use correct back link pattern on escalation page 2020-03-25 12:20:49 +00:00
Chris Hill-Scott
8e055a4375 Remove prefilled message thing 2020-03-24 17:56:12 +00:00
Chris Hill-Scott
697803a10c Add a ‘general’ ticket type
This is for tickets coming from non-logged-in users. It’s effectively
the same as reporting a problem, but doesn’t have the banner about
the status page (because we can’t tell if they’re actually reporting a
problem now we’re not asking).

It also gives a more generic page title.
2020-03-24 17:56:11 +00:00
Chris Hill-Scott
30a3418473 Refactor so constants are used everywhere 2020-03-24 17:48:13 +00:00
Chris Hill-Scott
17a3ee920c Use the same template for problems and questions 2020-03-24 17:48:12 +00:00
Chris Hill-Scott
61ab9661fb Direct members of the public somewhere more useful
We can’t give advice to members of the public, but increasingly we’re
seeing them try to use our support form to ask.

It would be better for them if we can direct them straight to somewhere
more useful, before they have the chance to raise a support ticket.

This commit replaces the report a problem/ask a question triaging for
users who aren’t signed in. It’s not possible for non-signed-in users to
raise an priority 1 ticket, so we never need to triage the tickets in
this way.

Instead we can triage people based on whether they work in the public
sector or not. If they do then we send them on to the feedback form. If
not then they go to a new page which contains some useful links. We’ve
chosen these links based on some analysis of the support tickets we’ve
received recently[1]

1. https://docs.google.com/spreadsheets/d/1uBQn-ZnCYfz6ltFaUKZpytgvBF0-MeshCLZ1cD74R0c/edit?usp=sharing
2020-03-24 17:48:11 +00:00
David McDonald
d7385da0df Require email address for all support tickets
We are seeing little benefit of allowing users to not put in their email
address. This will mean that you must provide it for feedback, not just
problems with the site.

There could maybe be some more refactoring of the support templates as
this is now very similar to the report a problem page but this is a
quick fix so haven't gone too in depth.
2020-03-23 11:21:52 +00:00
Tom Byers
a2f9f8d36a Merge pull request #3378 from alphagov/change-agreement-test-post-param
Remove POST param from agreement test
2020-03-20 10:57:02 +00:00
Chris Hill-Scott
8f15eee5e0 Let users delete a contact list
Follows our standard pattern of confirming with a red banner for actions
that are destructive.
2020-03-19 15:17:01 +00:00