From f475781a89ba751c2d821b1c73cf7505de8f11cc Mon Sep 17 00:00:00 2001
From: Raphael Michel
Date: Tue, 18 Mar 2025 08:58:54 +0100
Subject: [PATCH] Order email history: Record more information about
attachments (Z#23185463) (#4914)
---
src/pretix/base/models/orders.py | 4 ++
src/pretix/base/models/waitinglist.py | 2 +
.../pretixcontrol/order/mail_history.html | 35 +++++++++++++++
src/pretix/control/views/orders.py | 15 +++++++
src/pretix/plugins/sendmail/tasks.py | 17 ++++++--
.../pretixplugins/sendmail/send_form.html | 43 ++++++++++---------
6 files changed, 92 insertions(+), 24 deletions(-)
diff --git a/src/pretix/base/models/orders.py b/src/pretix/base/models/orders.py
index 8854151403..7ac8beff17 100644
--- a/src/pretix/base/models/orders.py
+++ b/src/pretix/base/models/orders.py
@@ -1199,6 +1199,8 @@ class Order(LockModel, LoggedModel):
'invoices': [i.pk for i in invoices] if invoices else [],
'attach_tickets': attach_tickets,
'attach_ical': attach_ical,
+ 'attach_other_files': attach_other_files,
+ 'attach_cached_files': [cf.filename for cf in attach_cached_files] if attach_cached_files else [],
}
)
@@ -2857,6 +2859,8 @@ class OrderPosition(AbstractPosition):
'invoices': [i.pk for i in invoices] if invoices else [],
'attach_tickets': attach_tickets,
'attach_ical': attach_ical,
+ 'attach_other_files': attach_other_files,
+ 'attach_cached_files': [],
}
)
diff --git a/src/pretix/base/models/waitinglist.py b/src/pretix/base/models/waitinglist.py
index df5d979922..2b9b48df75 100644
--- a/src/pretix/base/models/waitinglist.py
+++ b/src/pretix/base/models/waitinglist.py
@@ -286,6 +286,8 @@ class WaitingListEntry(LoggedModel):
'subject': subject,
'message': email_content,
'recipient': recipient,
+ 'attach_other_files': attach_other_files,
+ 'attach_cached_files': [cf.filename for cf in attach_cached_files] if attach_cached_files else [],
}
)
diff --git a/src/pretix/control/templates/pretixcontrol/order/mail_history.html b/src/pretix/control/templates/pretixcontrol/order/mail_history.html
index e3f72f5437..ade4baed66 100644
--- a/src/pretix/control/templates/pretixcontrol/order/mail_history.html
+++ b/src/pretix/control/templates/pretixcontrol/order/mail_history.html
@@ -51,6 +51,41 @@
{{ log.parsed_data.subject }}
{{ log.parsed_data.message }}
+
+ {% if log.parsed_data.attach_tickets %}
+ - {% trans "Tickets" %}
+ {% endif %}
+ {% if log.parsed_data.attach_ical %}
+ - {% trans "Calendar invite" %}
+ {% endif %}
+ {% if log.parsed_data.invoices %}
+ {% for i in log.parsed_invoices %}
+ -
+
+
+ {% if i.is_cancellation %}{% trans "Cancellation" context "invoice" %}{% else %}{% trans "Invoice" %}{% endif %}
+ {{ i.number }}
+
+
+ {% endfor %}
+ {% endif %}
+ {% if log.parsed_data.attach_other_files %}
+ {% for f in log.parsed_other_files %}
+ -
+
+ {{ f }}
+
+ {% endfor %}
+ {% endif %}
+ {% if log.parsed_data.attach_cached_files %}
+ {% for f in log.parsed_data.attach_cached_files %}
+ -
+
+ {{ f }}
+
+ {% endfor %}
+ {% endif %}
+
{% endif %}
{% endfor %}
diff --git a/src/pretix/control/views/orders.py b/src/pretix/control/views/orders.py
index 82bd4ca600..6b97bbc1ed 100644
--- a/src/pretix/control/views/orders.py
+++ b/src/pretix/control/views/orders.py
@@ -135,6 +135,7 @@ from pretix.control.views import PaginationMixin
from pretix.helpers import OF_SELF
from pretix.helpers.compat import CompatDeleteView
from pretix.helpers.format import SafeFormatter, format_map
+from pretix.helpers.hierarkey import clean_filename
from pretix.helpers.safedownload import check_token
from pretix.presale.signals import question_form_fields
@@ -2461,6 +2462,20 @@ class OrderEmailHistory(EventPermissionRequiredMixin, OrderViewMixin, ListView):
)
return qs
+ def get_context_data(self, **kwargs):
+ ctx = super().get_context_data(**kwargs)
+ for l in ctx["logs"]:
+ if l.parsed_data.get("invoices"):
+ l.parsed_invoices = Invoice.objects.filter(
+ event=self.request.event,
+ pk__in=l.parsed_data["invoices"],
+ )
+ if l.parsed_data.get("attach_other_files"):
+ l.parsed_other_files = [
+ clean_filename(os.path.basename(f)) for f in l.parsed_data["attach_other_files"]
+ ]
+ return ctx
+
class AnswerDownload(EventPermissionRequiredMixin, OrderViewMixin, ListView):
permission = 'can_view_orders'
diff --git a/src/pretix/plugins/sendmail/tasks.py b/src/pretix/plugins/sendmail/tasks.py
index c5b8792899..08ae713e73 100644
--- a/src/pretix/plugins/sendmail/tasks.py
+++ b/src/pretix/plugins/sendmail/tasks.py
@@ -38,7 +38,9 @@ from i18nfield.strings import LazyI18nString
from pretix.base.email import get_email_context
from pretix.base.i18n import language
-from pretix.base.models import Checkin, Event, InvoiceAddress, Order, User
+from pretix.base.models import (
+ CachedFile, Checkin, Event, InvoiceAddress, Order, User,
+)
from pretix.base.services.mail import SendMailException, mail
from pretix.base.services.tasks import ProfiledEventTask
from pretix.celery_app import app
@@ -56,6 +58,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
orders = Order.objects.filter(pk__in=objects, event=event)
subject = LazyI18nString(subject)
message = LazyI18nString(message)
+ attachments_for_log = [cf.filename for cf in CachedFile.objects.filter(pk__in=attachments)] if attachments else []
for o in orders:
send_to_order = recipients in ('both', 'orders')
@@ -134,7 +137,11 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
'position': p.positionid,
'subject': format_map(subject.localize(o.locale), email_context),
'message': format_map(message.localize(o.locale), email_context),
- 'recipient': p.attendee_email
+ 'recipient': p.attendee_email,
+ 'attach_tickets': attach_tickets,
+ 'attach_ical': attach_ical,
+ 'attach_other_files': [],
+ 'attach_cached_files': attachments_for_log,
}
)
except SendMailException:
@@ -162,7 +169,11 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
data={
'subject': format_map(subject.localize(o.locale), email_context),
'message': format_map(message.localize(o.locale), email_context),
- 'recipient': o.email
+ 'recipient': o.email,
+ 'attach_tickets': attach_tickets,
+ 'attach_ical': attach_ical,
+ 'attach_other_files': [],
+ 'attach_cached_files': attachments_for_log,
}
)
except SendMailException:
diff --git a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html
index 308009a56b..9ba3dbc1db 100644
--- a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html
+++ b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html
@@ -45,27 +45,28 @@
{{ out.subject|safe }}
{{ out.html|safe }}
- {% if out.attachment %}
-
-
-
- {{ out.attachment.filename }}
-
-
- {% endif %}
- {% if form.cleaned_data.attach_tickets %}
-
-
- {% trans "Tickets" %}
-
- {% endif %}
- {% if form.cleaned_data.attach_ical %}
-
-
- {% trans "Attach calendar files" %}
-
- {% endif %}
+
+ {% if out.attachment %}
+ -
+
+
+ {{ out.attachment.filename }}
+
+
+ {% endif %}
+ {% if form.cleaned_data.attach_tickets %}
+ -
+
+ {% trans "Tickets" %}
+
+ {% endif %}
+ {% if form.cleaned_data.attach_ical %}
+ -
+
+ {% trans "Attach calendar files" %}
+
+ {% endif %}
+
{% endfor %}