mirror of
https://github.com/pretix/pretix.git
synced 2026-10-04 19:44:42 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ea6159049 | ||
|
|
07615bbb30 | ||
|
|
038992ba9d | ||
|
|
c94e1ed31a |
@@ -11,7 +11,8 @@ Core
|
||||
----
|
||||
|
||||
.. automodule:: pretix.base.signals
|
||||
:members: periodic_task, event_live_issues, event_copy_data, email_filter, register_notification_types, notification,
|
||||
:members: periodic_task, event_live_issues, event_copy_data, email_filter,
|
||||
register_notification_types, event_notification_sent, organizer_notification_sent,
|
||||
item_copy_data, register_sales_channel_types, register_global_settings, quota_availability, global_email_filter,
|
||||
register_ticket_secret_generators, gift_card_transaction_display,
|
||||
register_text_placeholders, register_mail_placeholders, device_info_updated,
|
||||
|
||||
Generated
+15
-15
@@ -194,16 +194,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-array/node_modules/brace-expansion": {
|
||||
"version": "5.0.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
|
||||
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz",
|
||||
"integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^4.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
"node": "18 || 20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-array/node_modules/minimatch": {
|
||||
@@ -1339,16 +1339,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": {
|
||||
"version": "5.0.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
|
||||
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz",
|
||||
"integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^4.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
"node": "18 || 20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": {
|
||||
@@ -1697,9 +1697,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz",
|
||||
"integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
||||
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -2122,16 +2122,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/brace-expansion": {
|
||||
"version": "5.0.12",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
|
||||
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz",
|
||||
"integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^4.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
"node": "18 || 20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/eslint-visitor-keys": {
|
||||
|
||||
@@ -1683,7 +1683,7 @@ class PaymentViewSet(CreateModelMixin, viewsets.ReadOnlyModelViewSet):
|
||||
@action(detail=True, methods=['POST'])
|
||||
def confirm(self, request, **kwargs):
|
||||
payment = self.get_object()
|
||||
force = request.data.get('force', False) if request.data else False
|
||||
force = request.data.get('force', False)
|
||||
send_mail = request.data.get('send_email', True) if request.data else True
|
||||
|
||||
if payment.state not in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED):
|
||||
|
||||
@@ -71,8 +71,8 @@ class EmailTransmissionType(TransmissionType):
|
||||
|
||||
def transmission_info_to_form_data(self, transmission_info: dict) -> dict:
|
||||
return {
|
||||
"transmission_email_other": bool((transmission_info or {}).get("transmission_email_address")),
|
||||
"transmission_email_address": (transmission_info or {}).get("transmission_email_address"),
|
||||
"transmission_email_other": bool(transmission_info.get("transmission_email_address")),
|
||||
"transmission_email_address": transmission_info.get("transmission_email_address"),
|
||||
}
|
||||
|
||||
def form_data_to_transmission_info(self, form_data: dict) -> dict:
|
||||
|
||||
@@ -42,7 +42,7 @@ from django.conf import settings
|
||||
from django.core.mail import get_connection
|
||||
from django.core.validators import MinLengthValidator, RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
from django.urls import reverse
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.functional import cached_property
|
||||
@@ -312,6 +312,25 @@ class Organizer(LoggedModel):
|
||||
)
|
||||
i += 1
|
||||
|
||||
def get_users_with_permission(self, permission):
|
||||
"""
|
||||
Returns a queryset of users who have a specific permission to this organizer.
|
||||
|
||||
:return: Iterable of User
|
||||
"""
|
||||
from .auth import User
|
||||
|
||||
if permission:
|
||||
qs = Team.objects.with_organizer_permission(permission)
|
||||
else:
|
||||
qs = Team.objects.all()
|
||||
|
||||
team_with_perm = qs.filter(
|
||||
members__pk=OuterRef('pk'),
|
||||
organizer=self,
|
||||
)
|
||||
return User.objects.annotate(twp=Exists(team_with_perm)).filter(twp=True)
|
||||
|
||||
|
||||
def generate_invite_token():
|
||||
return get_random_string(length=32, allowed_chars=string.ascii_lowercase + string.digits)
|
||||
|
||||
@@ -35,12 +35,13 @@
|
||||
import logging
|
||||
from collections import OrderedDict, namedtuple
|
||||
from itertools import groupby
|
||||
from typing import Optional, Union
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.utils.formats import date_format
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
|
||||
from pretix.base.models import Event, LogEntry
|
||||
from pretix.base.models import Event, LogEntry, Organizer
|
||||
from pretix.base.signals import register_notification_types
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
from pretix.helpers.urls import mainreverse_absolute
|
||||
@@ -57,7 +58,8 @@ class Notification:
|
||||
"""
|
||||
Represents a notification that is sent/shown to a user. A notification consists of:
|
||||
|
||||
* one ``event`` reference
|
||||
* one ``event`` reference (can be ``Ǹone``)
|
||||
* one ``organizer`` reference
|
||||
* one ``title`` text that is shown e.g. in the email subject or in a headline
|
||||
* optionally one ``detail`` text that may or may not be shown depending on the notification method
|
||||
* optionally one ``url`` that should be absolute and point to the context of an notification (e.g. an order)
|
||||
@@ -67,8 +69,12 @@ class Notification:
|
||||
each consisting of a button label and an absolute URL to point to.
|
||||
"""
|
||||
|
||||
def __init__(self, event: Event, title: str, detail: str=None, url: str=None):
|
||||
def __init__(self, event: Optional[Event], title: str, detail: Optional[str]=None, url: Optional[str]=None, organizer: Optional[Organizer]=None):
|
||||
assert event or organizer, "You need to pass either event or organizer"
|
||||
if event and organizer:
|
||||
assert event.organizer_id == organizer.id, "Organizer and event mismatch"
|
||||
self.title = title
|
||||
self.organizer = organizer or event.organizer
|
||||
self.event = event
|
||||
self.detail = detail
|
||||
self.url = url
|
||||
@@ -91,8 +97,16 @@ class Notification:
|
||||
|
||||
|
||||
class NotificationType:
|
||||
def __init__(self, event: Event = None):
|
||||
self.event = event
|
||||
def __init__(self, event_or_organizer: Union[Event, Organizer] = None):
|
||||
if isinstance(event_or_organizer, Event):
|
||||
self.event = event_or_organizer
|
||||
self.organizer = event_or_organizer.organizer
|
||||
elif isinstance(event_or_organizer, Organizer):
|
||||
self.event = None
|
||||
self.organizer = event_or_organizer
|
||||
else:
|
||||
self.event = None
|
||||
self.organizer = None
|
||||
|
||||
def __repr__(self):
|
||||
return '<NotificationType: {}>'.format(self.action_type)
|
||||
@@ -121,31 +135,39 @@ class NotificationType:
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
|
||||
@property
|
||||
def is_event_level(self) -> bool:
|
||||
"""
|
||||
Return `True` if this notification type can be configured per event (the default).
|
||||
"""
|
||||
return True
|
||||
|
||||
def build_notification(self, logentry: LogEntry) -> Notification:
|
||||
"""
|
||||
This is the main function that you should override. It is supposed to turn a log entry
|
||||
object into a notification object that can then be rendered e.g. into an email.
|
||||
"""
|
||||
return Notification(
|
||||
logentry.event,
|
||||
logentry.display()
|
||||
event=logentry.event,
|
||||
title=logentry.display(),
|
||||
organizer=logentry.organizer,
|
||||
)
|
||||
|
||||
|
||||
def get_all_notification_types(event=None):
|
||||
def get_all_notification_types(event_or_organizer=None):
|
||||
global _ALL_TYPES
|
||||
|
||||
if event is None and _ALL_TYPES:
|
||||
if event_or_organizer is None and _ALL_TYPES:
|
||||
return _ALL_TYPES
|
||||
|
||||
types = OrderedDict()
|
||||
for recv, ret in register_notification_types.send(event):
|
||||
for recv, ret in register_notification_types.send(event_or_organizer):
|
||||
if isinstance(ret, (list, tuple)):
|
||||
for r in ret:
|
||||
types[r.action_type] = r
|
||||
else:
|
||||
types[ret.action_type] = ret
|
||||
if event is None:
|
||||
if event_or_organizer is None:
|
||||
_ALL_TYPES = types
|
||||
return types
|
||||
|
||||
@@ -181,6 +203,7 @@ class ParametrizedOrderNotificationType(NotificationType):
|
||||
|
||||
n = Notification(
|
||||
event=logentry.event,
|
||||
organizer=logentry.organizer,
|
||||
title=self._title.format(order=order, event=logentry.event),
|
||||
url=order_url
|
||||
)
|
||||
|
||||
@@ -34,7 +34,9 @@ from pretix.base.models import (
|
||||
from pretix.base.notifications import Notification, get_all_notification_types
|
||||
from pretix.base.services.mail import mail_send_task
|
||||
from pretix.base.services.tasks import ProfiledTask, TransactionAwareTask
|
||||
from pretix.base.signals import notification
|
||||
from pretix.base.signals import (
|
||||
event_notification_sent, organizer_notification_sent,
|
||||
)
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers.celery import get_task_priority
|
||||
from pretix.helpers.urls import mainreverse_absolute
|
||||
@@ -47,14 +49,14 @@ def notify(logentry_ids: list):
|
||||
logentry_ids = [logentry_ids]
|
||||
|
||||
qs = LogEntry.all.select_related(
|
||||
'event', 'event__organizer'
|
||||
'event', 'event__organizer', 'organizer'
|
||||
).order_by(
|
||||
'action_type', 'event_id',
|
||||
'action_type', 'event_id', 'organizer_id',
|
||||
).filter(id__in=logentry_ids)
|
||||
|
||||
_event, _at, notify_specific, notify_global = None, None, None, None
|
||||
_event, _organizer, _at, notify_specific, notify_global = None, None, None, None, None
|
||||
for logentry in qs:
|
||||
if not logentry.event:
|
||||
if not logentry.event and not logentry.organizer:
|
||||
break # Ignore, we only have event-related notifications right now
|
||||
|
||||
notification_type = logentry.notification_type
|
||||
@@ -62,25 +64,36 @@ def notify(logentry_ids: list):
|
||||
if not notification_type:
|
||||
break # No suitable plugin
|
||||
|
||||
if _event != logentry.event or _at != logentry.action_type or notify_global is None:
|
||||
if _event != logentry.event or _organizer != logentry.organizer or _at != logentry.action_type or notify_global is None:
|
||||
_event = logentry.event
|
||||
_organizer = logentry.organizer
|
||||
_at = logentry.action_type
|
||||
# All users that have the permission to get the notification
|
||||
users = logentry.event.get_users_with_permission(
|
||||
notification_type.required_permission
|
||||
).filter(notifications_send=True, is_active=True)
|
||||
|
||||
if logentry.event:
|
||||
# All users that have the permission to get the notification
|
||||
users = logentry.event.get_users_with_permission(
|
||||
notification_type.required_permission
|
||||
).filter(notifications_send=True, is_active=True)
|
||||
else:
|
||||
users = logentry.organizer.get_users_with_permission(
|
||||
notification_type.required_permission
|
||||
).filter(notifications_send=True, is_active=True)
|
||||
|
||||
if logentry.user:
|
||||
users = users.exclude(pk=logentry.user.pk)
|
||||
|
||||
# Get all notification settings, both specific to this event as well as global
|
||||
notify_specific = {
|
||||
(ns.user, ns.method): ns.enabled
|
||||
for ns in NotificationSetting.objects.filter(
|
||||
event=logentry.event,
|
||||
action_type=notification_type.action_type,
|
||||
user__pk__in=users.values_list('pk', flat=True)
|
||||
)
|
||||
}
|
||||
if logentry.event:
|
||||
notify_specific = {
|
||||
(ns.user, ns.method): ns.enabled
|
||||
for ns in NotificationSetting.objects.filter(
|
||||
event=logentry.event,
|
||||
action_type=notification_type.action_type,
|
||||
user__pk__in=users.values_list('pk', flat=True)
|
||||
)
|
||||
}
|
||||
else:
|
||||
notify_specific = {}
|
||||
notify_global = {
|
||||
(ns.user, ns.method): ns.enabled
|
||||
for ns in NotificationSetting.objects.filter(
|
||||
@@ -106,7 +119,10 @@ def notify(logentry_ids: list):
|
||||
priority=get_task_priority("notifications", logentry.organizer_id),
|
||||
)
|
||||
|
||||
notification.send(logentry.event, logentry_id=logentry.id, notification_type=notification_type.action_type)
|
||||
if logentry.event:
|
||||
event_notification_sent.send(logentry.event, logentry_id=logentry.id, notification_type=notification_type.action_type)
|
||||
elif logentry.organizer:
|
||||
organizer_notification_sent.send(logentry.organizer, logentry_id=logentry.id, notification_type=notification_type.action_type)
|
||||
|
||||
|
||||
@app.task(base=ProfiledTask, acks_late=True, max_retries=9, default_retry_delay=900)
|
||||
@@ -158,13 +174,19 @@ def send_notification_mail(notification: Notification, user: User):
|
||||
body_plain = tpl_plain.render(ctx)
|
||||
|
||||
guid = uuid.uuid4()
|
||||
settings_holder = notification.event or notification.organizer
|
||||
prefix = settings_holder.settings.mail_prefix
|
||||
if not prefix and notification.event:
|
||||
prefix = notification.event.slug.upper()
|
||||
elif notification.organizer:
|
||||
prefix = notification.organizer.name
|
||||
m = OutgoingMail.objects.create(
|
||||
guid=guid,
|
||||
user=user,
|
||||
to=[user.email],
|
||||
subject='[{}] {}: {}'.format(
|
||||
settings.PRETIX_INSTANCE_NAME,
|
||||
notification.event.settings.mail_prefix or notification.event.slug.upper(),
|
||||
prefix,
|
||||
notification.title
|
||||
),
|
||||
body_plain=body_plain,
|
||||
|
||||
@@ -605,15 +605,14 @@ subclass of pretix.base.ticketoutput.BaseTicketOutput
|
||||
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
|
||||
"""
|
||||
|
||||
register_notification_types = EventPluginSignal()
|
||||
register_notification_types = GlobalSignal()
|
||||
"""
|
||||
This signal is sent out to get all known notification types. Receivers should return an
|
||||
instance of a subclass of pretix.base.notifications.NotificationType or a list of such
|
||||
instances.
|
||||
|
||||
As with all event-plugin signals, the ``sender`` keyword argument will contain the event,
|
||||
however for this signal, the ``sender`` **may also be None** to allow creating the general
|
||||
notification settings!
|
||||
When called for actually sending notifications, ``sender`` will be the event or organizer,
|
||||
depending on context.
|
||||
"""
|
||||
|
||||
register_event_permission_groups = GlobalSignal()
|
||||
@@ -628,7 +627,7 @@ This signal is sent out to get all known permissions. Receivers should return an
|
||||
instance of pretix.base.permissions.PermissionGroup or a list of such instances.
|
||||
"""
|
||||
|
||||
notification = EventPluginSignal()
|
||||
event_notification_sent = EventPluginSignal()
|
||||
"""
|
||||
Arguments: ``logentry_id``, ``notification_type``
|
||||
|
||||
@@ -637,6 +636,15 @@ This signal is sent out when a notification is sent.
|
||||
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
|
||||
"""
|
||||
|
||||
organizer_notification_sent = OrganizerPluginSignal()
|
||||
"""
|
||||
Arguments: ``logentry_id``, ``notification_type``
|
||||
|
||||
This signal is sent out when a notification is sent.
|
||||
|
||||
As with all organizer-plugin signals, the ``sender`` keyword argument will contain the organizer.
|
||||
"""
|
||||
|
||||
register_sales_channel_types = GlobalSignal()
|
||||
"""
|
||||
This signal is sent out to get all known sales channels types. Receivers should return an
|
||||
|
||||
@@ -761,6 +761,7 @@ class UserNotificationsEditView(TemplateView):
|
||||
{k: a.get(t) for k, a in self.global_set.items()},
|
||||
)
|
||||
for t, tv in self.types.items()
|
||||
if tv.is_event_level or not self.event
|
||||
]
|
||||
ctx['event'] = self.event
|
||||
if self.event:
|
||||
|
||||
@@ -161,12 +161,7 @@ class OrderMailForm(BaseMailForm):
|
||||
),
|
||||
label=pgettext_lazy('sendmail_form', 'Restrict to products'),
|
||||
required=True,
|
||||
queryset=Item.objects.none(),
|
||||
help_text=pgettext_lazy(
|
||||
'sendmail_form',
|
||||
'There may be multiple mails sent out to the same mail address if one order contains multiple attendee '
|
||||
'products for it, if you restrict to products while also restricting mails to attendees only. '
|
||||
'This is intended, as every one of those get linked to their own separate order page restricted to only that product.')
|
||||
queryset=Item.objects.none()
|
||||
)
|
||||
filter_checkins = forms.BooleanField(
|
||||
label=_('Filter check-in status'),
|
||||
@@ -379,11 +374,6 @@ class RuleForm(FormPlaceholderMixin, I18nModelForm):
|
||||
del self.fields['subevent']
|
||||
|
||||
self.fields['limit_products'].queryset = Item.objects.filter(event=self.event)
|
||||
self.fields['limit_products'].help_text = pgettext_lazy(
|
||||
'sendmail_form',
|
||||
'There may be multiple mails sent out to the same mail address if one order contains multiple attendee '
|
||||
'products for it, if you restrict to products while also restricting mails to attendees only. '
|
||||
'This is intended, as every one of those get linked to their own separate order page restricted to only that product.')
|
||||
|
||||
self.fields['schedule_type'] = forms.ChoiceField(
|
||||
label=_('Type of schedule time'),
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
import logging
|
||||
from datetime import datetime, time, timedelta
|
||||
|
||||
from dateutil.tz import datetime_exists
|
||||
@@ -40,8 +39,6 @@ from pretix.base.models import (
|
||||
)
|
||||
from pretix.base.models.base import LoggingMixin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ScheduledMail(models.Model):
|
||||
STATE_SCHEDULED = 'scheduled'
|
||||
@@ -118,7 +115,7 @@ class ScheduledMail(models.Model):
|
||||
|
||||
filter_orders_by_op = False
|
||||
op_qs = OrderPosition.objects.filter(
|
||||
order__event=e,
|
||||
order__event=self.event,
|
||||
canceled=False,
|
||||
)
|
||||
|
||||
@@ -170,58 +167,14 @@ class ScheduledMail(models.Model):
|
||||
for o in orders:
|
||||
with language(o.locale, e.settings.region):
|
||||
positions = list(o.positions.all())
|
||||
send_to_order = send_to_orders
|
||||
o_sent = False
|
||||
|
||||
try:
|
||||
ia = o.invoice_address
|
||||
except InvoiceAddress.DoesNotExist:
|
||||
ia = InvoiceAddress(order=o)
|
||||
|
||||
if send_to_attendees:
|
||||
parent_op = None
|
||||
sent_to_positions = set()
|
||||
for p in positions:
|
||||
if p.addon_to_id is None:
|
||||
# this op might have matching add-ons, so save for later
|
||||
parent_op = p
|
||||
elif not parent_op or p.addon_to_id != parent_op.id:
|
||||
# this op is an add-on, but not to the current parent_op
|
||||
# something got mixed up as add-ons should always come directly after their parent
|
||||
logger.warning(f"Add-ons are mixed up for position #{p.positionid} in order {o.full_code}")
|
||||
continue
|
||||
|
||||
if p.id not in position_ids:
|
||||
# not a matching op, just there for parent_op
|
||||
continue
|
||||
|
||||
if p.addon_to_id and (
|
||||
not p.attendee_email or p.attendee_email == parent_op.attendee_email
|
||||
):
|
||||
# if op is addon and either has no mail or the same as parent => send to parent
|
||||
p = parent_op
|
||||
|
||||
if p.pk in sent_to_positions:
|
||||
# this position already got an email
|
||||
continue
|
||||
|
||||
if not p.attendee_email or p.attendee_email == o.email:
|
||||
# no email or same as order => send to order
|
||||
send_to_order = True
|
||||
continue
|
||||
|
||||
email_ctx = get_email_context(
|
||||
event=e,
|
||||
order=o,
|
||||
invoice_address=ia,
|
||||
position=p,
|
||||
event_or_subevent=self.subevent or e,
|
||||
)
|
||||
p.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||
attach_ical=self.rule.attach_ical,
|
||||
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
||||
sent_to_positions.add(p.pk)
|
||||
|
||||
if send_to_order and o.email:
|
||||
if send_to_orders and o.email:
|
||||
email_ctx = get_email_context(
|
||||
event=e,
|
||||
order=o,
|
||||
@@ -231,6 +184,38 @@ class ScheduledMail(models.Model):
|
||||
o.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||
attach_ical=self.rule.attach_ical,
|
||||
log_entry_type='pretix.plugins.sendmail.rule.order.email.sent')
|
||||
o_sent = True
|
||||
|
||||
if send_to_attendees:
|
||||
if not self.rule.all_products:
|
||||
positions = [p for p in positions if p.item_id in limit_products]
|
||||
if self.subevent_id:
|
||||
positions = [p for p in positions if p.subevent_id == self.subevent_id]
|
||||
|
||||
for p in positions:
|
||||
if p.id in position_ids:
|
||||
if p.attendee_email and (p.attendee_email != o.email or not o_sent):
|
||||
email_ctx = get_email_context(
|
||||
event=e,
|
||||
order=o,
|
||||
invoice_address=ia,
|
||||
position=p,
|
||||
event_or_subevent=self.subevent or e,
|
||||
)
|
||||
p.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||
attach_ical=self.rule.attach_ical,
|
||||
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
||||
elif not o_sent and o.email:
|
||||
email_ctx = get_email_context(
|
||||
event=e,
|
||||
order=o,
|
||||
invoice_address=ia,
|
||||
event_or_subevent=self.subevent or e,
|
||||
)
|
||||
o.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||
attach_ical=self.rule.attach_ical,
|
||||
log_entry_type='pretix.plugins.sendmail.rule.order.email.sent')
|
||||
o_sent = True
|
||||
|
||||
self.last_successful_order_id = o.pk
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
# Unless required by applicable law or agreed to in writing, software distributed under the Apache License 2.0 is
|
||||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations under the License.
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
@@ -44,8 +43,6 @@ from pretix.base.services.mail import mail
|
||||
from pretix.base.services.tasks import ProfiledEventTask
|
||||
from pretix.celery_app import app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _chunks(lst, n):
|
||||
"""
|
||||
@@ -73,8 +70,6 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
except InvoiceAddress.DoesNotExist:
|
||||
ia = InvoiceAddress(order=o)
|
||||
|
||||
parent_op = None
|
||||
sent_to_positions = set()
|
||||
if recipients in ('both', 'attendees'):
|
||||
for p in o.positions.annotate(
|
||||
any_checkins=Exists(
|
||||
@@ -90,16 +85,10 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
)
|
||||
),
|
||||
).prefetch_related('addons', 'subevent'):
|
||||
|
||||
if p.addon_to_id is None:
|
||||
parent_op = p
|
||||
elif not parent_op or p.addon_to_id != parent_op.id:
|
||||
# this op is an add-on, but not to the current parent_op
|
||||
# something got mixed up as add-ons should always come directly after their parent
|
||||
logger.warning(f"Add-ons are mixed up for position #{p.positionid} in order {o.full_code}")
|
||||
if p.addon_to_id is not None:
|
||||
continue
|
||||
|
||||
if p.item_id not in items:
|
||||
if p.item_id not in items and not any(a.item_id in items for a in p.addons.all()):
|
||||
continue
|
||||
|
||||
if filter_checkins:
|
||||
@@ -110,11 +99,13 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
if not allowed:
|
||||
continue
|
||||
|
||||
if p.addon_to_id and (
|
||||
not p.attendee_email or p.attendee_email == parent_op.attendee_email
|
||||
):
|
||||
# if op is addon and either has no mail or the same as parent => send to parent
|
||||
p = parent_op
|
||||
if not p.attendee_email:
|
||||
if recipients == 'attendees':
|
||||
send_to_order = True
|
||||
continue
|
||||
|
||||
if p.attendee_email == o.email and send_to_order:
|
||||
continue
|
||||
|
||||
if subevent and p.subevent_id != subevent:
|
||||
continue
|
||||
@@ -125,18 +116,6 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
if subevents_to and p.subevent.date_from >= subevents_to:
|
||||
continue
|
||||
|
||||
if not p.attendee_email:
|
||||
send_to_order = True
|
||||
continue
|
||||
|
||||
if p.pk in sent_to_positions:
|
||||
# this position already got an email
|
||||
continue
|
||||
|
||||
if p.attendee_email == o.email:
|
||||
send_to_order = True
|
||||
continue
|
||||
|
||||
with language(o.locale, event.settings.region):
|
||||
email_context = get_email_context(event=event, order=o, invoice_address=ia, position=p)
|
||||
outgoing_mail = mail(
|
||||
@@ -158,7 +137,6 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
user=user,
|
||||
data=outgoing_mail.log_data(),
|
||||
)
|
||||
sent_to_positions.add(p.pk)
|
||||
|
||||
if send_to_order and o.email:
|
||||
with language(o.locale, event.settings.region):
|
||||
|
||||
@@ -183,6 +183,7 @@ class OrderPositionDetailMixin(NoSearchIndexViewMixin):
|
||||
def position(self):
|
||||
qs = OrderPosition.objects.filter(
|
||||
order__event=self.request.event,
|
||||
addon_to__isnull=True,
|
||||
order__code=self.kwargs['order'],
|
||||
positionid=self.kwargs['position']
|
||||
).select_related('order', 'order__event')
|
||||
|
||||
@@ -556,6 +556,8 @@ var editor = {
|
||||
editor.$fcv.get(0).height = editor.pdf_viewport.height
|
||||
editor.fabric = new fabric.Canvas('fabric-canvas')
|
||||
|
||||
editor.fabric.on('object:modified', editor._create_savepoint)
|
||||
editor.fabric.on('object:added', editor._create_savepoint)
|
||||
editor.fabric.on('selection:cleared', editor._update_toolbox)
|
||||
editor.fabric.on('selection:created', editor._update_toolbox)
|
||||
editor.fabric.on('selection:updated', editor._update_toolbox)
|
||||
@@ -588,12 +590,6 @@ var editor = {
|
||||
if (editor._window_loaded) {
|
||||
editor._ready()
|
||||
}
|
||||
|
||||
editor.fabric.on('object:modified', editor._create_savepoint)
|
||||
editor.fabric.on('object:added', editor._create_savepoint)
|
||||
editor.fabric.on('object:added', function(e) {
|
||||
editor.fabric.setActiveObject(e.target);
|
||||
})
|
||||
},
|
||||
|
||||
_window_load_event: function () {
|
||||
@@ -960,6 +956,7 @@ var editor = {
|
||||
mtr: true
|
||||
})
|
||||
editor.fabric.add(text)
|
||||
editor._create_savepoint()
|
||||
return text
|
||||
},
|
||||
|
||||
@@ -975,6 +972,7 @@ var editor = {
|
||||
rect.scaleToHeight(126)
|
||||
rect.setControlsVisibility({ mtr: false, mb: false, mt: false, mr: false, ml: false })
|
||||
editor.fabric.add(rect)
|
||||
editor._create_savepoint()
|
||||
return rect
|
||||
},
|
||||
|
||||
@@ -1011,6 +1009,7 @@ var editor = {
|
||||
mtr: true
|
||||
})
|
||||
editor.fabric.add(rect)
|
||||
editor._create_savepoint()
|
||||
$('#version-notice').show()
|
||||
return rect
|
||||
},
|
||||
@@ -1027,6 +1026,7 @@ var editor = {
|
||||
})
|
||||
rect.setControlsVisibility({ mtr: false })
|
||||
editor.fabric.add(rect)
|
||||
editor._create_savepoint()
|
||||
return rect
|
||||
},
|
||||
|
||||
@@ -1044,6 +1044,7 @@ var editor = {
|
||||
})
|
||||
rect.setControlsVisibility({ mtr: false, mb: false, mt: false, mr: false, ml: false })
|
||||
editor.fabric.add(rect)
|
||||
editor._create_savepoint()
|
||||
return rect
|
||||
},
|
||||
|
||||
|
||||
@@ -813,13 +813,7 @@ function setup_basics (el) {
|
||||
return
|
||||
}
|
||||
|
||||
$('<li></li>')
|
||||
.append(
|
||||
$('<a></a>').attr("href", "#" + scrollTarget.id).text($.trim(label))
|
||||
)
|
||||
.append(
|
||||
document.createTextNode(' - ' + description)
|
||||
)
|
||||
$('<li><a href="#' + scrollTarget.id + '">' + $.trim(label) + '</a> – ' + description + '</li>')
|
||||
.appendTo(alert.querySelector('ul') || $('<ul>').appendTo(alert))
|
||||
.find('a').on('click', function (e) {
|
||||
$panel.collapse('show')
|
||||
|
||||
@@ -157,12 +157,6 @@
|
||||
.profile-scope:last-child .profile-save-container {
|
||||
margin-bottom: -15px;
|
||||
}
|
||||
|
||||
/* the rule above removes blank space after any profile-save-container at the end of every fieldset, which causes an overlay if addon-questions are used. So re-add margin for non-addon-fieldsets followed by fieldsets (currently only happens it addon-questions are available) */
|
||||
fieldset:not(:has(.profile-add-on)):has( + fieldset) .profile-scope:last-child .profile-save-container {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.profile-save-container .help-block {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ def order(event):
|
||||
|
||||
@pytest.fixture
|
||||
def team(event):
|
||||
return event.organizer.teams.create(all_events=True, all_event_permissions=True)
|
||||
return event.organizer.teams.create(all_events=True, all_event_permissions=True, all_organizer_permissions=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -108,6 +108,17 @@ def test_notification_trigger_global_wildcard(event, order, user, django_capture
|
||||
assert len(djmail.outbox) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_trigger_organizer(event, user, django_capture_on_commit_callbacks):
|
||||
djmail.outbox = []
|
||||
user.notification_settings.create(
|
||||
method='mail', event=None, action_type='pretix.organizer.changed', enabled=True
|
||||
)
|
||||
with django_capture_on_commit_callbacks(execute=True):
|
||||
event.organizer.log_action('pretix.organizer.changed', {})
|
||||
assert len(djmail.outbox) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_enabled_global_ignored_specific(event, order, user, django_capture_on_commit_callbacks):
|
||||
djmail.outbox = []
|
||||
@@ -134,7 +145,7 @@ def test_notification_ignore_same_user(event, order, user, django_capture_on_com
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_ignore_insufficient_permissions(event, order, user, team, django_capture_on_commit_callbacks):
|
||||
def test_notification_ignore_insufficient_event_permissions(event, order, user, team, django_capture_on_commit_callbacks):
|
||||
djmail.outbox = []
|
||||
team.all_event_permissions = False
|
||||
team.limit_event_permissions = {"event.vouchers:read": True}
|
||||
@@ -146,4 +157,18 @@ def test_notification_ignore_insufficient_permissions(event, order, user, team,
|
||||
order.log_action('pretix.event.order.paid', {})
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_ignore_insufficient_organizer_permissions(event, team, user, django_capture_on_commit_callbacks):
|
||||
djmail.outbox = []
|
||||
team.all_organizer_permissions = False
|
||||
team.limit_organizer_permissions = {"organizer.giftcards:read": True}
|
||||
team.save()
|
||||
user.notification_settings.create(
|
||||
method='mail', event=None, action_type='pretix.organizer.changed', enabled=True
|
||||
)
|
||||
with django_capture_on_commit_callbacks(execute=True):
|
||||
event.organizer.log_action('pretix.organizer.changed', {})
|
||||
assert len(djmail.outbox) == 0
|
||||
|
||||
# TODO: Test email content
|
||||
|
||||
@@ -219,8 +219,14 @@ def test_specific_organizer_permission(event, user):
|
||||
def test_organizer_permissions_multiple_teams(event, user):
|
||||
team1 = Team.objects.create(organizer=event.organizer, limit_organizer_permissions={"organizer.settings.general:write": True})
|
||||
team2 = Team.objects.create(organizer=event.organizer, limit_organizer_permissions={"organizer.events:create": True})
|
||||
assert set(event.organizer.get_users_with_permission('organizer.settings.general:write')) == set()
|
||||
assert set(event.organizer.get_users_with_permission(None)) == set()
|
||||
team1.members.add(user)
|
||||
assert set(event.organizer.get_users_with_permission('organizer.settings.general:write')) == {user}
|
||||
assert set(event.organizer.get_users_with_permission(None)) == {user}
|
||||
assert set(event.organizer.get_users_with_permission('organizer.events:create')) == set()
|
||||
team2.members.add(user)
|
||||
assert set(event.organizer.get_users_with_permission('organizer.events:create')) == {user}
|
||||
orga2 = Organizer.objects.create(slug='d2', name='d2')
|
||||
team3 = Team.objects.create(organizer=orga2, limit_organizer_permissions={"organizer.teams:write": True})
|
||||
team3.members.add(user)
|
||||
|
||||
@@ -199,84 +199,6 @@ def test_sendmail_rule_send_order_vs_pos(send_to, amount_mails, recipients, orde
|
||||
assert djmail.outbox[0].subject == 'Dummy: Foo City @ 11:30'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize('send_to,amount_mails,recipients,ticket_mail,addon_mail, products', [
|
||||
(Rule.ATTENDEES, 1, ['addon-attendee@dummy.test'], 'attendee@dummy.test', 'addon-attendee@dummy.test', 'addon'),
|
||||
(Rule.ATTENDEES, 2, ['attendee@dummy.test', 'addon-attendee@dummy.test'], 'attendee@dummy.test',
|
||||
'addon-attendee@dummy.test', 'both'),
|
||||
(Rule.ATTENDEES, 1, ['attendee@dummy.test'], 'attendee@dummy.test', 'attendee@dummy.test', 'both'),
|
||||
(Rule.ATTENDEES, 1, ['attendee@dummy.test'], 'attendee@dummy.test', None, 'addon'),
|
||||
(Rule.ATTENDEES, 1, ['attendee@dummy.test'], 'attendee@dummy.test', None, 'both'),
|
||||
(Rule.ATTENDEES, 1, ['dummy@dummy.test'], None, None, 'addon'),
|
||||
(Rule.ATTENDEES, 1, ['dummy@dummy.test'], None, None, 'both'),
|
||||
(Rule.ATTENDEES, 2, ['dummy@dummy.test', 'addon-attendee@dummy.test'], None, 'addon-attendee@dummy.test', 'both'),
|
||||
(Rule.ATTENDEES, 1, ['dummy@dummy.test'], None, None, 'all'),
|
||||
(Rule.ATTENDEES, 2, ['dummy@dummy.test', 'addon-attendee@dummy.test'], None, 'addon-attendee@dummy.test', 'all'),
|
||||
])
|
||||
@scopes_disabled()
|
||||
def test_sendmail_rule_send_addons(send_to, amount_mails, recipients, ticket_mail, addon_mail, products, order,
|
||||
event, pos, item, item2):
|
||||
djmail.outbox = []
|
||||
|
||||
order.status = order.STATUS_PAID
|
||||
order.save()
|
||||
|
||||
p = pos
|
||||
p.attendee_email = ticket_mail
|
||||
p.save()
|
||||
order.all_positions.create(item=item2, price=0, attendee_email=addon_mail, addon_to=p)
|
||||
rule = order.event.sendmail_rules.create(date_is_absolute=True, send_date=dt_now - datetime.timedelta(hours=1),
|
||||
send_to=send_to, subject='meow', template='meow meow meow',
|
||||
all_products=products == 'all')
|
||||
if products == 'addon':
|
||||
rule.limit_products.set([item2])
|
||||
if products == 'both':
|
||||
rule.limit_products.set([item, item2])
|
||||
|
||||
sendmail_run_rules(None)
|
||||
|
||||
assert len(djmail.outbox) == amount_mails
|
||||
|
||||
_recipients = [mail.to[0] for mail in djmail.outbox]
|
||||
assert set(recipients) == set(_recipients)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize('send_to,amount_mails,recipients,ticket_mail,addon_mail, products', [
|
||||
(Rule.ATTENDEES, 2, ['attendee@dummy.test', 'addon-attendee@dummy.test'], 'attendee@dummy.test',
|
||||
'addon-attendee@dummy.test', 'addon'),
|
||||
(Rule.ATTENDEES, 2, ['attendee@dummy.test', 'addon-attendee@dummy.test'], 'attendee@dummy.test',
|
||||
'addon-attendee@dummy.test', 'both'),
|
||||
])
|
||||
@scopes_disabled()
|
||||
def test_sendmail_rule_send_addons_one_unp(send_to, amount_mails, recipients, ticket_mail, addon_mail, products, order,
|
||||
event, pos, item, item2):
|
||||
djmail.outbox = []
|
||||
|
||||
order.status = order.STATUS_PAID
|
||||
order.save()
|
||||
|
||||
p = pos
|
||||
p.attendee_email = ticket_mail
|
||||
p.save()
|
||||
order.all_positions.create(item=item2, price=0, attendee_email=addon_mail, addon_to=p)
|
||||
order.all_positions.create(item=item2, price=0, addon_to=p)
|
||||
rule = order.event.sendmail_rules.create(date_is_absolute=True, send_date=dt_now - datetime.timedelta(hours=1),
|
||||
send_to=send_to, subject='meow', template='meow meow meow',
|
||||
all_products=False)
|
||||
if products == 'addon':
|
||||
rule.limit_products.set([item2])
|
||||
if products == 'both':
|
||||
rule.limit_products.set([item, item2])
|
||||
|
||||
sendmail_run_rules(None)
|
||||
|
||||
assert len(djmail.outbox) == amount_mails
|
||||
|
||||
_recipients = [mail.to[0] for mail in djmail.outbox]
|
||||
assert set(recipients) == set(_recipients)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@scopes_disabled()
|
||||
def test_sendmail_rule_send_attendees_unset_mail(order, event, item):
|
||||
|
||||
@@ -406,312 +406,6 @@ def test_sendmail_attendee_product_filter(logged_in_client, sendmail_url, event,
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_addon_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='add-on-attendee@dummy.test', addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': addon.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['add-on-attendee@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_ticket_and_addon_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='add-on-attendee@dummy.test', addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, p.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 2
|
||||
for msg in djmail.outbox:
|
||||
assert msg.to in [['attendee1@dummy.test'], ['add-on-attendee@dummy.test']]
|
||||
assert '/ticket/' in msg.body
|
||||
assert '/order/' not in msg.body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_ticket_and_same_addon_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='attendee1@dummy.test', addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, p.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['attendee1@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_addon_unpersonalized_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': addon.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['attendee1@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_ticket_and_addon_unp_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, p.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == ['attendee1@dummy.test']
|
||||
assert '/ticket/' in djmail.outbox[0].body
|
||||
assert '/order/' not in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_ticket_unp_and_addon_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='add-on-attendee@dummy.test', addon_to=pos
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, pos.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 2
|
||||
for msg in djmail.outbox:
|
||||
assert msg.to in [[order.email], ['add-on-attendee@dummy.test']]
|
||||
if msg.to == [order.email]:
|
||||
assert '/ticket/' not in msg.body
|
||||
assert '/order/' in msg.body
|
||||
else:
|
||||
assert msg.to == ['add-on-attendee@dummy.test']
|
||||
assert '/ticket/' in msg.body
|
||||
assert '/order/' not in msg.body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_addon_unp_unp_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=pos
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': addon.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == [order.email]
|
||||
assert '/ticket/' not in djmail.outbox[0].body
|
||||
assert '/order/' in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_and_addon_unp_unp_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=pos
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, pos.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 1
|
||||
assert djmail.outbox[0].to == [order.email]
|
||||
assert '/ticket/' not in djmail.outbox[0].body
|
||||
assert '/order/' in djmail.outbox[0].body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_two_addons_one_unp_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='add-on-attendee@dummy.test', addon_to=p
|
||||
)
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': addon.pk,
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 2
|
||||
for msg in djmail.outbox:
|
||||
assert msg.to in [['attendee1@dummy.test'], ['add-on-attendee@dummy.test']]
|
||||
assert '/ticket/' in msg.body
|
||||
assert '/order/' not in msg.body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_and_two_addons_one_unp_filter(logged_in_client, sendmail_url, event, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
with scopes_disabled():
|
||||
p = pos
|
||||
p.attendee_email = 'attendee1@dummy.test'
|
||||
p.save()
|
||||
addon = Item.objects.create(name='Test addon', event=event, default_price=12)
|
||||
order.positions.create(
|
||||
item=addon, price=0, attendee_email='add-on-attendee@dummy.test', addon_to=p
|
||||
)
|
||||
order.positions.create(
|
||||
item=addon, price=0, addon_to=p
|
||||
)
|
||||
|
||||
djmail.outbox = []
|
||||
response = logged_in_client.post(sendmail_url + 'orders/',
|
||||
{'sendto': 'na',
|
||||
'action': 'send',
|
||||
'recipients': 'attendees',
|
||||
'items': {addon.pk, p.item_id},
|
||||
'subject_0': 'Test subject',
|
||||
'message_0': 'This is a test file for sending mails.',
|
||||
},
|
||||
follow=True)
|
||||
assert response.status_code == 200
|
||||
assert 'alert-success' in response.rendered_content
|
||||
assert len(djmail.outbox) == 2
|
||||
for msg in djmail.outbox:
|
||||
assert msg.to in [['attendee1@dummy.test'], ['add-on-attendee@dummy.test']]
|
||||
assert '/ticket/' in msg.body
|
||||
assert '/order/' not in msg.body
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sendmail_attendee_subevent_filter(logged_in_client, sendmail_url, event, item, order, pos):
|
||||
event.settings.attendee_emails_asked = True
|
||||
|
||||
@@ -26,11 +26,12 @@ from pretix.base.exporter import BaseExporter
|
||||
from pretix.base.invoicing.transmission import (
|
||||
TransmissionProvider, transmission_providers,
|
||||
)
|
||||
from pretix.base.models import Invoice
|
||||
from pretix.base.models import Invoice, LogEntry
|
||||
from pretix.base.notifications import Notification, NotificationType
|
||||
from pretix.base.signals import (
|
||||
register_data_exporters, register_multievent_data_exporters,
|
||||
register_payment_providers, register_sales_channel_types,
|
||||
register_ticket_outputs,
|
||||
register_notification_types, register_payment_providers,
|
||||
register_sales_channel_types, register_ticket_outputs,
|
||||
)
|
||||
from pretix.presale.signals import html_head
|
||||
|
||||
@@ -144,3 +145,30 @@ class TestPeppolTransmissionProvider(TransmissionProvider):
|
||||
def transmit(self, invoice):
|
||||
invoice.transmission_status = Invoice.TRANSMISSION_STATUS_COMPLETED
|
||||
invoice.save()
|
||||
|
||||
|
||||
class OrgLevelTestNotificationType(NotificationType):
|
||||
required_permission = "organizer.settings.general:write" # does not make much sense, just for tests
|
||||
is_event_level = False
|
||||
action_type = "pretix.organizer.changed"
|
||||
verbose_name = "Organizer changed"
|
||||
|
||||
def __init__(self, organizer):
|
||||
super().__init__(organizer)
|
||||
|
||||
def build_notification(self, logentry: LogEntry):
|
||||
n = Notification(
|
||||
event=None,
|
||||
organizer=logentry.organizer,
|
||||
title="Organizer Changed",
|
||||
url="https://example.com"
|
||||
)
|
||||
n.add_attribute('Organizer', logentry.organizer.name)
|
||||
return n
|
||||
|
||||
|
||||
@receiver(register_notification_types, dispatch_uid="testdummy_register_notification_types")
|
||||
def testdummy_register_notification_types(sender, **kwargs):
|
||||
return (
|
||||
OrgLevelTestNotificationType(sender)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user