mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user