Commit Graph

67 Commits

Author SHA1 Message Date
Katie Smith
18e4e86565 Stop checking query string for filename if uploading contact list
The code was looking for `original_file_name` in the metadata for a
contact list, or the query string if it wasn't in the metadata. Now that
the change to use the metadata for the file name has been deployed for a
while e can stop looking in the query string for the
`original_file_name`.
2020-11-05 10:03:21 +00:00
Katie Smith
e07651ed80 Use metadata to store filename when uploading contact list
We were passing `original_file_name` from the `.upload_contact_list`
view function to the `.check_contact_list` view function as a query
param. We now store it in the metadata instead. `.check_contact_list`
still checks for `original_file_name` in the query string if it's not in
the metadata - this is necessary until the code has been deployed for a
few days and we can be sure that there are no contact lists that are
mid-way through the upload stage.
2020-10-29 13:53:50 +00:00
Chris Hill-Scott
f549168b5e Remove the upload_letters permission
Every service has it now, and we haven’t had any services ask to toggle
it off again.
2020-10-20 11:30:08 +01:00
Leo Hemsted
d86070a7e8 redirect from upload preview to notifications if it already exists
the upload preview page has a file_id - this corresponds to the file in
the transient pdf uploads bucket. However, if the user already hit send
(and then navigated back) the file's no longer in that bcuket, it's been
moved to the regular letters-pdf bucket. So the s3 get request fails. To
avoid this, simply redirect to the notifications page if the file isn't
in the transient bucket. This is better for the user as it'll stop them
trying to submit it twice, and will provide more clarity on the status
of the notification too.
2020-05-26 14:07:47 +01:00
Chris Hill-Scott
04ce13ebfc Remove default argument for file_id
It’s always provided now.
2020-05-22 14:50:33 +01:00
Chris Hill-Scott
782f43059d Refactor to pass through whole postal address
It’s a bit cleaner to not be passing through multiple variables which
are properties of the same object.
2020-05-21 14:20:19 +01:00
Chris Hill-Scott
b2ad7ff3cb Replace format_recipient with PostalAddress.as_single_line
We’ve refactored the code to display an address on a single line with
commas into utils now.
2020-05-21 14:20:18 +01:00
Chris Hill-Scott
68191a93ef Don’t show postage choice for international letters
International letters don’t have a choice of postage. Under the hood
they are either `europe` or `rest-of-world`.

So, for letters that we detect are international, this commit:
- removes the radios buttons that give users the choice of postage
- passes through either `europe` or `rest-of-world` to the API,
  depending on what address we find in the letter

This will cause the API to 500 until it can accept `europe` or
`rest-of-world` as postage types, but this is probably OK because it’s
only our services that have international letters switched on at the
moment.
2020-05-21 14:20:18 +01:00
Chris Hill-Scott
08a701b70c Refactor to get metadata before validating form
Because we no longer need the form to get the `file_id`, we can get the
metadata before building the form.

This will, in subsequent commits, let us build the form differently
based on the recipient metadata.

Also removed some variables that were assigned to then only used once
and reformatted arguments for readability.
2020-05-21 14:20:18 +01:00
Chris Hill-Scott
3378dfe258 Remove letter sending route without file_id
All instances of the app will be posting to the URL with the `file_id`
parameter now, so we can remove the old route without the ID now.
2020-05-21 14:20:18 +01:00
Chris Hill-Scott
1c5e661264 Accept file id in URL, not as form parameter
In the future we need to get the metadata from the file in order to work
out what form validation rules should apply (postage is only required
for UK letters).

To start doing this we need all instances of the app accepting `post`
requests with the `file_id` in the URL, as well as in the form data (for
backwards compatibility).
2020-05-19 17:44:39 +01:00
David McDonald
84dedb9cae Merge pull request #3450 from alphagov/non-ascii-metadata
Non ascii metadata
2020-05-19 11:31:26 +01:00
David McDonald
387fcfda3f Move recipient decoding into LetterMetadata class
This is for consistency with how we do it for filenames in the previous
commit and moves the decoding into the `LetterMetadata` class for
abstracting this behaviour.

Small refactor of the LetterMetadata class needed to handle None case as
recipient can be None.
2020-05-18 16:13:31 +01:00
Chris Hill-Scott
a9998958b7 Link back to uploaded letters page
If you’ve come to look at a notification via the uploaded letters page
then the ‘< back’ link should take you back there, not to the usual
activity page.
2020-05-11 14:30:14 +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
Chris Hill-Scott
2800b0a0c3 Add page to show all uploaded letters
Because we won’t be showing uploaded letters individually on the uploads
page any more we need a way of listing them. This should be by printing
day, to match how we’re grouping them on the uploads page.

This code reuses the notifications.html template, but flips the
precedence of the filename and recipient because I reckon when you’re
looking at uploads you’re thinking filename-first.
2020-05-11 14:27:43 +01:00
Chris Hill-Scott
53724dacd1 Tell template preview whether a letter can be sent internationally
If a service has permission to send international letters then the admin
app should tell template preview, so that template preview knows what
rules to apply when it’s validating the address of the letter.

We don’t need to wait for template preview to start looking at this
query string argument – it will just ignore it for now.
2020-05-01 15:43:54 +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
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
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
Chris Hill-Scott
b5d279e890 Redirect to uploads after save contact list
The saved uploads page just shows you the same thing you’ve seen on the
previous page – a list of email addresses.

It’s more useful to see the uploads page, so you can see where the thing
you’ve saved has gone. You can see it more in context.
2020-03-16 17:56:20 +00:00
Chris Hill-Scott
00f953de6d Give Flask bytes to send, not string
For some reason this passed the tests, but didn’t work running locally.
2020-03-16 13:48:44 +00:00
Chris Hill-Scott
050f98fea6 Show contact lists on the uploads page
Uploads page is where all the stuff you’ve uploaded lives. Now you can
upload contact lists they should live here too.

They always come first because they’re the most-removed from stuff
you’ve sent.
2020-03-16 13:09:16 +00:00
Chris Hill-Scott
b598af1eca Add an endpoint to download a contact list
In case you need to download it, modify it, and re-upload it when you
don’t have access to the existing list.
2020-03-16 13:08:46 +00:00
Chris Hill-Scott
aa85870ee1 Add a page to view a single contact list 2020-03-16 13:08:00 +00:00
Chris Hill-Scott
f15b9b8d38 Rename URL for consistency
We say `…/upload-letter` not `…/upload-a-letter`
2020-03-16 13:07:53 +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
Chris Hill-Scott
1c02476ee7 Let users upload a contact list to use later
We increasingly have teams wanting to do business-continuity type
messaging. They might be without access to their normal systems, which
is where they would otherwise go to get the list of email addresses or
phone numbers.

So we want to give them a place in Notify where they can store their
spreadsheets and use them at a later date.

For the initial pass we’re going to scope this to only allowing
spreadsheets with one column, ie just phone numbers/email addresses.
This is because:
- it minimises the amount of personal info we’re storing
- it reduces the chance of getting a placeholder error when you go to
  send the message, which is probably a high-stress situation where you
  might not be able to re-generate the file

The code for this is mostly copied from the existing upload CSV journey.
It’s quite duplicative, but that’s what I needed to do to get this out
quickly. There are opportunities for refactoring later.

Similarly, I would have liked to split this up into better commit
messages, but it really was a case of just bashing code out until it
worked 😳

This commit does not:
- implement the ‘view a contact list page’ (it just has a placeholder
  because the API isn’t ready at the moment)
- link to this page (because it’s not ready to use yet)
2020-03-16 13:07:28 +00:00
Chris Hill-Scott
63f704c64f Fix accidental switch of previous and next
We were showing the previous page link when we meant to show the next
page link because the variables were swapped round in the code.
2020-02-27 17:51:01 +00:00
Chris Hill-Scott
eed5e0fdd7 Combine scheduled and already-sent jobs
I’m hoping that if I can design something that clearly differentiates
them then we won’t need to do so by putting them in separate tables,
which then need labelling, which would clutter up the page.
2020-02-27 17:33:41 +00:00
Chris Hill-Scott
3dab9c2915 Refactor to make it logic clearer
The logic around what gets shown on the uploads page was hard to follow.
This commit makes three changes to hopefully make it easier:
- remove the passing-around of a string containing the contents of a
  rendered partial
- encapsulate everything in one `show_scheduled_jobs` variable, rather
  than mixing between `scheduled_jobs` and
  `current_service.scheduled_jobs`
- adds a comment to explain why we still render `_jobs.html` even when
  we know we have no jobs
2020-02-24 16:38:09 +00:00
Chris Hill-Scott
c20ec82cd2 Show scheduled jobs on page one of the uploads page
This is the same thing we do for caseworking users who don’t have the
dashboard. Since we’re going to summarise scheduled jobs on the
dashboard instead of listing them they need to be listed here instead
(which is where we’ll link to from the dashboard).

Design of this will probably evolve as we work out how to style single
letter uploads and letter jobs, but that’s OK for now because no-one
has the uploads page at the moment.
2020-02-24 16:38:07 +00:00
Leo Hemsted
d83250c7c2 remove the generic 400 error page handler
it just shows a h1, so isn't helpful for people. We can re-use the 500
error page, which includes instructings "Try again later" and
instructions on what to do next (check the status page, email notify
support).

this required refactoring to ensure we can show the 500 error page while
still returning the required status code
2020-02-21 11:58:37 +00:00
Chris Hill-Scott
721134dc17 Merge pull request #3251 from alphagov/job-model
Make models for individual jobs and collections of jobs
2020-01-16 15:52:21 +00:00
Chris Hill-Scott
e9ad2e9c42 Only put the overlay on bad pages
This will make it easier to find errors in your file, because you won’t
spent time looking for them on pages which are OK.
2020-01-13 17:42:44 +00:00
Chris Hill-Scott
25464a141b Use a ModelList for lists of jobs
This follows the pattern of what we’ve done with services, users and
events.

It gives us a way of neatly instantiating a model for each item in the
list we get back from the API and reduces the complexity of the view
layer code.

Now is a good time to do this because we’re going to be making a bunch
of changes to the jobs pages, and those changes will be easier to code
and understand with a sensible model behind them.
2020-01-13 15:10:10 +00:00
Rebecca Law
9d1f92a752 Strip the trailing comma on the first line of an address block. 2020-01-10 16:06:04 +00:00
Rebecca Law
f8e7635a1d Show the first line of the address from the to field.
Now persisting the address to the "to" field of the Notification, after the notification has been validated.
If the letter is pending validation, then "Checking..." will appear as the identifier for the letter.
If the letter has passed validation, then the first line of the address (now persisted in the "to" field) will be displayed, with the client reference underneath.
If the letter has failed validation the "Provided as PDF" will show be displayed, which is now the initial value of the "to" field.
2020-01-10 16:00:40 +00:00
David McDonald
0a66ad0b72 Merge pull request #3219 from alphagov/add-letters-to-uploads-page
Updated the uploads page to include letters.
2019-12-06 15:01:09 +00:00
Rebecca Law
673a0d64d0 Refactor mock_get_uploads to return more realistic data. 2019-12-06 13:22:25 +00:00
Rebecca Law
f9e01e0b45 Fix unit tests and put the antivirus check back in 2019-12-06 10:22:23 +00:00
Rebecca Law
833a5cad8f Updated the uploads page to include letters. Now the page shows uploaded letters plus jobs.
New units tests have not been written for this page because it is very like this will be refactor and probably a new template created for the page. Some design needs to go into this page.
But we needed something ready for user research.
2019-12-05 16:14:30 +00:00
David McDonald
ff9f12c4a7 Antivirus off for development by default
I have copied the approach we use in the API for this
2019-12-05 11:18:48 +00:00
Pea Tyczynska
02beccd066 Add re-upload button and back link to the preview page
Re-upload button is only shown if file failed validation.

Change wording of re-upload buttons

Make test we test right buttons on letter upload preview page

Also remove double backlink
2019-11-27 15:11:14 +00:00
Chris Hill-Scott
24dc438446 Merge pull request #3176 from alphagov/require-uuids-in-urls
Be stricter about the format of URL parameters
2019-11-13 10:33:31 +00:00
Katie Smith
a542047581 Show recipient when about to send uploaded letter
The recipient of the letter now displays at the bottom of the page when
previewing a valid letter. The template preview `/precompiled/sanitise`
endpoint returns the address, but we format it to display on a single
line with commas between each line. We also need to convert the
recipient address to ASCII so that it can be stored as S3 metadata.
2019-11-08 10:17:11 +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
Pea Tyczynska
5e10ed23a1 Refactor uploads preview error banner to use a shared component
Also refactor a corresponding test to avoid asserting on the content
2019-11-06 14:26:14 +00:00
David McDonald
159d2ff6b2 Add form.validate_on_submit for sending uploaded letter
Decided it was better to call this then not. This does rely on
the file_id not being corrupted so the file_id passed
into `uploaded_letter_preview` is valid but am taking that risk
given it should only change if a user is changing the form html.
2019-11-01 10:56:34 +00:00
David McDonald
4ddc82d148 Access request values from form object 2019-11-01 10:47:42 +00:00