Let plugins prevent the download of individual tickets in an order (#3858)

* Let plugins allow/prevent the download of individual tickets in an order (#3836)

(extends the functionality of the allow_ticket_download signal)

(cherry picked from commit e20edab98f)

* fix bug where in some cases, only the first ticket could be downloaded
This commit is contained in:
Mira
2024-02-06 17:35:59 +01:00
committed by GitHub
parent 92e6ffc7ef
commit fa3265b1fb
11 changed files with 139 additions and 125 deletions

View File

@@ -55,6 +55,7 @@ from pretix.base.services.orders import (
send_expiry_warnings,
)
from pretix.plugins.banktransfer.payment import BankTransfer
from pretix.testutils.mock import mocker_context
from pretix.testutils.scope import classscope
@@ -820,7 +821,7 @@ class DownloadReminderTests(TestCase):
self.event = Event.objects.create(
organizer=self.o, name='Dummy', slug='dummy',
date_from=now() + timedelta(days=2),
plugins='pretix.plugins.banktransfer'
plugins='pretix.plugins.banktransfer,tests.testdummy'
)
self.order = Order.objects.create(
code='FOO', event=self.event, email='dummy@dummy.test',
@@ -853,6 +854,58 @@ class DownloadReminderTests(TestCase):
send_download_reminders(sender=self.event)
assert len(djmail.outbox) == 0
@classscope(attr='o')
def test_downloads_disabled_by_plugin(self):
with mocker_context() as mocker:
self.event.settings.mail_days_download_reminder = 2
from pretix.base.signals import allow_ticket_download
mocker.patch('pretix.base.signals.allow_ticket_download.send')
allow_ticket_download.send.return_value = [(None, [])]
send_download_reminders(sender=self.event)
assert len(djmail.outbox) == 0
@classscope(attr='o')
def test_downloads_all_allowed_by_plugin(self):
with mocker_context() as mocker:
self.event.settings.mail_days_download_reminder = 2
self.event.settings.mail_attach_tickets = True
self.event.settings.ticketoutput_testdummy__enabled = True
self.op2 = OrderPosition.objects.create(
order=self.order, item=self.ticket, variation=None,
price=Decimal("42.00"), attendee_name_parts={"full_name": "Mary"}, positionid=2
)
from pretix.base.signals import allow_ticket_download
mocker.patch('pretix.base.signals.allow_ticket_download.send')
allow_ticket_download.send.return_value = [(None, True)]
send_download_reminders(sender=self.event)
assert len(djmail.outbox) == 1
assert len(djmail.outbox[0].attachments) == 2
@classscope(attr='o')
def test_downloads_partially_disabled_by_plugin(self):
with mocker_context() as mocker:
self.event.settings.mail_days_download_reminder = 2
self.event.settings.mail_attach_tickets = True
self.event.settings.ticketoutput_testdummy__enabled = True
self.op2 = OrderPosition.objects.create(
order=self.order, item=self.ticket, variation=None,
price=Decimal("42.00"), attendee_name_parts={"full_name": "Mary"}, positionid=2
)
from pretix.base.signals import allow_ticket_download
mocker.patch('pretix.base.signals.allow_ticket_download.send')
allow_ticket_download.send.return_value = [(None, [self.op2])]
send_download_reminders(sender=self.event)
assert len(djmail.outbox) == 1
assert len(djmail.outbox[0].attachments) == 1
@classscope(attr='o')
def test_disabled(self):
send_download_reminders(sender=self.event)

View File

@@ -33,3 +33,7 @@ class DummyTicketOutput(BaseTicketOutput):
def generate(self, op):
return 'test.txt', 'text/plain', str(op.order.id)
@property
def multi_download_enabled(self) -> bool:
return False