mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Add user argument to email_filter
This commit is contained in:
@@ -176,6 +176,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
|||||||
'url': build_absolute_uri('control:user.settings')
|
'url': build_absolute_uri('control:user.settings')
|
||||||
},
|
},
|
||||||
event=None,
|
event=None,
|
||||||
|
user=self,
|
||||||
locale=self.locale
|
locale=self.locale
|
||||||
)
|
)
|
||||||
except SendMailException:
|
except SendMailException:
|
||||||
@@ -191,7 +192,7 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
|||||||
'url': (build_absolute_uri('control:auth.forgot.recover')
|
'url': (build_absolute_uri('control:auth.forgot.recover')
|
||||||
+ '?id=%d&token=%s' % (self.id, default_token_generator.make_token(self)))
|
+ '?id=%d&token=%s' % (self.id, default_token_generator.make_token(self)))
|
||||||
},
|
},
|
||||||
None, locale=self.locale
|
None, locale=self.locale, user=self
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from i18nfield.strings import LazyI18nString
|
|||||||
from pretix.base.email import ClassicMailRenderer
|
from pretix.base.email import ClassicMailRenderer
|
||||||
from pretix.base.i18n import language
|
from pretix.base.i18n import language
|
||||||
from pretix.base.models import (
|
from pretix.base.models import (
|
||||||
Event, Invoice, InvoiceAddress, Order, OrderPosition,
|
Event, Invoice, InvoiceAddress, Order, OrderPosition, User,
|
||||||
)
|
)
|
||||||
from pretix.base.services.invoices import invoice_pdf_task
|
from pretix.base.services.invoices import invoice_pdf_task
|
||||||
from pretix.base.services.tasks import TransactionAwareTask
|
from pretix.base.services.tasks import TransactionAwareTask
|
||||||
@@ -51,7 +51,7 @@ class SendMailException(Exception):
|
|||||||
def mail(email: str, subject: str, template: Union[str, LazyI18nString],
|
def mail(email: str, subject: str, template: Union[str, LazyI18nString],
|
||||||
context: Dict[str, Any]=None, event: Event=None, locale: str=None,
|
context: Dict[str, Any]=None, event: Event=None, locale: str=None,
|
||||||
order: Order=None, position: OrderPosition=None, headers: dict=None, sender: str=None,
|
order: Order=None, position: OrderPosition=None, headers: dict=None, sender: str=None,
|
||||||
invoices: list=None, attach_tickets=False, auto_email=True):
|
invoices: list=None, attach_tickets=False, auto_email=True, user=None):
|
||||||
"""
|
"""
|
||||||
Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation.
|
Sends out an email to a user. The mail will be sent synchronously or asynchronously depending on the installation.
|
||||||
|
|
||||||
@@ -88,6 +88,8 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
|
|||||||
|
|
||||||
:param auto_email: Whether this email is auto-generated
|
:param auto_email: Whether this email is auto-generated
|
||||||
|
|
||||||
|
:param user: The user this email is sent to
|
||||||
|
|
||||||
:raises MailOrderException: on obvious, immediate failures. Not raising an exception does not necessarily mean
|
:raises MailOrderException: on obvious, immediate failures. Not raising an exception does not necessarily mean
|
||||||
that the email has been sent, just that it has been queued by the email backend.
|
that the email has been sent, just that it has been queued by the email backend.
|
||||||
"""
|
"""
|
||||||
@@ -214,7 +216,8 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
|
|||||||
invoices=[i.pk for i in invoices] if invoices and not position else [],
|
invoices=[i.pk for i in invoices] if invoices and not position else [],
|
||||||
order=order.pk if order else None,
|
order=order.pk if order else None,
|
||||||
position=position.pk if position else None,
|
position=position.pk if position else None,
|
||||||
attach_tickets=attach_tickets
|
attach_tickets=attach_tickets,
|
||||||
|
user=user.pk if user else None
|
||||||
)
|
)
|
||||||
|
|
||||||
if invoices:
|
if invoices:
|
||||||
@@ -229,13 +232,16 @@ def mail(email: str, subject: str, template: Union[str, LazyI18nString],
|
|||||||
@app.task(base=TransactionAwareTask, bind=True)
|
@app.task(base=TransactionAwareTask, bind=True)
|
||||||
def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: str, sender: str,
|
def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: str, sender: str,
|
||||||
event: int=None, position: int=None, headers: dict=None, bcc: List[str]=None,
|
event: int=None, position: int=None, headers: dict=None, bcc: List[str]=None,
|
||||||
invoices: List[int]=None, order: int=None, attach_tickets=False) -> bool:
|
invoices: List[int]=None, order: int=None, attach_tickets=False, user=None) -> bool:
|
||||||
email = EmailMultiAlternatives(subject, body, sender, to=to, bcc=bcc, headers=headers)
|
email = EmailMultiAlternatives(subject, body, sender, to=to, bcc=bcc, headers=headers)
|
||||||
if html is not None:
|
if html is not None:
|
||||||
html_with_cid, cid_images = replace_images_with_cid_paths(html)
|
html_with_cid, cid_images = replace_images_with_cid_paths(html)
|
||||||
email = attach_cid_images(email, cid_images, verify_ssl=True)
|
email = attach_cid_images(email, cid_images, verify_ssl=True)
|
||||||
email.attach_alternative(html_with_cid, "text/html")
|
email.attach_alternative(html_with_cid, "text/html")
|
||||||
|
|
||||||
|
if user:
|
||||||
|
user = User.objects.get(pk=user)
|
||||||
|
|
||||||
if event:
|
if event:
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
event = Event.objects.get(id=event)
|
event = Event.objects.get(id=event)
|
||||||
@@ -297,7 +303,7 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
email = email_filter.send_chained(event, 'message', message=email, order=order)
|
email = email_filter.send_chained(event, 'message', message=email, order=order, user=user)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backend.send_messages([email])
|
backend.send_messages([email])
|
||||||
|
|||||||
@@ -120,4 +120,5 @@ def send_notification_mail(notification: Notification, user: User):
|
|||||||
'html': body_html,
|
'html': body_html,
|
||||||
'sender': settings.MAIL_FROM,
|
'sender': settings.MAIL_FROM,
|
||||||
'headers': {},
|
'headers': {},
|
||||||
|
'user': user.pk
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ As with all event-plugin signals, the ``sender`` keyword argument will contain t
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
email_filter = EventPluginSignal(
|
email_filter = EventPluginSignal(
|
||||||
providing_args=['message', 'order']
|
providing_args=['message', 'order', 'user']
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
This signal allows you to implement a middleware-style filter on all outgoing emails. You are expected to
|
This signal allows you to implement a middleware-style filter on all outgoing emails. You are expected to
|
||||||
@@ -510,6 +510,8 @@ As with all event-plugin signals, the ``sender`` keyword argument will contain t
|
|||||||
The ``message`` argument will contain an ``EmailMultiAlternatives`` object.
|
The ``message`` argument will contain an ``EmailMultiAlternatives`` object.
|
||||||
If the email is associated with a specific order, the ``order`` argument will be passed as well, otherwise
|
If the email is associated with a specific order, the ``order`` argument will be passed as well, otherwise
|
||||||
it will be ``None``.
|
it will be ``None``.
|
||||||
|
If the email is associated with a specific user, e.g. a notification email, the ``user`` argument will be passed as
|
||||||
|
well, otherwise it will be ``None``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user