Skip to content

Copy templates also copies files#5871

Open
rparke wants to merge 1 commit into
mainfrom
rp-copy-template-also-copies-files
Open

Copy templates also copies files#5871
rparke wants to merge 1 commit into
mainfrom
rp-copy-template-also-copies-files

Conversation

@rparke
Copy link
Copy Markdown
Contributor

@rparke rparke commented Apr 9, 2026

we noticed a bug where we werent' copying over files when copying over a template with files. This results in the new template having fileplaceholders interpreted as "regular" placeholders for normal personalisation. This downloads the old file from s3, creates a new entry in template_email_files and then makes it live.

We don't have the api endpoints to make a file live straightaway - we may wish to implement this instead of hitting the create endpoint and then the update endpoint.

Copying templates when contact link is not set:
Screenshot 2026-05-06 at 10 34 17

Screenshot 2026-05-06 at 10 34 47 Screenshot 2026-05-06 at 10 34 56

@rparke rparke force-pushed the rp-copy-template-also-copies-files branch 3 times, most recently from af48f92 to c12c280 Compare April 16, 2026 09:07
@rparke rparke marked this pull request as ready for review April 16, 2026 09:08
Comment on lines +2738 to +2749
def test_post_copy_template_with_file(
client_request,
active_user_with_permissions,
mock_get_service,
multiple_sms_senders,
mock_get_service_email_template_with_file,
mock_get_service_templates,
mock_get_organisations_and_services_for_user,
fake_uuid,
mock_create_service_template,
mocker,
):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of code duplication in this with test_post_copy_template_into_folder which I don't love. And mocking out uuids in a nice way proved tricky, so I'm open to any ideas to make this a bit nicer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of getting deterministic UUIDs without mocking:

(uuid.UUID(int=1), uuid.UUID(int=2)), # BAD - this person has just signed in on a different browser

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to patch the file_id and the template_id specifically.

@rparke rparke changed the title WIP Copy templates also copies files Apr 16, 2026
Comment thread app/models/template_email_file.py
@rparke rparke force-pushed the rp-copy-template-also-copies-files branch 2 times, most recently from e4f57db to e7ebfa6 Compare May 6, 2026 12:06
@rparke rparke marked this pull request as draft May 6, 2026 12:12
@rparke rparke force-pushed the rp-copy-template-also-copies-files branch from e7ebfa6 to c4f54ba Compare May 6, 2026 15:18
@rparke rparke marked this pull request as ready for review May 7, 2026 09:07
Comment thread app/main/views/templates.py Outdated
we noticed a bug where we werent' copying over files when copying over a template with files. This results in the new template having fileplaceholders interpreted as "regular" placeholders for normal personalisation. This downloads the old file from s3, creates a new entry in `template_email_files` and then makes it live.

We don't have the api endpoints to make a file live straightaway - we may wish to implement this instead of hitting the create endpoint and then the update endpoint.
@rparke rparke force-pushed the rp-copy-template-also-copies-files branch from e7ba33b to 9cdc8b6 Compare May 11, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants