Commit Graph

244 Commits

Author SHA1 Message Date
Tom Byers
67392e97ee Fix issue with looping in list merging
The last_dest_idx variable should always have been
tracking the last index in the source list. The
original intention, implemented incorrectly, was
to just append any items which source has no item
at that index.
2021-01-26 12:16:08 +00:00
Tom Byers
23d391e3fc Change how merge_jsonlike treats lists
Current behaviour is to check item-against-item
and merge based on whether items match, irrelevant
of position. This doesn't produce the results we
need for our usecases (merging data to send to
GOVUK Frontend components).

We actually want:
- items to be compared based on their position
- new primitive items at the same position to
  overwrite existing ones
- dicts or lists at the same position to be merged

For example,

Starting with this list:

[{"name": "option-1", "value": "1"}]

Merging in this list:

[{"hint": {"text": "Choose one option"}}]

You currently get this:

[
  {"name": "option-1", "value": "1"},
  {"hint": {"text": "Choose one option"}}
]

We want to get this:

[
  {
    "name": "option-1", "value": "1",
    "hint": {"text": "Choose one option"}
  }
]
2021-01-21 21:15:51 +00:00
Chris Hill-Scott
7a95e1618e Extract formatters into their own module
We have lots of functions for converting various types of data into
strings to be displayed to the user somewhere.

This commit collects all these functions into their own module, rather
than having them cluttering up `app/__init__.py` or buried amongst
various other things that have ended up in `app/utils.py`.
2021-01-07 11:57:30 +00:00
Chris Hill-Scott
2c46d023da Extract Spreadsheet model from app/utils.py
`app/utils.py` is a bit of a dumping ground for things we don’t have a
better place for.

We now have a place and structure for storing ‘model’ code (‘model’ in
the model, view, controller (MVC) sense of the word).

This commit moves the spreadsheet model to that place.
2021-01-06 12:31:39 +00:00
Tom Byers
55a4ca6579 Remove set-to-string conversion from upload code
Also changes the allowed_spreadsheet_file_extensions
variable to allowed_file_extensions for
consistency.
2020-12-17 13:04:27 +00:00
Tom Byers
e9722256ea Rename Spreadsheet.allowed_file_extensions
We will use this list in various views, to send
them through to the file_upload component.

These changes make it:
- into a Set so it can't be altered
- uppercase to show it is a constant
2020-12-16 14:48:10 +00:00
Chris Hill-Scott
9c5dceaf81 Ensure test data uses timezone aware timestamps
This reflects what the API sends us, and means we have to do less
timezone-wrangling.
2020-10-06 11:34:08 +01:00
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
a384f4cace Add route for letter specification page 2020-09-22 15:36:20 +01:00
karlchillmaid
4616349b16 Add note 2020-09-21 16:41:02 +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
ba9f786971 Move round_to_significant_figures into utils 2020-09-17 11:03:14 +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 M. Tyczynska
9b69d16963 Merge pull request #3554 from alphagov/convert-single-line-textboxes-to-govuk-frontend
Convert single line textboxes to govuk frontend
2020-08-18 11:29:44 +01:00
Pea Tyczynska
36c1ffa7be New template button takes user to new template page
for all services that only allow sending one type of notifications
2020-08-14 17:15:45 +01:00
Pea Tyczynska
67da2c28bf Deep merge jsonlike objects
Also remove duplicate checkboxes code
2020-08-14 14:58:05 +01:00
Leo Hemsted
867ef30d18 add err msgs for letters with notify tags on pages 2+ 2020-07-31 18:31:26 +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
98eb3c61f6 Merge pull request #3498 from alphagov/add-broadcast-template
Allow adding broadcast templates
2020-07-06 09:06:16 +01:00
Chris Hill-Scott
dd2b737d24 Use service_has_permission decorator on inbox
This proves that the decorator works, because the inbox code is already
tested:
bad1e69cc3/tests/app/main/views/test_dashboard.py (L353-L367)
2020-07-03 10:12:55 +01:00
Chris Hill-Scott
d4627a2f3a Add service_has_permission decorator
Similar to how we can restrict routes to only users with a given
permission, this new decorator lets us restrict routes to services that
have a given permission.

Having this is a decorator is cleaner than putting if statements inside
the endpoint code.
2020-07-03 09:56:11 +01:00
Chris Hill-Scott
724e8d1838 Make it possible to preview a broadcast template
At the moment this won’t look like much, but it will let us do an
end-to-end run of adding a broadcast template.

At the moment all you can do with a broadcast template is edit it, so
there’s no ‘Send’ link on the page.
2020-07-01 17:49:55 +01:00
Chris Hill-Scott
154d4bdb85 Allow adding broadcast templates
At the moment the page is the same as for text message templates,
except:
- different H1
- no guidance about personalisation, links, etc (until we decide how
  these should work)

For now you won’t be able to really create a broadcast template, because
the API doesn’t support it (the API will respond with a 400). But that’s
OK because no real services have the broadcast permission yet.

This required a bit of refactoring of how we check which template types
a service can use, because there were some hard-coded assumptions about
emails and text messages.
2020-07-01 17:17:46 +01:00
Chris Hill-Scott
978ebcbe9b Send HTTP header as well as inserting meta tag
This will let us use the decorator on endpoints that don’t return HTML.
2020-05-27 10:32:06 +01:00
Chris Hill-Scott
92ffe3a78c Use meta tag to tell search engines not to index
Google’s documentation says:

> robots.txt is not a mechanism for keeping a web page out of Google. To
> keep a web page out of Google, you should use noindex directives

A noindex directive means adding the following meta tag to pages that
shouldn’t be indexed:
```html
<meta name="robots" content="noindex" />
```

It’s also possible to set the directive as a HTTP header, but this seems
trickier to achieve on a per-view basis in Flask.

I’ve implemented this as a decorator so it can quickly be added to any
other pages that we decide shouldn’t appear in search results.
2020-05-27 10:19:48 +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
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
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
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
03f2368deb Use the correct bucket for storing contact lists
We don’t want to muddy them up with the normal CSV uploads.

I’ve tried to reuse the existing S3 code where possible because it’s
well tested.

Buckets have already been created.
2020-03-16 13:07:39 +00:00
Tom Byers
e6767c4d01 Make links in validation summaries red 2020-02-25 15:32:31 +00:00
Tom Byers
9f2e1498fc Update links missed in previous work
Includes those in:
- the static 5xx error page
- validation messaging
- guidance page about trial mode
- links used in tests

Issues raised in https://github.com/alphagov/notifications-admin/pull/3303#issuecomment-589572715
2020-02-25 10:52:03 +00:00
Tom Byers
5b306dde4d Revert "Convert all links to govuk frontend" 2020-02-24 11:56:38 +00:00
Tom Byers
f90b6b46e6 Make links in validation summaries red 2020-02-21 15:50:28 +00:00
Tom Byers
1513cfa9e6 Update links missed in previous work
Includes those in:
- the static 5xx error page
- validation messaging
- guidance page about trial mode
- links used in tests

Issues raised in https://github.com/alphagov/notifications-admin/pull/3303#issuecomment-589572715
2020-02-21 13:59:04 +00: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
karlchillmaid
10e0c39001 Add reference for letter_spec_guidance 2020-02-13 15:53:03 +00:00
karlchillmaid
8a0a9666d7 Update links 2020-02-13 15:50:22 +00:00
karlchillmaid
fadf29c9b0 Fix API validation error summary links 2020-02-13 15:08:40 +00:00
karlchillmaid
90462d7c71 Update link to Letter specification guidance 2020-02-13 14:58:53 +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