Commit Graph

317 Commits

Author SHA1 Message Date
Katie Smith
247e7c2d93 Stop checking query string for filename when sending a job
We look for `original_file_name` in the metadata now. Initially we were
still checking the query string too, but now that the change to add the
filename to the metadata has been deployed for a while there shouldn't
be any cases of the filename still being in a query string.

Since the `original_file_name` is not being added to the metadata in
`.check_messages` (it has happened earlier in the process) a few tests
are no longer needed.
2020-11-05 10:03:21 +00:00
Katie Smith
6940291c96 Put filename in metadata when sending via a CSV
When sending from an uploaded CSV `.send_messages` now puts the filename
in the metadata. It previously used the query string to pass the
filename to `.check_messages`, where it can be lost.
2020-10-29 13:53:50 +00:00
Katie Smith
a6c103841e Check metadata for file name when sending from contact list
The `.send_from_contact_list` function redirected to `.check_messages`
with `original_file_name` in the query string. Contact lists already
have `original_file_name` as part of their metadata, so we can stop
sending it in the query string and use the metadata instead.
2020-10-29 13:53:50 +00:00
David McDonald
7d3a4e6085 Remove test/step- routes
We don't need these anymore as all users will use the `one-off/step`
routes.

This has mostly involved tidying up the tests which are still a little
disorganised and not as good as I'd like but it's a step in the right
direction.

More refactoring is still possible to the routes, it may come in a later
PR if I have time.
2020-10-09 17:36:09 +01:00
David McDonald
4aaf47aaa1 When sending to yourself use 'one-off' rather than 'test' routes
There is no real reason to have to support both 'one-off' steps and also
'test' steps when sending a one off notification. It's a lot of complex
code, just to now set the one of the placeholders in the session.

We make our code much simpler but no longer using the 'test' routes but
instead adding a new endpoint to set the notification recipient when
sending to yourself before continuing on with the rest of the 'one-off'
flow.

After this is deployed for a day then we can completely remove the
'test' routes and this will help remove a lot of code complexity.
2020-10-05 16:20:04 +01:00
David McDonald
389638244c Remove old tour and help arguments from sending flow
We no longer need the `start_tour` page as this has been replaced with
the new `begin_tour` page.

We also no longer need to handle the `help` argument in the
`send_test_step` or `send_one_off_step` as these no longer are
responsible for the tour and don't need to show the help text.

Worth pointing out, the new tour joins into the send one off flow. When
doing a GET `check_tour_notification`, and submitting the form shown on
this page you are POSTed to `send_notification` with `help=3`. Also for
general sending of one off notifications, the POST to
`send_notification` is done with `help=0` which is a bit of a hack to
make sure that we don't show a back link on the `view_notification` page
for when someone gets there having just sent a one off notification.
This use of `help=0` may be a candidate for a refactor in the future as
it feels like a bit of a hacky way of doing things and is therefore not
as clear to developers what is going on.

Also removes the help argument from the csv routes used here. There is
no reason that we need to ever show help for CSVs and this is leftover
code from when we used to do the tour that way.
2020-10-05 12:44:19 +01:00
Chris Hill-Scott
0459e26be9 Show address line 7 not postcode in example spreadsheet
Since the letter preview will now show address line 7, the example
spreadsheet we give should match.
2020-09-07 12:00:27 +01:00
Katie Smith
716977fe75 Include template values when calculating letter page count
When sending a letter we check how many pages it has and this number
then determines how many PNG images we ask template preview for. When
calculating the page count, we were getting the page count for the
template as it comes from the database (so without any placeholders
filled in). But filling in placeholders in a letter may cause the number
of pages to change, which was the cause of the 'Letter does not have a
page x' errors we were seeing from template-preview.

Now, when we calculate the letter page count during sending, we take the
placeholders that have already been filled in into account.
2020-07-27 17:22:14 +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
2f79ef136d Don’t cache page count for one off letters
Why we did this originally[1]:

> Calculating the number of pages in a letter is quite slow. And the
> send yourself a test pages need to load _fast_. Since filling in
> placeholders is very unlikely to change the number of pages in the
> resultant letter, it’s pretty safe to cache that count, and makes the
> subsequent pages load a lot faster.

However things have changed since then:
- this journey is used for sending real letters, not just test ones
- we’re doing enough letters that even an unlikely discrepancy will (and
  does) happen
- we cache the generation of the PDF now[2], so at least it’s not
  generating the PDF twice, once for the preview and once for the page
  count
- it’s no longer necessary to step through each address placeholder to
  populate a one-off letter, so a little bit slower isn’t so bad

1. e7896f283a
2. c9c6271aa0/app/preview.py (L140)
2020-05-15 13:55:04 +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
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
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
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
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
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
Chris Hill-Scott
fc58547be3 Tell the API which contact list a job’s come from
So that we can make enhancements to the UI in the future, for example
grouping jobs within their associated contact list.
2020-03-16 17:56:55 +00:00
Chris Hill-Scott
93f862621c Pass original file name when sending contact list
Otherwise the new file doesn’t get a name, which is very confusing.
2020-03-16 13:09:32 +00:00
Chris Hill-Scott
b99216173e Sort contact lists appropriately
On the uploads page this should be newest first, same as the scheduled
and immediate jobs on this page.

On the _choose_ page this should be alphabetical, same as choosing a
template.
2020-03-16 13:09:23 +00:00
Chris Hill-Scott
8ba75cf6ba Warn users trying to use a personalised template
Since contact lists only store the email address or phone number, this
won’t work. So we should warn people, and highlight that the
personalisation in the template is the problem, since this is what they
will need to change.
2020-03-16 13:09:09 +00:00
Chris Hill-Scott
6c2021aeb2 Only show contact lists relevant to template
You can’t send an email message template to a list of phone numbers. So
we shouldn’t show you the lists of phone numbers when you’ve chosen an
email template.
2020-03-16 13:08:53 +00:00
Chris Hill-Scott
e24083ce9d Add a page to choose a contact list
You’ll be able to use a contact list by first choosing a template, then
choosing the list you want to use.

At the moment this shows all lists, not just the ones that are
compatible with your template.
2020-03-16 13:08:07 +00:00
Chris Hill-Scott
460b779d11 Add endpoint to redirect from contact list to send
In order to use a contact list we’re going to put you in the normal
upload a spreadsheet journey. Except without having to upload again.

So this commit adds an endpoint that takes the file from the contact
list bucket, puts it in the same place it would have gone if you’d
uploaded it, then sends you on your way.
2020-03-16 13:07:46 +00: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
Rebecca Law
040da762ed Fix the error message for message-too=long
There was a bug that displayed the error message with 2 red error boxes around the error message.
Also need another else to handle a new error message from the API, the old one can be removed after the API is deployed. But this can go first. I tested this branch with API master and the API branch with the change. I tested one off SMS and a CSV upload.
2020-03-10 09:29:38 +00:00
Leo Hemsted
f3fa6a67e1 fix one more place where senders weren't sanitised
make sure everything is using the `nl2br` formatter that properly wraps
it in markdown to keep everything sanitised nicely. Also write a couple
of tests
2020-01-22 17:22:01 +00:00
Leo Hemsted
3be9150dcf change letter previews to be in the no_cookies blueprint
this blueprint should be applied to every endpoint that is loaded async
(as in via a src tag on an img, iframe, etc)
2019-12-03 17:06:15 +00:00
Pea M. Tyczynska
0d8824c3e9 Merge pull request #3193 from alphagov/validate-against-empty-messages
Validate CSVs against rows with empty messages
2019-12-03 14:12:04 +00:00
Pea Tyczynska
f265dde8ab Validate CSVs against rows with empty messages 2019-12-03 13:36:41 +00:00
Leo Hemsted
6ad9ec8d21 flake8 2019-11-29 15:25:37 +00:00
Chris Hill-Scott
ef335e7601 Require IDs to be UUIDs in URLS
We mostly rely on the API returning a 404 to generate 404s for trying
to get things with non-UUID IDs. This is fine, except our tests often
mock these API calls. So it could look like everything is working fine,
except the thing your passing in might never be a valid UUID, and thus
would 404 in a non-test environment.

So this commit:
1. uses the `uuid` URL converter everywhere there’s something that looks
   like an ID in a URL parameter
2.  adds a test which automates checking for 1.
2019-11-07 13:46:25 +00:00
Chris Hill-Scott
554a852e2d Don’t return UUID objects from the UUID convertor
Because it means you often have to cast to string in your application
code just to get your tests passing.

The method being monkey patched is originally defined here: b81aa0f18c/src/werkzeug/routing.py (L1272)
2019-11-07 13:46:24 +00:00
Pea Tyczynska
4b5a131072 Harmonise content of error message with the document laid out by our content designer 2019-10-16 13:02:11 +01:00
Pea Tyczynska
2ed1e382b4 Move letter length check to utils repo so template-preview can use it, too
Update requirements
2019-10-10 14:25:19 +01:00
Pea Tyczynska
6639209229 Check page count of actual notification not of template
But for jobs we are only checking preview row, otherwise it would
be too slow. We will check other row when creating the pdf
2019-10-09 16:03:48 +01:00
Pea Tyczynska
12ec2870af Move letter too long banner message over from utils, also refactor 2019-10-09 16:03:47 +01:00
Pea Tyczynska
b42c7c4c9f Refactor page_count checks to avoid magic numbers 2019-10-09 16:03:47 +01:00
Pea Tyczynska
028d156dc7 Do not allow to send job of letters if letters longer than 10 pages 2019-10-09 16:03:47 +01:00
Pea Tyczynska
c690434b1f One off letter flow does not allow to send letter longer than 10 pages 2019-10-09 16:03:47 +01:00
karlchillmaid
daf94ddc16 Replace couldn't with could not 2019-09-23 13:22:16 +01:00
karlchillmaid
1a603c8d48 Replace can't with cannot 2019-09-23 13:21:08 +01:00
Chris Hill-Scott
40e020d40d Remove expand_emails argument from get_template
It isn’t used for anything now.
2019-09-02 17:04:53 +01:00
Chris Hill-Scott
b620b677d3 Have permissions decorators check user signed in
Rather than force us to write the decorators in a specific order let’s
just have one decorator call the other. This should make fewer lines of
code, and fewer annoying test failures. It also means that the same way
of raising a `401` (through the `current_app` method) is used
everywhere.
2019-07-03 09:54:35 +01:00