Commit Graph

115 Commits

Author SHA1 Message Date
Steven Reilly
ff4190a8eb Remove letters-related code (#175)
This deletes a big ol' chunk of code related to letters. It's not everything—there are still a few things that might be tied to sms/email—but it's the the heart of letters function. SMS and email function should be untouched by this.

Areas affected:

- Things obviously about letters
- PDF tasks, used for precompiling letters
- Virus scanning, used for those PDFs
- FTP, used to send letters to the printer
- Postage stuff
2023-03-02 20:20:31 -05:00
stvnrlly
57f4df8ed1 remove broadcast-related code, except migrations 2022-10-04 15:28:27 +00:00
Ben Thorner
ee8e86f409 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 14:27:25 +01:00
Katie Smith
8ae2b0bb31 Replace how .dump is called
As with `.load`, only data is now returned instead of a tuple.
2022-05-25 11:35:44 +01:00
Ben Thorner
0312e2a528 Split generating authorization headers by type
In response to [1].

[1]: https://github.com/alphagov/notifications-api/pull/3300#discussion_r681653248
2021-08-04 15:13:52 +01:00
Rebecca Law
424796bdcc Add unit test for archiving a template with a template folder 2021-04-29 13:32:36 +01:00
Rebecca Law
85895a9e8b Revert "Scheduled weekly dependency update for week 16" 2021-04-28 10:17:16 +01:00
Rebecca Law
10b0554784 Merge pull request #3219 from alphagov/pyup-scheduled-update-2021-04-21
Scheduled weekly dependency update for week 16
2021-04-28 09:20:35 +01:00
Rebecca Law
dcd08a0e45 Add unit test for archiving a template with a template folder 2021-04-27 12:30:50 +01:00
Chris Hill-Scott
f8bca5765d Validate length of broadcast templates on creation
This is a belt-and-braces check because the admin app already checks
this. But since we do it for SMS already it makes sense to replicate it
for broadcast templates.
2021-04-22 17:11:31 +01:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Katie Smith
c77e73b26f Fix failing test
This was passing locally, but failing on Concourse due to a different
order of TemplateHistory items being returned. This changes the
test so that it can't randomly fail based on the order of template
history items returned.
2021-02-18 09:07:21 +00:00
Chris Hill-Scott
3a2081dc06 Serialise content for broadcast templates
Broadcast services only have broadcast templates. But on the frontend
we show the template type under the name of the template. This is
redundant. It would be better to preview the content of the template
instead.

At the moment we can’t do this because we optimised the template schema
response to not include the content of the templates in
https://github.com/alphagov/notifications-api/pull/2880

This commit reverses that optimisation, for broadcast templates only,
and expands the tests to cover all template types.
2020-10-13 16:27:29 +01:00
David McDonald
7b5f4ad156 Fix bug with missing template version param
We were asking for the latest version of a letter template rather than
the version that the notification was sent with. This mean that if you
previewed a letter and had made edits to the template since it was sent
you would be shown an incorrect preview.
2020-08-17 15:30:16 +01:00
Leo Hemsted
5f337f7914 add broadcast_message to database
new broadcast_message table. contains a whole bunch of timestamps, a
couple of user ids for who created and who approved, some
personalisation and a template id/version. areas is a jsonb field - it
is expected that this will be an array, for example `["england",
"wales"]`

intended valid state transitions are as follows, from an initial status
of draft

* draft -> pending-approval, rejected
* pending-approval -> broadcasting, rejected, (draft maybe)
* broadcasting -> completed, cancelled

rejected, completed, cancelled and technical-failure are terminating
states.

also copy across the enum switching code from migration 0060 (adding
letter type).
2020-07-06 16:37:35 +01:00
Leo Hemsted
7ecd7341b0 add broadcast to template_types and add broadcast_data
had to go through the code and change a few places where we filter on
template types. i specifically didn't worry about jobs or notifications.

Also, add braodcast_data - a json column that might contain arbitrary
broadcast data that we'll figure out as we go. We don't know what it'll
look like, but it should be returned by the API
2020-07-06 15:47:13 +01:00
Chris Hill-Scott
02e5ff61a4 Test that template history updates created by 2020-06-29 12:30:08 +01:00
Chris Hill-Scott
718f8ccad0 Remove content and subject from get all templates
Content and subject are user-submitted so are effectively unbounded in
size. And we’re serialising them for every template when sending the
list of templates to the admin app.

For the service with the most templates this results in a 1.3Mb blob of
JSON going over the wire, and being cached in Redis.

And then the admin app completely ignores these fields, because it does
show template content until you’ve clicked into a single template.

This commit adds a new query parameter, `detailed`, that the admin app
can set to `False`. When it does only the fields needed to render the
`/templates` page are returned.

This is done with a new parameter so as not to break the V1 API.
Although I looked in Kibana and it doesn’t seem like anyone external is
using this endpoint we’ve come this far without breaking the API so…
2020-06-22 13:08:41 +01:00
Katie Smith
ab956c9eb3 Update JSON schema postage validation for new values 2020-06-19 15:36:10 +01:00
Katie Smith
72be10c681 Add JSON schema for updating template
We did not have a JSON schema for updating a template. Since we will
remove the postage constraint from the templates table, this adds a JSON
schema for updating a template so that we can use it to check that the
postage is one of the allowed values.
2020-06-19 08:59:27 +01:00
Katie Smith
15112b2148 Update post_create_template_schema
Updated the `post_create_template_schema` to check that the postage is
one of our allowed values.
2020-06-19 08:59:27 +01:00
David McDonald
483c00b3a2 Undo bug for previewing precompiled letters
https://github.com/alphagov/notifications-api/pull/2742/files#diff-d9a6761afaff4a491e60b64f6063654fL265
introduced a change in behaviour which causes template preview to 500
for a precompiled letter that is invalid but not because the content is
outside the printable area.

The changes it back to the previous behaviour, where we b64encode and
utf-8 decode for a page that is invalid for reasons that are not content
outside the printable area, for example a non portrait a4 letter.

I didn't end up writing a unit test for this because I really can't
figure out the existing behaviour we expect for this use case. This
method is too big and complex but I'm confident by looking at the change
in the commit mentioned above that this puts behaviour back to how it
was. Manual testing also confirms the fix.

I've also taken this opportunity to improve two test names whilst I was
looking at things.
2020-03-11 14:34:12 +00:00
David McDonald
d9243b8b8a When requesting a png for a single page, show overlay as appropriate
If the png page is invalid then show the overlay for that page
If the png page is not invalid, even if other pages are invalid, then
don't shown the overlay for that page

These keeps the behaviour were if you get the pdf for a pdf which has
invalid pages then the whole PDF is requested (not just a single page)
and all of the pages include the overlay

Tests have been improved to be more explicit about what we are testing
2020-03-09 14:54:58 +00:00
David McDonald
9eda30f4fd Refactor tests to be a bit more readable
Make arguments more verbose and have pytest params as inputs at the
start and expected things at the end
2020-03-09 14:48:33 +00:00
David McDonald
d168dd106e Add uncovered test cases
We want to know that the overlay is added regardless of which page
number you are requesting when a pdf contains pages that go beyond the
print area
2020-03-09 14:47:31 +00:00
Pea (Malgorzata Tyczynska)
2b1a84dd0d Merge pull request #2647 from alphagov/tell-users-why-letter-failed-validation
Grab metadata when getting pdf letter preview from S3
2019-11-01 10:19:53 +00:00
Katie Smith
38243cf860 Stop calling fixtures as functions in the tests 2019-10-30 13:05:53 +00:00
Katie Smith
99c3837dc1 Fix the fixtures for templates lacking certain permissions
These fixtures were both calling other fixtures as functions and being
called as functions in the tests. Rewriting the tests to make them
Pytest 4 compatible means we are no longer using
`sample_template_without_letter_permission`, so this has been deleted.
2019-10-30 11:22:36 +00:00
Pea Tyczynska
c2825e10b1 Grab metadata when getting pdf letter preview from S3
Also use this metadata to decide whether preview pages need
overlay or not. So far we have always added overlay when validation
has failed. Now we will only show it when validation failed due to
content being outside of printable area.
2019-10-29 16:19:50 +00:00
Katie Smith
0c1fa3852f Add endpoint for getting / creating a hidden template
We want a way of getting the hidden precompiled template from admin,
so this adds an endpoint which gets the template or creates it if it doesn't
exist. The function to get or create the hidden template already existed
but has been moved to the template DAO now that it is used in more
places.
2019-09-12 09:56:10 +01:00
Pea Tyczynska
454690a008 Fix bug in precompiled preview with overlay
The bug treated all pages of png preview as if they were all first
page, showing overlay for address bar
2019-04-24 18:29:01 +01:00
Pea Tyczynska
2d71aea7a1 Get rid of an unneeded flag - destination endpoint is slimmer now and doesnt need it 2019-04-11 16:33:40 +01:00
Pea Tyczynska
dd9e285684 Refactor preview_letter_template_by_notification_id 2019-04-11 14:27:57 +01:00
Pea Tyczynska
63fe210202 Also show overlay on document download of failed letter
And of course test this new flex
2019-04-11 14:27:12 +01:00
Pea Tyczynska
2f52a8fd64 Call overlaid preview for precompiled letters that fail validation
Also test precompiled letter preview with overlay
2019-04-11 14:26:59 +01:00
Leo Hemsted
afc5c96927 Don't fallback to dvla_organisation if letter branding unset
The template preview app now accepts a null value for the `filename` 
parameter. If a service doesn't have a letter branding option set, 
previously we defaulted to their dvla_organisation (probably HM 
Government). Now, we pass through None, so that we generate letters 
without any logo or branding.
2019-02-13 11:58:54 +00:00
Pea Tyczynska
5b9e6c2086 Set postage on basis of postage argument or template postage 2019-02-06 13:23:09 +00:00
Pea Tyczynska
ccd5a758f0 Set postage to second class when creating new letter template
Also get rid of checks for CHOOSE_POSTAGE permission when creating
and updating a template.
2019-01-30 16:26:49 +00:00
Pea Tyczynska
fb1ca9b20d Test postage setting on happy path for create and update template 2018-12-24 12:24:17 +00:00
Pea Tyczynska
e6524af89c Choose postage when persisting a notification 2018-12-21 16:37:52 +00:00
Pea Tyczynska
19f7678b05 Don't allow to set postage per template if no service permission 2018-12-21 16:37:52 +00:00
Rebecca Law
4120525568 Update error from ResultNotFound to InvalidRequest 2018-11-07 17:07:04 +00:00
Rebecca Law
f5de80f195 Fix conflict 2018-11-07 16:39:04 +00:00
Rebecca Law
1b0b16fa74 Update model and controller to handle parent_folder_id when creating a template.
If the parent_folder_id then check if the folder exists and is for the same service. If it is add the folder to the template model object, the relationship will be persisted when the template is saved. If the folder does not exist or is for a different service, then return a ResultNotFound error.
2018-11-07 16:17:09 +00:00
Rebecca Law
4849ecdf63 Update the template_schema to include a parent_folder_id.
When creating the Tempalte from_json, the folder is passed in. Since some validation should done, as in the folder exists and is for the same service, the folder is passed through to the Tempalte.from_json method.
When the template is persisted so is the relationship to folders.
TODO: If the folder is invalid a specific message should be returned.
2018-11-07 16:17:09 +00:00
Rebecca Law
39198ed67e Using jsonschema for create_template.
Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required.
This version is backward compatible with Draft4.
When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
2018-11-07 16:17:08 +00:00
Katie Smith
a87be9b74a Use new value of SMS_CHAR_COUNT_LIMIT from utils
Admin, API and utils were all defining a value for SMS_CHAR_COUNT_LIMIT.
This value has been updated in notifications-utils to allow text
messages to be 4 fragments long and notifications-api now gets the value of
SMS_CHAR_COUNT_LIMIT from notifications-utils instead of defining it in
config.

Also updated some tests to check for the higher limit.
2018-08-16 16:34:34 +01:00
Chris Hill-Scott
8ae800b117 Pass date of letter to template preview
Otherwise all letters will show the current date.

Also beefed up the tests around this part of the code a bit.
2018-04-30 15:47:49 +01:00
Ken Tsang
7524402b56 Only hide the notify tag on precompiled on first page 2018-03-29 14:38:38 +01:00
Richard Chapman
79a6ce8782 * Updated imports to comply with pep8 for better maintainability
* Removed extra log messages so there are not two log messages being
generated per exception, as InvalidRequest also logs, updated the
InvalidRequest log message to include the exception type and exception
information
* Added extra asserts to ensure the exception messages are printed
2018-03-12 11:05:05 +00:00