Commit Graph

103 Commits

Author SHA1 Message Date
Andrew Shumway
a401562735 Add report options 1/3/5-day 2024-06-10 10:15:22 -06:00
Kenneth Kehl
802ebfa243 use sent_at instead of updated_at 2024-02-02 08:31:05 -08:00
Kenneth Kehl
fd8981d5cd add timezone to file name 2024-01-24 11:59:31 -08:00
Kenneth Kehl
2126ba8038 fix name of download file 2024-01-24 11:54:25 -08:00
Kenneth Kehl
94b86f1afc fix tests 2023-12-15 10:29:42 -08:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
stvnrlly
944715ac46 big commit with letters removal 2022-12-05 15:33:44 -05:00
stvnrlly
e12e780a05 code cleanup 2022-11-28 15:53:56 -05:00
stvnrlly
a2b58c926e more test fixes & letter trimming 2022-11-22 22:50:47 -05:00
stvnrlly
ca1897973a test time fixes and bonus letter removal 2022-11-22 17:03:42 -05:00
Chris Hill-Scott
2a62586799 Reflect change in argument name
`filename_or_fp` was changed to `path_or_file` here:
https://github.com/pallets/flask/pull/3828/files#diff-1f51c8ded4d4ff7e13badab599ef22436c529c2b5f9c25dc6250c1f9fd985440R479
2022-06-06 12:12:52 +01:00
Ben Thorner
ee3d2d1804 Bump utils to version 56.0.0
The only impactful change is the major version itself, where I've
fixed the breaking changes due to the upgrade of PyPDF2 [^1] and
checked there are no deprecation warnings when I run the tests.

[^1]: https://github.com/alphagov/notifications-utils/pull/973
2022-06-01 13:29:54 +01:00
Rebecca Law
49138946ac Update comment to help clarify the decision for this approach to showing
letters that are too long.
2022-02-01 13:20:25 +00:00
Rebecca Law
fc8c536fa7 Show validation error message for a templated letter over 10 pages
If a letters that has been posted via the API has more than 10 pages it would not get a validation-failed status. This also happens for letters in a CSV upload, only the first row has been validated for having too many pages, because you need to created the pdf before getting an accurate page count.

The API has been updated to mark these letters as invalid and move the
letter to the invalid s3 bucket, the meta data is also set with the
error message and page count.

This PR updates the notification page to display the validation error.

https://www.pivotaltracker.com/story/show/169209742
2022-01-04 12:42:35 +00:00
Pea Tyczynska
e1420e7ff7 Catch cancel_letter errors from API
When we catch such error, if the message is recognised,
show the message and redirect user to view_notification page.
2021-07-28 12:55:06 +01:00
Ben Thorner
0326005aeb Extract template / csv utility code into modules
This follows a similar approach to the previous commits, noting that
one module depends on the other, so we have to extract both together.
2021-06-09 15:19:00 +01:00
Ben Thorner
2a4aa8b4e1 Extract letter utility code into own module
This provides more room for expansion, and reduces the amount of
arbitrary code in the __init__.py file for the new package.
2021-06-09 13:59:06 +01:00
Ben Thorner
7c27646d6a Extract user utility code into own module
This provides more room for expansion, and reduces the amount of
arbitrary code in the __init__.py file for the new package.
2021-06-09 13:19:05 +01:00
Leo Hemsted
087f908968 allow caseworkers to view letter previews
they can already view notifications page, but the png and pdf letter
previews just 403 for them currently.
2021-02-23 16:08:03 +00:00
Ben Thorner
933d5bf68e Show 'From' / 'Reply To' if set for notification
Previously when a service had multiple "reply to" entries setup for
email or SMS, we would show the one that was selected on all screens
[1][2] except the final one, where the notification is actually sent.
This fixes that, with the caveat that it will also show for services
with only one "reply to" entry (see notes below) - we will look at
making this consistent on the previous screens in the next commit.

Here's a bit more detail on how this works:

- If a service has multiple "reply to" entries, the journey to send a
  one-off message starts with a screen to select the "sender_id", which
  is otherwise "None" [3].

- The "sender_id" is subsequently resolved to an actual email / phone
  number by calling an API [4] and plucking it out of the response JSON.

- The email / phone number then get rendered as part of the preview
  template [5][6].

- Unfortunately the "sender_id" is removed from the session by the time
  we get to the "view_notification" view [7].

- However, we can get back the equivalent text from the notification
  JSON, which is set by the API when the notification is created [8],
  give or take a bit of validation code [9][10].

- But the "reply_to_text" field is also set by the API when the service
  only has one "reply to" entry, so it will show then as well.

We could add look at the number of "reply to" entries for the service,
in order to consistently only show it when there is more the one. But
it seems more useful to show it on previous screens, since it provides
more information than is currently show (esp. for emails).

[1]: 93226ec5d6/app/main/views/send.py (L441-L442)
[2]: 93226ec5d6/app/main/views/send.py (L966-L967)
[3]: 93226ec5d6/app/main/views/send.py (L247)
[4]: 93226ec5d6/app/main/views/send.py (L1071-L1082)
[5]: 93226ec5d6/app/templates/views/notifications/notification.html (L80)
[6]: https://github.com/alphagov/notifications-utils/blob/master/notifications_utils/jinja_templates/sms_preview_template.jinja2
[7]: 93226ec5d6/app/main/views/send.py (L1059)
[8]: f8b4c9151c/app/service/send_notification.py (L87-L93)
[9]: f8b4c9151c/app/models.py (L653)
[10]: https://github.com/alphagov/notifications-utils/blob/master/notifications_utils/recipients.py#L482
2021-02-10 10:43:27 +00:00
Chris Hill-Scott
d828c1c481 Bump utils to 39.4.0
Adds delivery estimates for letters posted to Europe or the rest of the
world.
2020-05-26 13:37:03 +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
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
Chris Hill-Scott
b236df523c Don’t show the postage when validation has failed
The postage covers up some of the letter, so it can hide the problem. It
also implies that the letter has been put in an envelope, which will
never happen if it fails validation.

This matches what we do for uploaded letters.
2020-03-03 12:57:43 +00:00
Chris Hill-Scott
545b485d86 Add URL converters for template and file types
Sometimes we manually check that a URL parameter is in a required set.
Sometimes we don’t bother.

This commit adds a URL converter to do this so that:
- we don’t have to re-write the same code every time
- it’s easier to apply this check to other endpoints

This means endpoints that previously allowed a `template_type` or
`message_type` of `None` now 404. So I’ve had to add new routes for
with URLs that don’t include such parameters.

So this…:
```
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/sms.csv
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/None.csv
```

…becomes:
```
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications/sms.csv
/services/128b91b6-2996-4107-bb65-51b7c24a728d/notifications.csv
```

This matches what we do for the HTML-responding equivalent (see
265931d217/app/main/views/jobs.py (L215-L216))
2019-11-07 13:48:09 +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
678e0bed81 Show users more detailed validation failed mesage on notification page
Show valdiation failed messages on letter notifications in red text,
not in the banner like we do on Uploads and Validation checker pages.
This is because it is a different step in the journey: the user
has already sent the notification and styling needs to be in line
with other places where user is checking the notification she already
has sent.
2019-11-07 11:10:27 +00: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
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
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
Chris Hill-Scott
3da9e84ece Enforce order of permissions decorators
At the moment we mostly have `user_has_permissions` execute first. It
shouldn’t matter, but it feels right for us to check that a user is
logged in before we check their permissions to a service. Otherwise a
malicious user could (maybe) check if a service ID belongs to a real
service, and go on to do something malicious with that information.

This commit adds some extra test code to enforce that the order is
always the same.

N.B. decorators in Python execute from closest to furthest (from the
line on which the function is defined).
2019-07-03 09:54:17 +01:00
Chris Hill-Scott
91f2da8b68 Ensure all service route have permission decorators
We accidentally miss these sometimes. This code adds a test which
inspects the code to automatically check that any function which:
- handles a route
- accepts a service_id

For each function it checks that each of these routes have the
permissions decorator we’d expect.

Most of the introspection/AST code is adapted from here:
https://mvdwoord.github.io/exploration/2017/08/18/ast_explore.html
2019-07-03 09:47:20 +01:00
Chris Hill-Scott
c6b21ab022 Hide back link when you’ve just sent a message
Changed this yesterday. Changing it again now because I think it’s
confusing.

There’s really no going ‘back’ once you’ve sent a message – you can’t
undo it. If you want to get back to the template you used, well, that
link is in the page.

This commit changes the back link logic so it only appears when you’ve
navigated to a notification, not when you’ve just sent it.
2019-06-07 16:16:13 +01:00
Chris Hill-Scott
48eb698713 Fix back link on ‘sent’ page in tour
If the user wants to go back from here they need to be sent back to the
start of entering the placeholders, because we won’t have their previous
personalisation in the session still

I think the back link on this page was introduced by accident. But it’s
good to still have it on this page, because it keeps consistency with
the previous pages.
2019-06-06 12:00:23 +01:00
Chris Hill-Scott
4fc7498415 Include status when linking to notifications page
Without this argument the 'sending' filter doesn’t get highlighted by
default.
2019-05-15 10:04:43 +01:00
Chris Hill-Scott
b4894e7a03 Always go back to previous page from notification
When looking at a notification you can either be coming from the page
of all notifications, or from a job. Currently the back link always
takes you to the page of all notifications.

This commit makes it a bit more sophisticated so if you’ve come from
looking at a job, you go back to the job.
2019-05-09 17:33:22 +01:00
karlchillmaid
b7c955c010 Make the formatting of postage times consistent 2019-04-16 10:39:50 +01:00
Pea Tyczynska
e0b61e3d70 Call precompiled letter preview with overlay 2019-04-04 12:05:17 +01:00
Chris Hill-Scott
cd70355db8 Display postage everywhere we display a letter
To avoid the problem of having confusing defaults, the postage is now
set explicitly on every template.

Putting the postage ‘inside’ the letter template makes the interaction
for changing it consistent with how other parts of the template are
added.

Plus everyone loves skeumorphism.
2019-02-06 14:37:16 +00:00
Chris Hill-Scott
cfcdfcc38c Show if letters are sent using a test key
It’s inaccurate to have an estimated delivery date for letters sent
using a test key. We shouldn’t reassure people that:
- the letter won’t be printed
- (in the case of precompiled letters) that the letter has passed
  validation
2019-01-22 09:54:40 +00:00
Katie Smith
da50f77538 Show error message if precompiled PDF cannot be opened
If PDF files have a validation error which means that they can't be
opened by PyPDF2 we would previously show the 500 status error page. We
now catch PyPDF2.utils.PdfReadErrors so that we can display a custom
error message on the notification page instead.
2019-01-09 13:10:36 +00:00
Katie Smith
5406efa0cc Add link to cancel letters
Added a link to cancel letters from the letter notification pages if the
letter is still able to be cancelled. Clicking on this link will show a
confirmation box, and will then cancel the letter if the user confirms.
2018-12-05 11:12:05 +00:00
Alexey Bezhan
b787ca6e5b Add Service.get_days_of_retention helper method
Data retention lookup by type is only performed to get the number
of days, so we can update the service method to return the number
or the default directly.
2018-12-03 18:04:58 +00:00
Alexey Bezhan
7a7a9ae854 Cache service data retention in Redis
Adds caching for service data retention. This removes separate API
client methods to retrieve individual data retention records by id
or type in favor of a single method that fetches and caches all
retention settings configured for the service. This makes it much
easier to invalidate cache when settings change.

Lookup by id or type is provided by helper methods in the service
model.
2018-12-03 17:57:02 +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
c7118a80e2 Stick email status to bottom of screen
We’ve moved away from using the expand/collapse pattern on the page
where you click ‘send’. Instead we’re putting the send button in the
sticky footer.

So it’s a bit jarring to still have the expand/collapse on the page you
see after you’ve sent an email. This commit replaces it with the sticky
footer as well.

This is only relevant for emails because:

1. Text messages are generally short enough to fit on the screen
2. We don’t show the status of letters because they don’t really change
2018-11-22 10:20:39 +00:00
Chris Hill-Scott
39c51dd994 Show all letter pages on the notification page
Sometimes a long placeholder can push stuff onto a new page, so we need
to take the personalisation into account when counting pages.
2018-11-02 14:30:18 +00:00
Chris Hill-Scott
c01d761a3c Show if a letter has been cancelled
At the moment we are manually cancelling letters for people when they
ask us to. Once’s we’ve done this there is no indication that it’s
happened except for the date going red on the list of letters.

This commit adds some error messaging and styling to show when a letter
is cancelled.

Letting people cancel their own letters will be a future enhancement.
2018-10-29 11:51:41 +00:00
Leo Hemsted
432f1286fe update notifications page to take into account first class! 2018-10-01 11:07:35 +01: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