Commit Graph

83 Commits

Author SHA1 Message Date
Chris Hill-Scott
5c2469b24e Refactor to use shared date comparison function
This means we don’t have to repeatedly do timezone conversions or string
to datetime conversions in our business logic.
2020-09-29 13:38:00 +01:00
Tom Byers
a75cde039f Merge pull request #3624 from alphagov/add-accessible-letter-specification
Add accessible letter specification
2020-09-22 16:36:15 +01:00
Chris Hill-Scott
2d64306e88 Link to specification page, not PDF directly 2020-09-22 15:49:38 +01:00
Chris Hill-Scott
ae17ff1f07 Fix significant figure round for value of 0
You can’t do `log10(0)` in maths, so we need to handle it as a special
case.
2020-09-17 11:08:36 +01:00
Chris Hill-Scott
f824b3a5eb Give specific error if international letters off
If a service doesn’t have permission to send international letters but
someone tries to upload a letter with a valid international address we
just tell them that the last line must be a UK postcode.

This is a bit opaque and:
- suggests that we’re not recognising at all that it’s not a UK letter
- doesn’t explain why it must be a UK postcode

This commit adds a new, error message which tells users why their letter
can’t be sent. And hopefully will give them a better idea of how to
resolve the problem, if they really do need to be able to send
international letters.
2020-09-10 11:25:17 +01:00
Pea Tyczynska
67da2c28bf Deep merge jsonlike objects
Also remove duplicate checkboxes code
2020-08-14 14:58:05 +01:00
Katie Smith
ba5f7d7c36 Check for invalid chars in letter addresses
This now adds validation for invalid characters on the
LetterAddressForm for one off letters. It also adds a validation failed
message for uploaded letters, precompiled letters sent through the API,
and CSV rows with errors.
2020-07-31 08:51:07 +01:00
Chris Hill-Scott
34f5417844 Group uploaded letters by day of printing
Some teams have started uploading quite a lot of letters (in the
hundreds per week). They’re also uploading CSVs of emails. This means
the uploads page ends up quite jumbled.

This is because:
- there’s just a lot of items to scan through
- conceptually it’s a bit odd to have batches of things displayed
  alongside individual things on the same page

So instead we’re going to start grouping together uploaded letters. This
will be by the date on which we ‘start’ printing them, or in other
words the time at which they can no longer be cancelled.

This feels like a natural grouping, and it matches what we know about
people’s mental models of ‘batches’ and ‘runs’ when talking about
printing.

This grouping will be done in the API, so all this commit need to do is:
- be ready to display this new type of pseudo-job
- link to the page that displays all the uploaded letters for a given
  print day
2020-05-11 14:29:03 +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
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
Leo Hemsted
671d0872c2 fix letter notification status around UTC/BST
timezones grr blah blah blah
2020-04-14 09:52:13 +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
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
Pea Tyczynska
86ab0a6a0f Add missing test cases for precompiled validation messages 2020-04-02 13:39:40 +01:00
Pea Tyczynska
e413798b4d Change email_access_validated_at formatting to be more in line with other dates on User model 2020-02-17 11:34:25 +00:00
Pea Tyczynska
7d460fe483 Move date-checking logic to utils and unit test it 2020-02-17 11:34:25 +00:00
Katie Smith
f425fe75cf Update link in error messages for uploaded letters 2020-02-13 16:14:11 +00:00
Leo Hemsted
4e1fcfbff1 handle invalid upload errors correctly
previously it assumed that invalid_pages would always exist, however it
might be `None` if the error isn't on a specific page. Errors on
specific pages include a page not being A4 or content being outside the
boundary. Errors not on specific pages include the file not being a pdf,
or containing too many pages
2020-01-27 15:11:37 +00:00
Chris Hill-Scott
34f209a08b Fix mixed-up error messages
The too many pages error was being returned when the file couldn’t be
read. This commit corrects the error message, and adds a test to make
sure this case is covered.
2020-01-20 15:54:07 +00:00
Chris Hill-Scott
1fc0f58541 Add test for plural form of error message 2020-01-20 15:50:16 +00:00
Chris Hill-Scott
3762daad84 Add a redirect for the letter specification
This way we have a URL we can give people that always points to the
latest version of the spec.

And it makes our code more Flask-idiomatic to be using `url_for` to be
generating a URL, rather than passing around a constant.
2020-01-15 11:54:14 +00:00
Chris Hill-Scott
b57e4a0d0d Test URLs separately
It’s hard to read the tests when they have HTML bundled up with content.
So this commit:
- introduces BeautifulSoup to parse the HTML
- asserts separately on the text and any links found in the HTML
2020-01-14 13:50:22 +00:00
Chris Hill-Scott
540945539b Add some summaries of letter validation errors
We show letter validation errors in two places:

1. In response to a user uploading a PDF
   Here we use the error banner pattern because the problem is as a
   direct consequence of a user’s action, and is blocking them from
   continuing.

2. Once a PDF provided through the API has been validated
   We use a less prominent pattern of red text with no border because
   the message is reporting on something that’s already happened, and
   which wasn’t a direct consequence of the user clicking something

Because the context and patterns used are different we need slightly
different content in each of these situations. Previously we tried to
reuse the same content to make the code cleaner and less repetitive. But
ultimately a clear interface trumps clear code.
2020-01-14 13:34:18 +00:00
Chris Hill-Scott
72abd89fe0 Fix indentation and trailing commas
This will make the diffs introducing substative changes easier to read.
Consistent indenting and always having trailing commas on lists and
dictionaries makes for smaller diffs.
2020-01-14 13:31:29 +00:00
Rebecca Law
f7b3f9b06a - Remove the trailing comma from the first line of the "to" field
- Add client_reference to the activity CSV report
- Show the recipient on the CSV report the same way as the view activity page.
2020-01-10 16:00:40 +00:00
Rebecca Law
47ec4912db Merge pull request #3253 from alphagov/new-no-address-message
Added a new error message when the letter is missing an address block.
2020-01-10 15:44:47 +00:00
Rebecca Law
70276cb526 Added a new error message when the letter is mising an address block.
Before deploying a change to template-preview to return a validation error for letters that are missing the address block, we need to add the new erorr message to admin.

Some content changes have been made to other messages.
The format of the message has changed.
2020-01-10 14:42:56 +00:00
Katie Smith
8e9b7ae368 Remove arguments from fixtures
These can't be used, since we fixtures can no longer be called as if
they were functions, so we can simply the code by removing them.
2020-01-10 12:17:56 +00:00
Katie Smith
8f7a05200d Add function to map template-preview errors to user-friendly errors
Template preview now returns a short string as it's error message plus
a list of invalid pages.
2019-10-21 08:35:04 +01:00
Pea Tyczynska
4a679a6583 Letter job can't be cancelled if already printed
Non-cancellable letter statuses mean that it's too late to cancel a job
2019-07-04 14:44:21 +01:00
Chris Hill-Scott
55d4810c4b Don’t convert Excel reports to CSV before output
Converting Python data to CSV makes every field a string. This means
that in the report we return to the user every field will be a string,
even if it’s come from an `int` type in Python. This is because the CSV
‘standard’ doesn’t support any kind of typing.

Excel does support types for fields, so we can make our reports more
useful by preserving these types. This is particularly relevant in the
report we generate for performance platform, which needs the `count`
column to be a number type.

This commit adds extra code paths to the `Spreadsheet` class which mean
that it can be instantiated from either CSV data or a list of Python
data. Previously we were converting the Python data to CSV as an
intermediate step, before instantiating the class.
2019-05-07 16:07:23 +01:00
Chris Hill-Scott
9d99c78c3a Remove code that reads domains.yml
Since we’ve removed calls to this code from the rest of the app, it can
safely be removed now.
2019-04-12 15:23:08 +01:00
Chris Hill-Scott
032cbf9a17 Flag go live requests from DWP
It’s not enough to check that they’ve signed the agreement. We have to
make sure we inform them every time a service wants to go live.
2019-02-19 11:18:50 +00:00
Chris Hill-Scott
978719cd20 Ensure domains are canonicalised
So, each domain owner only has one entry in the file (but can still
have multiple domains).
2019-02-12 13:33:14 +00:00
Chris Hill-Scott
70ac96fed9 Make sure all domains are lowercased 2019-02-12 13:33:14 +00:00
Chris Hill-Scott
ba8d2ff1e3 Don’t let domains have none values 2019-02-12 13:33:13 +00:00
Katie Smith
f005d7a569 Refactor to split s3_client.py into multiple files
Separated s3_client.py into 3 files - for logos, CSV files and the MOU.
This helps to keep things clearer now that we need to add lots more logo
functions for letters.
2019-02-06 17:26:58 +00:00
Chris Hill-Scott
a093b8d976 Use Babergh as the example in tests
Because Aberdeenshire have signed the agreement.
2019-01-08 15:12:52 +00:00
Pea Tyczynska
1858ee93fd Notifications CSV Report now also shows sender email address 2018-12-07 11:20:20 +00:00
Katie Smith
088d6ee4b0 Content changes for notification pages
This commit adds content pages for the notifications pages, particularly
the letter pages, which will make things clearer now that we will soon be allowing
letters to be cancelled.

The main changes are:
* The confirmation banner for letters sent from a CSV file now states when
printing will start.
* We state the CSV file that notifications were sent from on the
notifications page
* The notification page for letters shows when printing starts (today,
tomorrow, or that date that the letter was printed)
2018-12-03 10:42:47 +00:00
Chris Hill-Scott
bc6b9c7af7 Use named arguments for clearer string formatting
Helps when the string is long.

Also helps disambiguate between the CDN domain used for the logos and
those for CSS/JS.
2018-11-29 11:56:01 +00:00
Leo Hemsted
32f39475d2 remove dupe of get_letter_timings
it was moved from admin to utils a while ago
2018-09-28 15:02:32 +01:00
Chris Hill-Scott
20e71499f0 List who sent a message in CSV download
This is useful if you have lots of people sending messages and want to
report on who’s doing what.

Needs the API updating to return `created_by_name` in its response.
2018-09-06 14:52:31 +01:00
Chris Hill-Scott
47c9b71fa8 Add canonical domain info to agreement class
Because we alias domains (eg `foo.gsi.gov.uk` to `foo.gov.uk`, or where
a local council has multiple domains) it could be hard to look up a
brand (which has one domain field).

Therefore we need a way of getting the canonical domain from a user’s
email address, which we can later use to look up their branding.
2018-09-05 10:32:43 +01:00
Chris Hill-Scott
ed9444b436 Fix org info in branding requests with known orgs
This wasn’t looking quite right in the case where an organisation is in
our list of domains.
2018-07-10 17:18:50 +01:00
Chris Hill-Scott
949bf6feea Add organisation info to branding requests
This will let us know which organisation the person asking for the
branding is from. This should reduce how often we have to go back to
them and ask.
2018-07-10 16:34:44 +01:00
Chris Hill-Scott
060b93c4d4 Check that all domains in our lists are valid
Since we have too many to add individual tests every time we add a new
one now.
2018-05-08 15:25:41 +01:00
Leo Hemsted
be038e345d define isort first party (app and tests)
we were seeing isort produce different outputs locally and in docker -
this was due to it having different opinions about whether the tests
module (ie all our unit tests) is a first party (local) or third party
(pip installed) import. It's a first party import, so by defining this
in the setup.cfg isort settings, we can force it to be consistent
between environments.

Note: I don't know why it was different in the first place though
2018-04-25 14:12:58 +01:00
Leo Hemsted
df30562216 fix relative datetime function to handle dates correctly
Previously, we were looking at the day of the week - so messages sent
six days ago would show up as "tomorrow". We now look at the actual
date, so that won't happen again.

We were also subtracting an hour to make 00:00 this evening show up as
"midnight today", despite it technically being tomorrow. However, this
means that 00:59 tomorrow morning would show up as "00:59 today", a
full day out. So reduce that to just a minute, so it doesn't affect
other times of day.
2018-03-21 16:08:09 +00:00
Chris Hill-Scott
056c4ebb88 Rename GovernmentDomain to AgreementInfo
This better describes the data encapsulated by this class, and how we
are now using it.
2018-03-15 10:45:34 +00:00