Skip to content

Commit 1022a87

Browse files
authored
Show list of attachments on template edit page (#2743)
* Show list of attachments on template edit page * Fix translation * Fix test * Used shared partial instead of duplicating code
1 parent 4eb2044 commit 1022a87

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

app/main/views/templates.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,26 @@ def edit_service_template(service_id, template_id):
12811281
)
12821282
)
12831283
else:
1284+
template_attachments = None
1285+
if (
1286+
current_app.config.get("FF_FILE_ATTACHMENTS")
1287+
and template["template_type"] == "email"
1288+
and current_service.has_permission("upload_document")
1289+
):
1290+
template_attachments = [
1291+
{
1292+
"id": attachment.get("id"),
1293+
"filename": attachment.get("name") or attachment.get("filename"),
1294+
"file_size": attachment.get("size") or attachment.get("file_size"),
1295+
"status": attachment.get("status") or "uploaded",
1296+
}
1297+
for attachment in filter_attachments(
1298+
current_service.get_template_attachments(template_id),
1299+
exclude_statuses={"deleted", "virus_scan_failed"},
1300+
)
1301+
if attachment.get("name") or attachment.get("filename")
1302+
]
1303+
12841304
return render_template(
12851305
f"views/edit-{template['template_type']}-template.html",
12861306
form=form,
@@ -1292,6 +1312,7 @@ def edit_service_template(service_id, template_id):
12921312
sms_char_count_limit=SMS_CHAR_COUNT_LIMIT,
12931313
one_click_unsub_enabled=current_app.config.get("ONE_CLICK_UNSUB_ALL_SERVICES", False)
12941314
or str(service_id) in current_app.config.get("ONE_CLICK_UNSUB_SERVICE_IDS", []),
1315+
attachments=template_attachments,
12951316
)
12961317

12971318

app/templates/partials/template-attachments-list.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
- summary text and warning behavior should track product decisions in send views.
1616
#}
1717
{% if template.template_type == 'email' and template_attachments %}
18-
<section class="mb-8 border border-gray-300 p-4 attachment-list-flush-top" data-testid="template-attachments-list">
18+
{% set attachment_list_classes = attachment_list_classes|default('attachment-list-flush-top') %}
19+
<section class="mb-8 border border-gray-300 p-4 {{ attachment_list_classes }}" data-testid="template-attachments-list">
1920
<ul class="list-none m-0 p-0" data-testid="template-attachments-items">
2021
{% for attachment in template_attachments %}
2122
<li class="attachment-file-row border border-gray-300 p-3 mb-2" data-testid="template-attachments-item">

app/templates/views/edit-email-template.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{% from "components/template-content.html" import template_content with context %}
1111
{% from "components/links.html" import content_link with context %}
1212
{% from "components/tiptap-editor.html" import tiptap_editor with context %}
13+
{% from "components/notice.html" import notice %}
1314

1415
{% block service_page_title %}
1516
{{ heading }}
@@ -85,6 +86,24 @@
8586
initialMode="rte" if current_user.default_editor_is_rte else "markdown")
8687
}}
8788

89+
{% if config['FF_FILE_ATTACHMENTS'] and attachments %}
90+
<section class="mb-16">
91+
<h2 id="attachments-heading" class="heading-medium">
92+
{{ _("Attachments") }}
93+
</h2>
94+
95+
{% call notice('info') %}
96+
<p data-testid="file-attachments-edit-template-notice">
97+
{{ _('To edit attachments, save changes to your template or press back.') }}
98+
</p>
99+
{% endcall %}
100+
101+
{% set template_attachments = attachments %}
102+
{% set attachment_list_classes = 'mt-4' %}
103+
{% include "partials/template-attachments-list.html" %}
104+
</section>
105+
{% endif %}
106+
88107
<h2 class="heading-medium">{{ _('Template category') }}</h2>
89108
{% call template_category(form.template_category_id, true if template_category_mode == 'expand' else false) %}
90109
{{ select(form.template_category_id, hint=_('Template categories help improve delivery of your messages'), option_hints=template_category_hints, option_conditionals=other_category, testid="template-categories", use_aria_labelledby=false) }}

app/translations/csv/fr.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,3 +2494,7 @@
24942494
"Counted as 1 text message part.","Compté comme 1 partie de message texte."
24952495
"Counted as {} text message parts.","Compté comme {} parties de messages texte."
24962496
"Text message parts count toward your sending limits.","Les parties de message texte comptent envers vos limites d'envoi."
2497+
"To edit attachments, save changes to your template or press back.","Pour modifier les pièces jointes, enregistrez les modifications apportées à votre modèle ou appuyez sur Retour."
2498+
"Attachment","Pièce jointe"
2499+
"files attached","fichiers joints"
2500+
"Files attached to this template","Fichiers joints à ce gabarit"

0 commit comments

Comments
 (0)