Commit Graph

9693 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
Chris Hill-Scott
66b748bfd2 Merge pull request #3409 from alphagov/introspect-dynamic-model-properties
Make dynamic attributes of model introspectable
2020-04-14 14:19:09 +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
cee7277b47 Merge pull request #3405 from alphagov/ajax-backoff
Delay AJAX calls if the server is slow to respond
2020-04-09 12:19:32 +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
2c7e7fbc4b Merge pull request #3403 from alphagov/pdf-bug-fix
Specify mimetype for PDF letters to be downloaded
2020-04-09 11:29:39 +01:00
Katie Smith
0b81b697c2 Delete commented code
This content was all moved to other pages.
2020-04-09 11:04:20 +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
Tom Byers
2992aacd8a Merge pull request #3404 from alphagov/fix-time-in-cookies-tests
Fix timestamp used for clearing old cookies
2020-04-08 09:17:48 +01:00
Tom Byers
6d620dd283 Fix timestamp used for clearing old cookies
The code in the test that added the 'old' cookies
uses Greenwich Mean Time (GMT) format:

https://github.com/alphagov/notifications-admin/blob/master/tests/javascripts/support/helpers/cookies.js#L19

The code that cleared any 'old' cookies doesn't
specify a time format so uses that set on the host
OS:

https://github.com/alphagov/notifications-admin/blob/master/app/assets/javascripts/cookieMessage.js#L12
https://github.com/alphagov/notifications-admin/blob/master/app/assets/javascripts/cookieMessage.js#L19

Cookies are deleted by setting the data to one
that has expired. Because of the hour difference
the date set to make the cookies expire didn't
work.

This fixes that by making the clearing up code use
GMT.
2020-04-08 08:51:53 +01:00
Chris Hill-Scott
8219b5aa79 Merge pull request #3402 from alphagov/fix-send-one-off-letter-post
Fix API call to send one off letter
2020-04-07 13:28:35 +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
d70172a452 Merge pull request #3400 from alphagov/validate-postcode-templated-one-off
Add postcode validation check for one-off letters
2020-04-07 12:15:55 +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
17f4d3cfff Merge pull request #3399 from alphagov/underscores-in-sms-senders
Allow underscores in SMS senders
2020-04-02 16:03:59 +01:00
Chris Hill-Scott
1fe3f1871e Allow underscores in SMS senders 2020-04-02 15:57:46 +01:00
Chris Hill-Scott
c400695f68 Merge pull request #3398 from alphagov/fix-unecessary-call-to-get-org
Fix unnecessary call to organisation API endpoint
2020-04-02 15:37:41 +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
00404a0017 Merge pull request #3391 from alphagov/cache-organisation-name
Cache organisation name in Redis
2020-04-02 13:26:31 +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
Pea Tyczynska
0a7fa1f799 Update content for postcode valdiation handling for precompiled 2020-04-02 11:45:57 +01:00
Pea Tyczynska
5036511803 Handle postcode validation 2020-04-02 11:23:17 +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
1947b62ed9 Merge pull request #3396 from alphagov/fix-relative-date-for-returned-letters
Fix relative date for returned letters
2020-04-02 09:58:31 +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
fef822d470 Merge pull request #3395 from alphagov/update-humanize
Update humanize from 1.0.0 to 2.2.0
2020-04-01 16:00:50 +01:00
pyup-bot
1dc9f0aa5d Update humanize from 1.0.0 to 2.2.0 2020-04-01 14:37:12 +01:00
Chris Hill-Scott
3895794208 Merge branch 'master' into flask-login-again 2020-04-01 14:29:16 +01:00
Chris Hill-Scott
f6a286ca4f Merge pull request #3314 from alphagov/itsdangerous-upgrade
Upgrade itsdangerous
2020-04-01 13:50:49 +01:00
Chris Hill-Scott
7930dc0b4a Merge pull request #3345 from alphagov/returned-letters-stats
Use statistics for returned letters on dashboard
2020-04-01 10:44:08 +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
c3fa8ab2e1 Merge pull request #3368 from alphagov/address-block
one off letter address form
2020-03-31 16:08:11 +01:00