Commit Graph

46 Commits

Author SHA1 Message Date
Cliff Hill
43a8b6539f More fixes, removing literal "created" from code.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:58:22 -05:00
Cliff Hill
cd081ef163 Down to 11 errors left to fix for tests.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:44:19 -05:00
Cliff Hill
26bc6198f8 Cleaning up tests.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:43:34 -05:00
Cliff Hill
ac9591ec7c More tweaks, trying to get tests to be clean.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:43:31 -05:00
Cliff Hill
df866e40f7 More Enum goodness.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:43:27 -05:00
Kenneth Kehl
1ecb747c6d reformat 2023-08-29 14:54:30 -07:00
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
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
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Pea Tyczynska
95deb5a52f Move DATETIME_FORMAT from app to app.utils
To avoid cyclical import issues
2020-12-18 17:39:35 +00:00
Pea Tyczynska
f6f88750b5 Add contact block to serialize template for v2
This attribute has been requested by a user, and we have not been
serializing it so far.
2020-07-13 17:04:01 +01:00
Leo Hemsted
0282a76bf7 rename template.serialize to serialize_for_v2
make it clear that this is for the public api, and we shouldn't add
fields to it without considering impacts

also add the broadcast_messages relationship on service and template to
the exclude from the marshmallow schemas, so it's not included elsewhere
2020-07-06 16:42:31 +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
Katie Smith
98a69684c5 Update get_template_by_id_response & post_template_preview_response schemas
To check the format of postage. Neither of these two schemas are used
for validating - they seem to be added for reference.
2020-06-19 08:59:27 +01:00
Chris Hill-Scott
054cd16d02 Ensure correct object renders V2 template preview
The `body` field of the ‘preview a template’ endpoint should contain the
content of the template with the placeholders replaced.

It should not be rendered into a plain text email, which does stuff like
normalising newlines (so `\r\n` becomes `\n`). However the object that
the `create_post_template_preview_response` function receives is an
instance of `PlainTextEmailTemplate`. So we can’t just call `str()` on
it. Instead we need to call the `__str__` method of
`WithSubjectTemplate` which gives us the result we want.

We were already doing this the right way in the V1 endpoint[1] but
forgot to do it here too.

1. 0108749daa/app/template/rest.py (L181-L184)
2020-04-07 17:09:59 +01:00
Chris Hill-Scott
025ac3ea89 Use same template to validate and send notification
To be absolutely sure that we can send a message we should also validate
it using the same template class that we use to render it.
2020-04-07 10:41:16 +01:00
Rebecca Law
5d6886242b Check that the request payload data is valid json.
By adding `force=True` to request.get_json() the mime type is ignore. If the data is not valid json the method will return a `BadRequestError` we catch that and throw our own error with a clear error message "Invalid JSON supplied in POST data".
If the json is valid return the json data or an empty dict if None is passed in.

This PR improves the error messages if the json is invalid, previously, the error message was "None object type" message which is not very helpful.
2019-11-21 15:23:11 +00:00
Leo Hemsted
c78a5d8536 Merge pull request #2662 from alphagov/utils-bump
Utils bump
2019-11-21 15:23:11 +00:00
Pea (Malgorzata Tyczynska)
ccfa1c8228 Revert "Ensure dao_create_template doesn't clash with new trigger" 2019-06-26 18:01:20 +01:00
Pea Tyczynska
673cabe6b8 Ensure dao_create_template doesn't clash with new trigger
New trigger creates template_redacted row after insert to template
table

And update tests
2019-06-25 15:40:10 +01:00
Chris Hill-Scott
aab36157a5 Test for HTML response in the schema
Because we test for the other properties in the schema.

Also sets `additionalProperties` to `False` so we’re forced to update
the schemas if we make similar changes in the future. This means
removing `created_by` from the test data because it’s not returned by
the real response.
2019-02-08 13:10:42 +00:00
Chris Hill-Scott
f185dbecbe Return rendered HTML when previewing a template
If you’re trying to show what a Notify email will look like in your
caseworking system all the API gives you at the moment is raw markdown
(with the placeholders replaced).

This isn’t that useful if your caseworkers have no idea what markdown
is. If we also give teams the HTML then they can embed this in their
systems, and the people using those systems will be able to see how
headings, bulleted lists, etc. look.
2019-02-07 17:43:46 +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
52a7dcf86c Add choose_postage service permission and add postage to Template 2018-12-14 18:12:26 +00:00
Chris Hill-Scott
55d185f50d Return metadata about placeholders
In the future, we may want to return additional information about
placeholders.

We came up with three possible formats:
1. list of `dict`s, eg `[{'name': 'first name', 'required': True}]`
2. `dict` of `list`s, eg `{'required': ['first name']}`
3. `dict` of `dict`s, eg `{'name': {'required': True}}`

I don’t like 1. because it’s harder to traverse if all you want is the
name of the placeholders, and suggests that you could have two
placeholders with the same name (which you can’t). I don’t like 2.
because it only lets the data be sliced by one dimension (unless the
inner lists aren’t exclusive, in which case you’d need to filter
duplicates when just listing placeholders).

I think 3. has the two advantages of:
- represents that personalisation is unique, ie you can’t pass back in
  two different values for the same key
- is forward compatible, ie we can add many more properties of a
  placeholder without breaking anything

So this commit implements 3.
2017-09-22 16:42:16 +01:00
Chris Hill-Scott
fa8e4b29f2 Return placeholders when getting a template
> Currently when retrieving a template via one of the clients, we do
> not return the personalisation fields that are required for that
> template.
>
> This is useful for services who want to perform template validation on
> their own systems. A service user has also requested this.

– https://www.pivotaltracker.com/story/show/150674476

This commit adds an extra attribute to the JSON response containing an
array of the placeholder names. This key is called "personalisation",
to match the argument that developers use to pass in the values of
placeholders.
2017-09-22 10:00:23 +01:00
Chris Hill-Scott
04e41e3147 Return template name in public API
The use for the public template API is for building caseworking systems
or similar, where you might need a list of templates to pick from (ie
instead of using the Notify web interface to pick from and send a
message).

Right now our API isn’t returning the template name as part of the
response. The name is a useful, human-friendly way of identifying a
template.

This commit changes the response to include the name.

Some clients will need updating before this can be useful.
2017-08-15 14:46:30 +01:00
Leo Hemsted
da02ffa32f ensure template history serializes using template serialize fn 2017-08-09 12:24:35 +01:00
Leo Hemsted
11f8603319 Remove custom error message from personalisation validation
There's no longer a single err msg that fits all problems with
personalisation - since letters expect specific fields there
2017-07-27 16:49:37 +01:00
Ken Tsang
e2ad8ba50d Renamed get template test 2017-04-19 10:51:12 +01:00
Ken Tsang
89e244ccd2 First commit 2017-04-19 10:51:12 +01:00
Ken Tsang
f5da3574b5 Add get all templates schema 2017-04-19 10:51:12 +01:00
Ken Tsang
7c0aeca66e Removed unused imports 2017-04-11 16:19:43 +01:00
Ken Tsang
06ec7a59a6 Refactored code to personalise subject 2017-04-11 16:19:43 +01:00
Ken Tsang
eba88b08c5 Removed URI from preview response 2017-04-11 16:19:43 +01:00
Ken Tsang
50db538df7 Updated schema to remove redundant 'content' 2017-03-23 11:50:15 +00:00
Ken Tsang
41f82c0aef Refactored tests to use fake_uuid 2017-03-22 14:31:16 +00:00
Ken Tsang
ecbe87a0d6 Added letter preview 2017-03-22 14:22:26 +00:00
Ken Tsang
b81d789307 Add preview endpoint and tests 2017-03-22 10:11:31 +00:00
Ken Tsang
fbcea9c777 Refactored test for optionals 2017-03-22 10:10:06 +00:00
Ken Tsang
8d63f8d9d3 Refactored get template test 2017-03-22 10:10:06 +00:00
Ken Tsang
fad67e1bdd Added schemas + tests & updated get template tests 2017-03-22 10:10:05 +00:00
Ken Tsang
ea8a3754a0 Updated schema to handle null updated_at 2017-03-15 15:48:28 +00:00
Ken Tsang
7558a7661a Updated schema description 2017-03-15 09:19:56 +00:00
Ken Tsang
a596a1bb87 Refactored tests and get template endpoint 2017-03-14 17:51:30 +00:00
Ken Tsang
9e4b1b2bfc Add schemas, endpoints and supporting tests 2017-03-14 15:40:38 +00:00