mirror of
https://github.com/pretix/pretix.git
synced 2026-11-20 02:56:03 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4b65ba49d | ||
|
|
071b8baf61 | ||
|
|
ff6922e2ce | ||
|
|
428d28e744 | ||
|
|
0de0ad6cae |
No files matched your search
@@ -123,7 +123,7 @@ jobs:
|
||||
working-directory: ./src
|
||||
run: make all compress
|
||||
- name: Install Playwright browsers
|
||||
run: playwright install chromium --with-deps
|
||||
run: playwright install --with-deps
|
||||
- name: Run E2E tests
|
||||
working-directory: ./src
|
||||
run: PRETIX_CONFIG_FILE=tests/ci_postgres.cfg py.test tests/e2e/ -v --maxfail=10 --tracing=retain-on-failure
|
||||
|
||||
@@ -57,7 +57,6 @@ seating_plan integer If reserved sea
|
||||
seat_category_mapping object An object mapping categories of the seating plan
|
||||
(strings) to items in the event (integers or ``null``).
|
||||
last_modified datetime Last modification of this object
|
||||
comment string Internal comment for this subevent (or ``null``)
|
||||
===================================== ========================== =======================================================
|
||||
|
||||
.. versionchanged:: 2023.8.0
|
||||
@@ -118,10 +117,7 @@ Endpoints
|
||||
}
|
||||
],
|
||||
"variation_price_overrides": [],
|
||||
"meta_data": {},
|
||||
"frontpage_text": {},
|
||||
"last_modified": "2017-12-01T10:00:30Z",
|
||||
"comment": "internal comment"
|
||||
"meta_data": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -191,9 +187,7 @@ Endpoints
|
||||
}
|
||||
],
|
||||
"variation_price_overrides": [],
|
||||
"meta_data": {},
|
||||
"last_modified": "2017-12-01T10:00:30Z",
|
||||
"comment": ""
|
||||
"meta_data": {}
|
||||
}
|
||||
|
||||
|
||||
@@ -230,9 +224,7 @@ Endpoints
|
||||
}
|
||||
],
|
||||
"variation_price_overrides": [],
|
||||
"meta_data": {},
|
||||
"last_modified": "2017-12-01T10:00:30Z",
|
||||
"comment": ""
|
||||
"meta_data": {}
|
||||
}
|
||||
|
||||
|
||||
@@ -290,9 +282,7 @@ Endpoints
|
||||
}
|
||||
],
|
||||
"variation_price_overrides": [],
|
||||
"meta_data": {},
|
||||
"last_modified": "2017-12-01T10:00:30Z",
|
||||
"comment": ""
|
||||
"meta_data": {}
|
||||
}
|
||||
|
||||
:param organizer: The ``slug`` field of a valid organizer
|
||||
@@ -453,9 +443,7 @@ Endpoints
|
||||
}
|
||||
],
|
||||
"variation_price_overrides": [],
|
||||
"meta_data": {},
|
||||
"last_modified": "2017-12-01T10:00:30Z",
|
||||
"comment": ""
|
||||
"meta_data": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+3
-5
@@ -34,7 +34,7 @@ dependencies = [
|
||||
"celery==5.6.*",
|
||||
"chardet==5.2.*",
|
||||
"cryptography>=50.0.2",
|
||||
"css-inline==0.24.*",
|
||||
"css-inline==0.23.*",
|
||||
"defusedcsv>=3.0.0",
|
||||
"dnspython==2.9.*",
|
||||
"Django[argon2]==5.2.*,>=5.2.17",
|
||||
@@ -62,7 +62,7 @@ dependencies = [
|
||||
"geoip2==5.*",
|
||||
"isoweek",
|
||||
"jsonschema",
|
||||
"kombu==5.7.*",
|
||||
"kombu==5.6.*",
|
||||
"libsass==0.23.*",
|
||||
"lxml",
|
||||
"markdown==3.11.2",
|
||||
@@ -80,7 +80,6 @@ dependencies = [
|
||||
"psycopg2-binary",
|
||||
"pycountry",
|
||||
"pycparser==3.12",
|
||||
"pycryptodome==3.24.*",
|
||||
"pypdf==6.21.*",
|
||||
"python-bidi==0.6.*", # Support for Arabic in reportlab
|
||||
"python-dateutil==4.0.*",
|
||||
@@ -123,8 +122,7 @@ dev = [
|
||||
"pytest-sugar",
|
||||
"pytest-xdist==3.8.*",
|
||||
"pytest-playwright",
|
||||
"pytest-base-url",
|
||||
"pytest==9.2.*",
|
||||
"pytest==9.1.*",
|
||||
"playwright",
|
||||
"responses",
|
||||
"pypdfium2"
|
||||
|
||||
@@ -33,7 +33,7 @@ from rest_framework import status
|
||||
|
||||
from pretix.api.models import ApiCall
|
||||
from pretix.base.models import Organizer
|
||||
from pretix.helpers.database import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -60,7 +60,7 @@ class IdempotencyMiddleware:
|
||||
idempotency_key = request.headers.get('X-Idempotency-Key', '')
|
||||
|
||||
with transaction.atomic(durable=True):
|
||||
call, created = ApiCall.objects.select_for_update(**LOCK_SELF_NO_KEY).get_or_create(
|
||||
call, created = ApiCall.objects.select_for_update(of=OF_SELF).get_or_create(
|
||||
auth_hash=auth_hash,
|
||||
idempotency_key=idempotency_key,
|
||||
defaults={
|
||||
|
||||
@@ -378,7 +378,6 @@ class ItemSerializer(SalesChannelMigrationMixin, I18nAwareModelSerializer):
|
||||
def validate_bundles(self, value):
|
||||
if not self.instance:
|
||||
for b_data in value:
|
||||
ItemBundle.clean_count(b_data.get('count', 1))
|
||||
ItemBundle.clean_itemvar(self.context['event'], b_data.get('bundled_item'), b_data.get('bundled_variation'))
|
||||
return value
|
||||
|
||||
@@ -387,8 +386,8 @@ class ItemSerializer(SalesChannelMigrationMixin, I18nAwareModelSerializer):
|
||||
for addon_data in value:
|
||||
ItemAddOn.clean_categories(self.context['event'], None, self.instance, addon_data['addon_category'])
|
||||
ItemAddOn.clean_min_count(addon_data.get('min_count', 0))
|
||||
ItemAddOn.clean_max_count(addon_data.get('max_count', 1))
|
||||
ItemAddOn.clean_max_min_count(addon_data.get('max_count', 1), addon_data.get('min_count', 0))
|
||||
ItemAddOn.clean_max_count(addon_data.get('max_count', 0))
|
||||
ItemAddOn.clean_max_min_count(addon_data.get('max_count', 0), addon_data.get('min_count', 0))
|
||||
return value
|
||||
|
||||
def validate_program_times(self, value):
|
||||
|
||||
@@ -75,7 +75,7 @@ from pretix.base.services.checkin import (
|
||||
)
|
||||
from pretix.base.services.media import perform_media_exchange
|
||||
from pretix.base.signals import checkin_annulled
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
with scopes_disabled():
|
||||
class CheckinListFilter(FilterSet):
|
||||
@@ -1184,14 +1184,14 @@ class CheckinRPCAnnulView(views.APIView):
|
||||
if isinstance(request.auth, Device):
|
||||
qs = qs.filter(device=request.auth)
|
||||
ci = qs.select_for_update(
|
||||
**LOCK_SELF_NO_KEY,
|
||||
of=OF_SELF,
|
||||
).select_related("position", "position__order", "position__order__event").get(
|
||||
list__in=s.validated_data['lists'],
|
||||
nonce=s.validated_data['nonce'],
|
||||
)
|
||||
if connection.features.has_select_for_update_of and ci.position_id:
|
||||
# Lock position as well, can't do it with of= above because relation is nullable
|
||||
OrderPosition.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=ci.position_id)
|
||||
OrderPosition.objects.select_for_update(of=OF_SELF).get(pk=ci.position_id)
|
||||
|
||||
if not ci.successful or not ci.position:
|
||||
raise ValidationError("Cannot annul an unsuccessful checkin")
|
||||
|
||||
@@ -43,7 +43,7 @@ from pretix.base.models import (
|
||||
ReusableMedium,
|
||||
)
|
||||
from pretix.base.models.orders import PrintLog
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.dicts import merge_dicts
|
||||
|
||||
with scopes_disabled():
|
||||
@@ -119,7 +119,7 @@ class ReusableMediaViewSet(viewsets.ModelViewSet):
|
||||
|
||||
@transaction.atomic()
|
||||
def perform_update(self, serializer):
|
||||
rm = ReusableMedium.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.get_object().pk)
|
||||
rm = ReusableMedium.objects.select_for_update(of=OF_SELF).get(pk=self.get_object().pk)
|
||||
prev_linked_ops_pks = list(rm.linked_orderpositions.values_list("pk", flat=True))
|
||||
inst = serializer.save(identifier=serializer.instance.identifier, type=serializer.instance.type)
|
||||
linked_ops_pks = inst.linked_orderpositions.values_list("pk", flat=True)
|
||||
|
||||
@@ -102,7 +102,7 @@ from pretix.base.signals import (
|
||||
order_modified, order_paid, order_placed, register_ticket_outputs,
|
||||
)
|
||||
from pretix.control.signals import order_search_filter_q
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -600,7 +600,7 @@ class EventOrderViewSet(OrderViewSetMixin, viewsets.ModelViewSet):
|
||||
@transaction.atomic()
|
||||
def create_invoice(self, request, **kwargs):
|
||||
order = self.get_object()
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=order.pk)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=order.pk)
|
||||
has_inv = order.invoices.exists() and not (
|
||||
order.status in (Order.STATUS_PAID, Order.STATUS_PENDING)
|
||||
and order.invoices.filter(is_cancellation=True).count() >= order.invoices.filter(is_cancellation=False).count()
|
||||
@@ -2026,7 +2026,7 @@ class InvoiceViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
raise PermissionDenied('The invoice file is no longer stored on the server.')
|
||||
|
||||
with transaction.atomic(durable=True):
|
||||
invoice = Invoice.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=invoice.pk)
|
||||
invoice = Invoice.objects.select_for_update(of=OF_SELF).get(pk=invoice.pk)
|
||||
|
||||
if invoice.transmission_status == Invoice.TRANSMISSION_STATUS_INFLIGHT:
|
||||
raise CurrentlyInflightException()
|
||||
@@ -2080,7 +2080,7 @@ class InvoiceViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
elif inv.shredded:
|
||||
raise PermissionDenied('The invoice file is no longer stored on the server.')
|
||||
else:
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=inv.order_id)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=inv.order_id)
|
||||
c = generate_cancellation(inv)
|
||||
if invoice_qualified(order):
|
||||
inv = generate_invoice(order)
|
||||
|
||||
@@ -58,7 +58,7 @@ from pretix.base.models import (
|
||||
from pretix.base.plugins import (
|
||||
PLUGIN_LEVEL_EVENT, PLUGIN_LEVEL_EVENT_ORGANIZER_HYBRID,
|
||||
)
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.dicts import merge_dicts
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ class GiftCardViewSet(viewsets.ModelViewSet):
|
||||
def perform_update(self, serializer):
|
||||
if 'include_accepted' in self.request.GET:
|
||||
raise PermissionDenied("Accepted gift cards cannot be updated, use transact instead.")
|
||||
GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.get_object().pk)
|
||||
GiftCard.objects.select_for_update(of=OF_SELF).get(pk=self.get_object().pk)
|
||||
|
||||
value = serializer.validated_data.pop('value', None)
|
||||
|
||||
@@ -310,7 +310,7 @@ class GiftCardViewSet(viewsets.ModelViewSet):
|
||||
@action(detail=True, methods=["POST"])
|
||||
@transaction.atomic()
|
||||
def transact(self, request, **kwargs):
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.get_object().pk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=self.get_object().pk)
|
||||
value = serializers.DecimalField(max_digits=13, decimal_places=2).to_internal_value(
|
||||
request.data.get('value')
|
||||
)
|
||||
|
||||
@@ -42,7 +42,7 @@ from pretix.base.models import LogEntry
|
||||
from pretix.base.services.tasks import ProfiledTask, TransactionAwareTask
|
||||
from pretix.base.signals import periodic_task
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.celery import get_task_priority
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -678,7 +678,7 @@ def manually_retry_all_calls(webhook_id: int):
|
||||
with scope(organizer=webhook.organizer), transaction.atomic():
|
||||
for whcr in webhook.retries.select_for_update(
|
||||
skip_locked=connection.features.has_select_for_update_skip_locked,
|
||||
**LOCK_SELF_NO_KEY
|
||||
of=OF_SELF
|
||||
):
|
||||
send_webhook.apply_async(
|
||||
args=(whcr.logentry_id, whcr.action_type, whcr.webhook_id, whcr.retry_count),
|
||||
@@ -692,7 +692,7 @@ def schedule_webhook_retries_on_celery(sender, **kwargs):
|
||||
with transaction.atomic():
|
||||
for whcr in WebHookCallRetry.objects.select_for_update(
|
||||
skip_locked=connection.features.has_select_for_update_skip_locked,
|
||||
**LOCK_SELF_NO_KEY
|
||||
of=OF_SELF
|
||||
).filter(retry_not_before__lt=now()):
|
||||
send_webhook.apply_async(
|
||||
args=(whcr.logentry_id, whcr.action_type, whcr.webhook_id, whcr.retry_count),
|
||||
|
||||
@@ -40,7 +40,7 @@ from pretix.base.i18n import language
|
||||
from pretix.base.logentrytype_registry import make_link
|
||||
from pretix.base.models.datasync import OrderSyncQueue, OrderSyncResult
|
||||
from pretix.base.signals import PluginAwareRegistry
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -199,7 +199,7 @@ class OutboundSyncProvider:
|
||||
try:
|
||||
sq = (
|
||||
OrderSyncQueue.objects
|
||||
.select_for_update(**LOCK_SELF_NO_KEY, nowait=True)
|
||||
.select_for_update(of=OF_SELF, nowait=True)
|
||||
.select_related("order")
|
||||
.get(pk=queue_item.pk)
|
||||
)
|
||||
|
||||
@@ -93,7 +93,7 @@ class Gate(LoggedModel):
|
||||
if instance:
|
||||
qs = qs.exclude(pk=instance.pk)
|
||||
if qs.exists():
|
||||
raise ValidationError(_('This identifier is already used for a different gate.'))
|
||||
raise ValidationError(_('This identifier is already used for a different question.'))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.identifier:
|
||||
|
||||
@@ -1343,8 +1343,6 @@ class ItemVariation(models.Model):
|
||||
quotacounter[q] += b.count
|
||||
|
||||
for q, n in quotacounter.items():
|
||||
if n == 0:
|
||||
continue
|
||||
a = q.availability(count_waitinglist=count_waitinglist, _cache=_cache)
|
||||
if a[1] is None:
|
||||
continue
|
||||
@@ -1488,8 +1486,8 @@ class ItemAddOn(models.Model):
|
||||
|
||||
@staticmethod
|
||||
def clean_max_count(max_count):
|
||||
if max_count < 1:
|
||||
raise ValidationError(_('The maximum count needs to be greater than zero.'))
|
||||
if max_count < 0:
|
||||
raise ValidationError(_('The maximum count needs to be equal to or greater than zero.'))
|
||||
|
||||
@staticmethod
|
||||
def clean_max_min_count(max_count, min_count):
|
||||
@@ -1570,8 +1568,8 @@ class ItemBundle(models.Model):
|
||||
|
||||
@staticmethod
|
||||
def clean_count(count):
|
||||
if count < 1:
|
||||
raise ValidationError(_('The count needs to be greater than zero.'))
|
||||
if count < 0:
|
||||
raise ValidationError(_('The count needs to be equal to or greater than zero.'))
|
||||
|
||||
|
||||
class Question(LoggedModel):
|
||||
|
||||
@@ -85,7 +85,7 @@ from pretix.base.settings import PERSON_NAME_SCHEMES, ROUNDING_MODES
|
||||
from pretix.base.signals import allow_ticket_download, order_gracefully_delete
|
||||
from pretix.base.timemachine import time_machine_now
|
||||
|
||||
from ...helpers import LOCK_SELF_NO_KEY
|
||||
from ...helpers import OF_SELF
|
||||
from ...helpers.countries import CachedCountries, FastCountryField
|
||||
from ...helpers.models import NormalizedDecimalField
|
||||
from ...helpers.names import build_name
|
||||
@@ -1859,7 +1859,7 @@ class OrderPayment(models.Model):
|
||||
:param send_mail: Whether an email should be sent to the user about this event (default: ``True``).
|
||||
"""
|
||||
with transaction.atomic():
|
||||
locked_instance = OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.pk)
|
||||
locked_instance = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=self.pk)
|
||||
if locked_instance.state in (
|
||||
OrderPayment.PAYMENT_STATE_CONFIRMED,
|
||||
OrderPayment.PAYMENT_STATE_FAILED,
|
||||
@@ -1928,7 +1928,7 @@ class OrderPayment(models.Model):
|
||||
:raises Quota.QuotaExceededException: if the quota is exceeded and ``force`` is ``False``
|
||||
"""
|
||||
with transaction.atomic():
|
||||
locked_instance = OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.pk)
|
||||
locked_instance = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=self.pk)
|
||||
if locked_instance.state == self.PAYMENT_STATE_CONFIRMED:
|
||||
# Race condition detected, this payment is already confirmed
|
||||
logger.info('Confirmed payment {} but ignored due to likely race condition.'.format(
|
||||
|
||||
@@ -35,7 +35,7 @@ from pretix.base.email import get_email_context
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.models import User, Voucher
|
||||
from pretix.base.services.mail import mail
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
from ...helpers.names import build_name
|
||||
from .base import LoggedModel
|
||||
@@ -191,7 +191,7 @@ class WaitingListEntry(LoggedModel):
|
||||
raise WaitingListException(_('This entry is anonymized and can no longer be used.'))
|
||||
|
||||
with transaction.atomic():
|
||||
locked_wle = WaitingListEntry.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.pk)
|
||||
locked_wle = WaitingListEntry.objects.select_for_update(of=OF_SELF).get(pk=self.pk)
|
||||
locked_wle.event = event
|
||||
if locked_wle.voucher:
|
||||
raise WaitingListException(_('A voucher has already been sent to this person.'))
|
||||
|
||||
@@ -67,7 +67,7 @@ from pretix.base.signals import register_payment_providers
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
from pretix.base.templatetags.rich_text import rich_text
|
||||
from pretix.base.timemachine import time_machine_now
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.countries import CachedCountries
|
||||
from pretix.helpers.format import format_map
|
||||
from pretix.helpers.money import DecimalTextInput
|
||||
@@ -1645,7 +1645,7 @@ class GiftCardPayment(BasePaymentProvider):
|
||||
try:
|
||||
with transaction.atomic():
|
||||
try:
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=gcpk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=gcpk)
|
||||
except GiftCard.DoesNotExist:
|
||||
raise PaymentException(_("This gift card does not support this currency."))
|
||||
if gc.currency != self.event.currency: # noqa - just a safeguard
|
||||
|
||||
@@ -45,7 +45,7 @@ from pretix.base.services.tasks import ProfiledEventTask
|
||||
from pretix.base.services.tax import split_fee_for_taxes
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -286,7 +286,7 @@ def cancel_event(self, event: Event, subevent: int, auto_refund: bool,
|
||||
if dry_run:
|
||||
o = event.orders.get(pk=o)
|
||||
else:
|
||||
o = event.orders.select_for_update(**LOCK_SELF_NO_KEY).get(pk=o)
|
||||
o = event.orders.select_for_update(of=OF_SELF).get(pk=o)
|
||||
total = Decimal('0.00')
|
||||
fee = Decimal('0.00')
|
||||
positions = []
|
||||
|
||||
@@ -58,7 +58,7 @@ from pretix.base.models import (
|
||||
OrderPosition, QuestionOption,
|
||||
)
|
||||
from pretix.base.signals import checkin_created, periodic_task
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.database import conditional_atomic
|
||||
from pretix.helpers.jsonlogic import Logic
|
||||
from pretix.helpers.jsonlogic_boolalg import convert_to_dnf
|
||||
@@ -1049,7 +1049,7 @@ def perform_checkin(op: OrderPosition, clist: CheckinList, given_answers: dict,
|
||||
# Lock order positions, if it is an entry. We don't need it for exits, as a race condition wouldn't be problematic
|
||||
opqs = OrderPosition.all.select_related("order", "item")
|
||||
if type != Checkin.TYPE_EXIT and not simulate:
|
||||
opqs = opqs.select_for_update(**LOCK_SELF_NO_KEY)
|
||||
opqs = opqs.select_for_update(of=OF_SELF)
|
||||
op = opqs.get(pk=op.pk)
|
||||
|
||||
if not clist.all_products and op.item_id not in [i.pk for i in clist.limit_products.all()]:
|
||||
|
||||
@@ -50,7 +50,7 @@ from pretix.base.signals import (
|
||||
periodic_task, register_data_exporters, register_multievent_data_exporters,
|
||||
)
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY, repeatable_reads_transaction
|
||||
from pretix.helpers import OF_SELF, repeatable_reads_transaction
|
||||
from pretix.helpers.urls import mainreverse_absolute
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -501,7 +501,7 @@ def run_scheduled_exports(sender, **kwargs):
|
||||
qs = ScheduledEventExport.objects.filter(
|
||||
schedule_next_run__lt=now(),
|
||||
error_counter__lt=5,
|
||||
).select_for_update(skip_locked=connection.features.has_select_for_update_skip_locked, **LOCK_SELF_NO_KEY).select_related('event')
|
||||
).select_for_update(skip_locked=connection.features.has_select_for_update_skip_locked, of=OF_SELF).select_related('event')
|
||||
for s in qs:
|
||||
scheduled_event_export.apply_async(kwargs={
|
||||
'event': s.event_id,
|
||||
@@ -512,7 +512,7 @@ def run_scheduled_exports(sender, **kwargs):
|
||||
qs = ScheduledOrganizerExport.objects.filter(
|
||||
schedule_next_run__lt=now(),
|
||||
error_counter__lt=5,
|
||||
).select_for_update(skip_locked=connection.features.has_select_for_update_skip_locked, **LOCK_SELF_NO_KEY).select_related('organizer')
|
||||
).select_for_update(skip_locked=connection.features.has_select_for_update_skip_locked, of=OF_SELF).select_related('organizer')
|
||||
for s in qs:
|
||||
scheduled_organizer_export.apply_async(kwargs={
|
||||
'organizer': s.organizer_id,
|
||||
|
||||
@@ -67,7 +67,7 @@ from pretix.base.signals import (
|
||||
build_invoice_data, invoice_line_text, periodic_task,
|
||||
)
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers.database import LOCK_SELF_NO_KEY, rolledback_transaction
|
||||
from pretix.helpers.database import OF_SELF, rolledback_transaction
|
||||
from pretix.helpers.models import modelcopy
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -688,7 +688,7 @@ def send_invoices_to_organizer(sender, **kwargs):
|
||||
with transaction.atomic():
|
||||
qs = Invoice.objects.filter(
|
||||
sent_to_organizer__isnull=True
|
||||
).prefetch_related('event', 'order').select_for_update(**LOCK_SELF_NO_KEY, skip_locked=connection.features.has_select_for_update_skip_locked)
|
||||
).prefetch_related('event', 'order').select_for_update(of=OF_SELF, skip_locked=connection.features.has_select_for_update_skip_locked)
|
||||
for i in qs[:batch_size]:
|
||||
if i.event.settings.invoice_email_organizer:
|
||||
with language(i.event.settings.locale):
|
||||
@@ -724,7 +724,7 @@ def retry_stuck_invoices(sender, **kwargs):
|
||||
transmission_status=Invoice.TRANSMISSION_STATUS_INFLIGHT,
|
||||
transmission_date__lte=now() - timedelta(hours=48),
|
||||
).select_for_update(
|
||||
**LOCK_SELF_NO_KEY, skip_locked=connection.features.has_select_for_update_skip_locked
|
||||
of=OF_SELF, skip_locked=connection.features.has_select_for_update_skip_locked
|
||||
)
|
||||
batch_size = 5000
|
||||
for invoice in qs[:batch_size]:
|
||||
@@ -749,7 +749,7 @@ def send_pending_invoices(sender, **kwargs):
|
||||
transmission_status=Invoice.TRANSMISSION_STATUS_PENDING,
|
||||
created__lte=now() - timedelta(minutes=15),
|
||||
).select_for_update(
|
||||
**LOCK_SELF_NO_KEY, skip_locked=connection.features.has_select_for_update_skip_locked
|
||||
of=OF_SELF, skip_locked=connection.features.has_select_for_update_skip_locked
|
||||
)
|
||||
batch_size = 5000
|
||||
for invoice in qs[:batch_size]:
|
||||
@@ -760,7 +760,7 @@ def send_pending_invoices(sender, **kwargs):
|
||||
def transmit_invoice(sender, invoice_id, allow_retransmission=True, **kwargs):
|
||||
with transaction.atomic(durable='tests.testdummy' not in settings.INSTALLED_APPS):
|
||||
# We need durable=True for transactional correctness, but can't have it during tests
|
||||
invoice = Invoice.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=invoice_id)
|
||||
invoice = Invoice.objects.select_for_update(of=OF_SELF).get(pk=invoice_id)
|
||||
|
||||
if invoice.transmission_status == Invoice.TRANSMISSION_STATUS_INFLIGHT:
|
||||
logger.info(f"Did not transmit invoice {invoice.pk} due to being in inflight state.")
|
||||
|
||||
@@ -80,7 +80,7 @@ from pretix.base.signals import (
|
||||
email_filter, global_email_filter, periodic_task,
|
||||
)
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.format import (
|
||||
FormattedString, PlainHtmlAlternativeString, SafeFormatter, format_map,
|
||||
)
|
||||
@@ -412,7 +412,7 @@ def mail_send_task(self, **kwargs) -> bool:
|
||||
|
||||
with transaction.atomic():
|
||||
try:
|
||||
outgoing_mail = OutgoingMail.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=outgoing_mail)
|
||||
outgoing_mail = OutgoingMail.objects.select_for_update(of=OF_SELF).get(pk=outgoing_mail)
|
||||
except OutgoingMail.DoesNotExist:
|
||||
logger.info(f"Ignoring job for non existing email {outgoing_mail}")
|
||||
return False
|
||||
@@ -1107,7 +1107,7 @@ def retry_stuck_inflight_mails(sender, **kwargs):
|
||||
for m in OutgoingMail.objects.filter(
|
||||
status=OutgoingMail.STATUS_INFLIGHT,
|
||||
inflight_since__lt=now() - timedelta(hours=1),
|
||||
).select_for_update(**LOCK_SELF_NO_KEY, skip_locked=connection.features.has_select_for_update_skip_locked):
|
||||
).select_for_update(of=OF_SELF, skip_locked=connection.features.has_select_for_update_skip_locked):
|
||||
m.status = OutgoingMail.STATUS_QUEUED
|
||||
m.save()
|
||||
mail_send_task.apply_async(kwargs={"outgoing_mail": m.pk})
|
||||
|
||||
@@ -33,7 +33,7 @@ from pretix.base.models import (
|
||||
OrderPosition, SubEvent,
|
||||
)
|
||||
from pretix.base.timemachine import time_machine_now
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
|
||||
def membership_validity(item: Item, subevent: Optional[SubEvent], event: Event):
|
||||
@@ -125,7 +125,7 @@ def validate_memberships_in_order(customer: Customer, positions: List[AbstractPo
|
||||
base_qs = Membership.objects.with_usages(ignored_order=ignored_order)
|
||||
|
||||
if lock:
|
||||
base_qs = base_qs.select_for_update(**LOCK_SELF_NO_KEY)
|
||||
base_qs = base_qs.select_for_update(of=OF_SELF)
|
||||
|
||||
membership_cache = base_qs\
|
||||
.select_related('membership_type')\
|
||||
|
||||
@@ -107,7 +107,7 @@ from pretix.base.signals import (
|
||||
)
|
||||
from pretix.base.timemachine import time_machine_now, time_machine_now_assigned
|
||||
from pretix.celery_app import app
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.models import modelcopy
|
||||
from pretix.helpers.periodic import minimum_interval
|
||||
from pretix.presale.productlist import prepare_item_list_for_shop
|
||||
@@ -246,7 +246,7 @@ def reactivate_order(order: Order, force: bool=False, user: User=None, auth=None
|
||||
Voucher.objects.filter(pk=position.voucher.pk).update(redeemed=Greatest(0, F('redeemed') + 1))
|
||||
|
||||
for gc in position.issued_gift_cards.all():
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=gc.pk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=gc.pk)
|
||||
gc.transactions.create(value=position.price, order=order, acceptor=order.event.organizer)
|
||||
gc.log_action(
|
||||
action='pretix.giftcards.transaction.manual',
|
||||
@@ -524,7 +524,7 @@ def _cancel_order(order, user=None, send_mail: bool=True, api_token=None, device
|
||||
# If new actions are added to this function, make sure to add the reverse operation to reactivate_order()
|
||||
with transaction.atomic():
|
||||
if isinstance(order, int):
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=order)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=order)
|
||||
if isinstance(user, int):
|
||||
user = User.objects.get(pk=user)
|
||||
if isinstance(api_token, int):
|
||||
@@ -550,7 +550,7 @@ def _cancel_order(order, user=None, send_mail: bool=True, api_token=None, device
|
||||
|
||||
for position in order.positions.all():
|
||||
for gc in position.issued_gift_cards.all():
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=gc.pk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=gc.pk)
|
||||
if gc.value < position.price:
|
||||
raise OrderError(
|
||||
_('This order can not be canceled since the gift card {card} purchased in '
|
||||
@@ -1489,7 +1489,7 @@ def send_expiry_warnings(sender, **kwargs):
|
||||
|
||||
if days and (o.expires - today).days <= days:
|
||||
with transaction.atomic():
|
||||
o = Order.objects.select_related('event').select_for_update(**LOCK_SELF_NO_KEY).get(pk=o.pk)
|
||||
o = Order.objects.select_related('event').select_for_update(of=OF_SELF).get(pk=o.pk)
|
||||
if o.status != Order.STATUS_PENDING or o.expiry_reminder_sent:
|
||||
# Race condition
|
||||
continue
|
||||
@@ -1574,7 +1574,7 @@ def send_download_reminders(sender, **kwargs):
|
||||
continue
|
||||
|
||||
with transaction.atomic():
|
||||
o = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=o.pk)
|
||||
o = Order.objects.select_for_update(of=OF_SELF).get(pk=o.pk)
|
||||
if o.download_reminder_sent:
|
||||
# Race condition
|
||||
continue
|
||||
@@ -2560,7 +2560,7 @@ class OrderChangeManager:
|
||||
elif isinstance(op, self.CancelOperation):
|
||||
position = position_cache.setdefault(op.position.pk, op.position)
|
||||
for gc in position.issued_gift_cards.all():
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=gc.pk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=gc.pk)
|
||||
if gc.value < position.price:
|
||||
raise OrderError(_(
|
||||
'A position can not be canceled since the gift card {card} purchased in this order has '
|
||||
@@ -2587,7 +2587,7 @@ class OrderChangeManager:
|
||||
for opa in position.addons.all():
|
||||
opa = position_cache.setdefault(opa.pk, opa)
|
||||
for gc in opa.issued_gift_cards.all():
|
||||
gc = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=gc.pk)
|
||||
gc = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=gc.pk)
|
||||
if gc.value < opa.position.price:
|
||||
raise OrderError(_(
|
||||
'A position can not be canceled since the gift card {card} purchased in this order has '
|
||||
@@ -3162,7 +3162,7 @@ class OrderChangeManager:
|
||||
self._check_order_size()
|
||||
|
||||
with transaction.atomic():
|
||||
locked_instance = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.order.pk)
|
||||
locked_instance = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
|
||||
if locked_instance.last_modified != self.order.last_modified:
|
||||
raise OrderError(error_messages['race_condition'])
|
||||
|
||||
@@ -3466,9 +3466,9 @@ def change_payment_provider(order: Order, payment_provider, amount=None, new_pay
|
||||
|
||||
open_payment = None
|
||||
if new_payment:
|
||||
lp = order.payments.select_for_update(**LOCK_SELF_NO_KEY).exclude(pk=new_payment.pk).last()
|
||||
lp = order.payments.select_for_update(of=OF_SELF).exclude(pk=new_payment.pk).last()
|
||||
else:
|
||||
lp = order.payments.select_for_update(**LOCK_SELF_NO_KEY).last()
|
||||
lp = order.payments.select_for_update(of=OF_SELF).last()
|
||||
|
||||
if lp and lp.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED):
|
||||
open_payment = lp
|
||||
@@ -3515,7 +3515,7 @@ def change_payment_provider(order: Order, payment_provider, amount=None, new_pay
|
||||
new_invoice = None
|
||||
if recreate_invoices:
|
||||
# Lock to prevent duplicate invoice creation
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=order.pk)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=order.pk)
|
||||
|
||||
i = order.invoices.filter(is_cancellation=False).last()
|
||||
has_active_invoice = i and not i.canceled
|
||||
|
||||
@@ -340,14 +340,7 @@ class LinkifyAndCleanExtension(Extension):
|
||||
)
|
||||
|
||||
|
||||
class SnippetExtension(markdown.extensions.Extension):
|
||||
def extendMarkdown(self, md, *args, **kwargs):
|
||||
md.parser.blockprocessors.deregister('olist')
|
||||
md.parser.blockprocessors.deregister('ulist')
|
||||
md.parser.blockprocessors.deregister('quote')
|
||||
|
||||
|
||||
def _get_email_markdown(allowed_tags=None, allowed_attributes=ALLOWED_ATTRIBUTES, snippet=False, context=None):
|
||||
def markdown_compile_email(source, allowed_tags=None, allowed_attributes=ALLOWED_ATTRIBUTES, snippet=False, context=None):
|
||||
if allowed_tags is None:
|
||||
allowed_tags = ALLOWED_TAGS_SNIPPET if snippet else ALLOWED_TAGS
|
||||
|
||||
@@ -388,16 +381,20 @@ def _get_email_markdown(allowed_tags=None, allowed_attributes=ALLOWED_ATTRIBUTES
|
||||
]
|
||||
if snippet:
|
||||
exts.append(SnippetExtension())
|
||||
|
||||
return markdown.Markdown(extensions=exts)
|
||||
return markdown.markdown(
|
||||
source,
|
||||
extensions=exts
|
||||
)
|
||||
|
||||
|
||||
def markdown_compile_email(source, allowed_tags=None, allowed_attributes=ALLOWED_ATTRIBUTES, snippet=False, context=None):
|
||||
md = _get_email_markdown(allowed_tags, allowed_attributes, snippet, context)
|
||||
return md.convert(source)
|
||||
class SnippetExtension(markdown.extensions.Extension):
|
||||
def extendMarkdown(self, md, *args, **kwargs):
|
||||
md.parser.blockprocessors.deregister('olist')
|
||||
md.parser.blockprocessors.deregister('ulist')
|
||||
md.parser.blockprocessors.deregister('quote')
|
||||
|
||||
|
||||
def _get_markdown(linker, snippet=False):
|
||||
def markdown_compile(source, linker, snippet=False):
|
||||
tags = ALLOWED_TAGS_SNIPPET if snippet else ALLOWED_TAGS
|
||||
exts = [
|
||||
'markdown.extensions.sane_lists',
|
||||
@@ -412,13 +409,10 @@ def _get_markdown(linker, snippet=False):
|
||||
]
|
||||
if snippet:
|
||||
exts.append(SnippetExtension())
|
||||
|
||||
return markdown.Markdown(extensions=exts)
|
||||
|
||||
|
||||
def markdown_compile(source, linker, snippet=False):
|
||||
md = _get_markdown(linker, snippet)
|
||||
return md.convert(source)
|
||||
return markdown.markdown(
|
||||
source,
|
||||
extensions=exts
|
||||
)
|
||||
|
||||
|
||||
@register.filter
|
||||
@@ -451,25 +445,3 @@ def rich_text_snippet(text: str, **kwargs):
|
||||
)
|
||||
body_md = markdown_compile(text, linker, snippet=True)
|
||||
return mark_safe(body_md)
|
||||
|
||||
|
||||
def _md_escape(md: markdown.Markdown, plain: str):
|
||||
escaped_chars = md.ESCAPED_CHARS
|
||||
translation_map = {ord(x): f"\\{x}" for x in escaped_chars}
|
||||
return plain.translate(translation_map)
|
||||
|
||||
|
||||
def markdown_escape(plain: str) -> str:
|
||||
"""
|
||||
Escape formatting characters in markdown with backslash using the default markdown renderer config.
|
||||
"""
|
||||
md = _get_markdown(bleach.Linker())
|
||||
return _md_escape(md, plain)
|
||||
|
||||
|
||||
def markdown_email_escape(plain: str) -> str:
|
||||
"""
|
||||
Escape formatting characters in markdown with backslash using the default email markdown renderer config.
|
||||
"""
|
||||
md = _get_email_markdown(None, False)
|
||||
return _md_escape(md, plain)
|
||||
@@ -1207,11 +1207,6 @@ class ItemAddOnForm(I18nModelForm):
|
||||
}
|
||||
)
|
||||
self.fields['addon_category'].widget.choices = self.fields['addon_category'].choices
|
||||
self.fields['max_count'] = forms.IntegerField(
|
||||
min_value=1,
|
||||
label=self.fields['max_count'].label,
|
||||
widget=forms.NumberInput(attrs={'placeholder': '1'}),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ItemAddOn
|
||||
@@ -1324,12 +1319,6 @@ class ItemBundleForm(I18nModelForm):
|
||||
self.fields['itemvar'].choices = choices
|
||||
change_decimal_field(self.fields['designated_price'], self.event.currency)
|
||||
|
||||
self.fields['count'] = forms.IntegerField(
|
||||
min_value=1,
|
||||
label=self.fields['count'].label,
|
||||
widget=forms.NumberInput(attrs={'placeholder': '1'}),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
d = super().clean()
|
||||
if not self.cleaned_data.get('designated_price'):
|
||||
|
||||
@@ -66,7 +66,7 @@ from pretix.base.forms.auth import (
|
||||
)
|
||||
from pretix.base.metrics import pretix_failed_logins, pretix_successful_logins
|
||||
from pretix.base.models import TeamInvite, U2FDevice, User, WebAuthnDevice
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.http import get_client_ip, redirect_to_url
|
||||
from pretix.helpers.ratelimit import rate_limit, rate_limit_reset
|
||||
from pretix.helpers.security import handle_login_source, session_login
|
||||
@@ -401,7 +401,7 @@ class Recover(TemplateView):
|
||||
with transaction.atomic():
|
||||
# Check token in transaction to prevent race condition
|
||||
try:
|
||||
user = User.objects.select_for_update(**LOCK_SELF_NO_KEY).get(id=self.request.GET.get('id'), auth_backend='native')
|
||||
user = User.objects.select_for_update(of=OF_SELF).get(id=self.request.GET.get('id'), auth_backend='native')
|
||||
except User.DoesNotExist:
|
||||
return self.invalid('unknownuser')
|
||||
if not default_token_generator.check_token(user, self.request.GET.get('token')):
|
||||
|
||||
@@ -43,7 +43,7 @@ from pretix.control.permissions import (
|
||||
)
|
||||
from pretix.control.signals import order_info
|
||||
from pretix.control.views.orders import OrderView
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
|
||||
|
||||
@receiver(order_info, dispatch_uid="datasync_control_order_info")
|
||||
@@ -83,7 +83,7 @@ class ControlSyncJob(OrderView):
|
||||
elif self.request.POST.get("cancel_job"):
|
||||
with transaction.atomic():
|
||||
try:
|
||||
job = self.order.queued_sync_jobs.select_for_update(**LOCK_SELF_NO_KEY).get(
|
||||
job = self.order.queued_sync_jobs.select_for_update(of=OF_SELF).get(
|
||||
pk=self.request.POST.get("cancel_job")
|
||||
)
|
||||
except OrderSyncQueue.DoesNotExist:
|
||||
@@ -97,7 +97,7 @@ class ControlSyncJob(OrderView):
|
||||
elif self.request.POST.get("run_job_now"):
|
||||
with transaction.atomic():
|
||||
try:
|
||||
job = self.order.queued_sync_jobs.select_for_update(**LOCK_SELF_NO_KEY).get(
|
||||
job = self.order.queued_sync_jobs.select_for_update(of=OF_SELF).get(
|
||||
pk=self.request.POST.get("run_job_now")
|
||||
)
|
||||
except OrderSyncQueue.DoesNotExist:
|
||||
|
||||
@@ -135,7 +135,7 @@ from pretix.control.permissions import (
|
||||
)
|
||||
from pretix.control.signals import order_search_forms
|
||||
from pretix.control.views import PaginationMixin
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
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
|
||||
@@ -1161,7 +1161,7 @@ class OrderRefundView(OrderView):
|
||||
|
||||
@transaction.atomic()
|
||||
def perform_refund(self, comment, full_refund, payments):
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.order.pk)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
|
||||
|
||||
if self.request.POST.get("last_known_refund_id", "0") != str(self.order.refunds.aggregate(m=Max("id"))["m"] or 0):
|
||||
messages.error(self.request, _('The refund was prevented due to a refund already being processed at the '
|
||||
@@ -1477,7 +1477,7 @@ class OrderTransition(OrderView):
|
||||
@transaction.atomic()
|
||||
def post(self, request, *args, **kwargs):
|
||||
to = self.request.POST.get('status', '')
|
||||
self.order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.order.pk)
|
||||
self.order = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
|
||||
|
||||
if self.order.status in (Order.STATUS_PENDING, Order.STATUS_EXPIRED) and to == 'p' and self.mark_paid_form.is_valid():
|
||||
ps = self.mark_paid_form.cleaned_data['amount']
|
||||
@@ -1618,7 +1618,7 @@ class OrderInvoiceCreate(OrderView):
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.order.pk)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
|
||||
has_inv = order.invoices.exists() and not (
|
||||
order.status in (Order.STATUS_PAID, Order.STATUS_PENDING)
|
||||
and order.invoices.filter(is_cancellation=True).count() >= order.invoices.filter(is_cancellation=False).count()
|
||||
@@ -1727,7 +1727,7 @@ class OrderInvoiceRetransmit(OrderView):
|
||||
def post(self, *args, **kwargs):
|
||||
with transaction.atomic(durable=True):
|
||||
try:
|
||||
invoice = self.order.invoices.select_for_update(**LOCK_SELF_NO_KEY).get(pk=kwargs.get("id"))
|
||||
invoice = self.order.invoices.select_for_update(of=OF_SELF).get(pk=kwargs.get("id"))
|
||||
except Invoice.DoesNotExist:
|
||||
messages.error(self.request, _('Unknown invoice.'))
|
||||
return redirect(self.get_order_url())
|
||||
@@ -1757,7 +1757,7 @@ class OrderInvoiceReissue(OrderView):
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
order = Order.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.order.pk)
|
||||
order = Order.objects.select_for_update(of=OF_SELF).get(pk=self.order.pk)
|
||||
try:
|
||||
inv = order.invoices.get(pk=kwargs.get('id'))
|
||||
except Invoice.DoesNotExist:
|
||||
|
||||
@@ -139,7 +139,7 @@ from pretix.control.permissions import (
|
||||
from pretix.control.signals import nav_organizer
|
||||
from pretix.control.views import LargeResultSetPaginator, PaginationMixin
|
||||
from pretix.control.views.mailsetup import MailSettingsSetupView
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY, GroupConcat
|
||||
from pretix.helpers import OF_SELF, GroupConcat
|
||||
from pretix.helpers.compat import CompatDeleteView
|
||||
from pretix.helpers.dicts import merge_dicts
|
||||
from pretix.helpers.format import SafeFormatter, format_map
|
||||
@@ -1795,7 +1795,7 @@ class GiftCardDetailView(OrganizerDetailViewMixin, OrganizerPermissionRequiredMi
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not request.user.has_organizer_permission(request.organizer, "organizer.giftcards:write", request=request):
|
||||
raise PermissionDenied()
|
||||
self.object = GiftCard.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.get_object().pk)
|
||||
self.object = GiftCard.objects.select_for_update(of=OF_SELF).get(pk=self.get_object().pk)
|
||||
if 'revert' in request.POST:
|
||||
t = get_object_or_404(self.object.transactions.all(), pk=request.POST.get('revert'), order__isnull=False)
|
||||
if self.object.value - t.value < Decimal('0.00'):
|
||||
|
||||
@@ -29,6 +29,7 @@ from django.db.models import (
|
||||
Aggregate, Expression, F, Field, Func, IntegerField, JSONField, Lookup,
|
||||
OrderBy, Value,
|
||||
)
|
||||
from django.utils.functional import lazy
|
||||
|
||||
|
||||
class DummyRollbackException(Exception):
|
||||
@@ -212,12 +213,9 @@ class PostgresWindowFrame(Expression):
|
||||
}
|
||||
|
||||
|
||||
# OF_SELF is kept for backwards-compatibility. Since we do not need MySQL any more, you can just use `of=("self",)`
|
||||
# SQLite will not fail, but just ignore it
|
||||
OF_SELF = ("self",)
|
||||
# Provided as a constant for convenience because `("self",)` is annoying to type and this way we can more easily update
|
||||
# things across the codebase if required
|
||||
LOCK_SELF_NO_KEY = {"of": OF_SELF, "no_key": True}
|
||||
# This is a short-hand for .select_for_update(of=("self,")), that falls back gracefully on databases that don't support
|
||||
# the SELECT FOR UPDATE OF ... query.
|
||||
OF_SELF = lazy(lambda: ("self",) if connection.features.has_select_for_update_of else (), tuple)()
|
||||
|
||||
|
||||
def get_deterministic_ordering(model, ordering):
|
||||
|
||||
@@ -51,7 +51,6 @@ from pretix.base.forms import I18nMarkdownTextarea
|
||||
from pretix.base.models import InvoiceAddress, Order, OrderPayment, OrderRefund
|
||||
from pretix.base.payment import BasePaymentProvider
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
from pretix.base.templatetags.rich_text import markdown_email_escape
|
||||
from pretix.helpers.payment import generate_payment_qr_codes
|
||||
from pretix.plugins.banktransfer.templatetags.ibanformat import ibanformat
|
||||
from pretix.presale.views.cart import cart_session
|
||||
@@ -309,7 +308,7 @@ class BankTransfer(BasePaymentProvider):
|
||||
(_("Reference"), self._code(order, force=True)),
|
||||
(_("Amount"), money_filter(payment.amount, self.event.currency)),
|
||||
)
|
||||
t += md_nl2br.join([f"**{markdown_email_escape(k)}:** {markdown_email_escape(v)}" for k, v in bankdetails])
|
||||
t += md_nl2br.join([f"**{k}:** {v}" for k, v in bankdetails])
|
||||
if self.settings.get('bank_details', as_type=LazyI18nString):
|
||||
t += md_nl2br
|
||||
t += str(self.settings.get('bank_details', as_type=LazyI18nString))
|
||||
|
||||
@@ -56,7 +56,7 @@ from pretix.base.forms.questions import guess_country
|
||||
from pretix.base.models import Event, Order, OrderPayment, OrderRefund, Quota
|
||||
from pretix.base.payment import BasePaymentProvider, PaymentException
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.urls import mainreverse_absolute
|
||||
from pretix.multidomain.urlreverse import eventreverse, eventreverse_absolute
|
||||
from pretix.plugins.paypal2.client.core.environment import (
|
||||
@@ -675,7 +675,7 @@ class PaypalMethod(BasePaymentProvider):
|
||||
return False
|
||||
|
||||
def _execute_payment(self, request: HttpRequest, payment: OrderPayment):
|
||||
payment = OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=payment.pk)
|
||||
payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=payment.pk)
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_CONFIRMED:
|
||||
# payment is already confirmed; possible return-view/webhook race-condition
|
||||
return
|
||||
@@ -1002,7 +1002,7 @@ class PaypalMethod(BasePaymentProvider):
|
||||
self.init_api()
|
||||
with transaction.atomic():
|
||||
# Lock payment that we are creating refund for to prevent race condition with incoming webhook
|
||||
OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=refund.payment_id)
|
||||
OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=refund.payment_id)
|
||||
try:
|
||||
pp_payment = None
|
||||
payment_info_data = None
|
||||
|
||||
@@ -61,7 +61,7 @@ from pretix.base.payment import PaymentException
|
||||
from pretix.base.services.cart import add_payment_to_cart, get_fees
|
||||
from pretix.base.settings import GlobalSettingsObject
|
||||
from pretix.control.permissions import event_permission_required
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.http import redirect_to_url
|
||||
from pretix.multidomain.urlreverse import eventreverse
|
||||
from pretix.plugins.paypal2.client.customer.partners_merchantintegrations_get_request import (
|
||||
@@ -460,7 +460,7 @@ def webhook(request, *args, **kwargs):
|
||||
|
||||
with transaction.atomic():
|
||||
# Lock payment in case a refund is currently still running
|
||||
payment = OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=payment.pk)
|
||||
payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=payment.pk)
|
||||
known_refunds = {r.info_data.get('id'): r for r in payment.refunds.all()}
|
||||
if refund['id'] not in known_refunds:
|
||||
payment.create_external_refund(
|
||||
|
||||
@@ -55,7 +55,7 @@ from pretix.base.signals import (
|
||||
EventPluginSignal, event_copy_data, periodic_task,
|
||||
)
|
||||
from pretix.control.signals import nav_event
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.plugins.sendmail.models import Rule, ScheduledMail
|
||||
from pretix.plugins.sendmail.views import OrderSendView, WaitinglistSendView
|
||||
|
||||
@@ -206,7 +206,7 @@ def sendmail_run_rules(sender, **kwargs):
|
||||
|
||||
with transaction.atomic(durable=True):
|
||||
m = ScheduledMail.objects.select_for_update(
|
||||
**LOCK_SELF_NO_KEY,
|
||||
of=OF_SELF,
|
||||
skip_locked=connection.features.has_select_for_update_skip_locked
|
||||
).filter(pk=m_id).first()
|
||||
if not m or m.state not in (ScheduledMail.STATE_SCHEDULED, ScheduledMail.STATE_FAILED):
|
||||
|
||||
@@ -72,7 +72,7 @@ from pretix.base.payment import (
|
||||
from pretix.base.plugins import get_all_plugins
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
from pretix.base.views.redirect import safelink
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.countries import CachedCountries
|
||||
from pretix.helpers.http import get_client_ip
|
||||
from pretix.helpers.urls import mainreverse_absolute
|
||||
@@ -753,7 +753,7 @@ class StripeMethod(BasePaymentProvider):
|
||||
self._init_api()
|
||||
|
||||
payment_info = refund.payment.info_data
|
||||
OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=refund.payment.pk)
|
||||
OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=refund.payment.pk)
|
||||
|
||||
if not payment_info:
|
||||
raise PaymentException(_('No payment information found.'))
|
||||
|
||||
@@ -24,13 +24,14 @@ from django.urls import include, re_path
|
||||
from pretix.multidomain import event_url
|
||||
|
||||
from .views import (
|
||||
OrganizerSettingsFormView, ScaReturnView, ScaView, oauth_disconnect,
|
||||
oauth_return, webhook,
|
||||
OrganizerSettingsFormView, ReturnView, ScaReturnView, ScaView,
|
||||
oauth_disconnect, oauth_return, webhook,
|
||||
)
|
||||
|
||||
event_patterns = [
|
||||
re_path(r'^stripe/', include([
|
||||
event_url(r'^webhook/$', webhook, name='webhook', require_live=False),
|
||||
re_path(r'^return/(?P<order>[^/]+)/(?P<hash>[^/]+)/(?P<payment>[0-9]+)/$', ReturnView.as_view(), name='return'),
|
||||
re_path(r'^sca/(?P<order>[^/]+)/(?P<hash>[^/]+)/(?P<payment>[0-9]+)/$', ScaView.as_view(), name='sca'),
|
||||
re_path(r'^sca/(?P<order>[^/]+)/(?P<hash>[^/]+)/(?P<payment>[0-9]+)/return/$',
|
||||
ScaReturnView.as_view(), name='sca.return'),
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# This file is part of pretix (Community Edition).
|
||||
#
|
||||
# Copyright (C) 2014-2020 Raphael Michel and contributors
|
||||
# Copyright (C) 2020-today pretix GmbH and contributors
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
|
||||
# Public License as published by the Free Software Foundation in version 3 of the License.
|
||||
#
|
||||
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
|
||||
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
|
||||
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
|
||||
# this file, see <https://pretix.eu/about/en/license>.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
@@ -60,7 +60,7 @@ from pretix.control.permissions import (
|
||||
)
|
||||
from pretix.control.views.event import DecoupleMixin
|
||||
from pretix.control.views.organizer import OrganizerDetailViewMixin
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.http import redirect_to_url
|
||||
from pretix.multidomain.urlreverse import eventreverse
|
||||
from pretix.plugins.stripe.forms import OrganizerStripeSettingsForm
|
||||
@@ -193,6 +193,10 @@ def webhook(request, *args, **kwargs):
|
||||
func = charge_webhook
|
||||
objid = event_json['data']['object']['charge']
|
||||
lookup_ids = [objid]
|
||||
elif event_json['data']['object']['object'] == "source":
|
||||
func = source_webhook
|
||||
objid = event_json['data']['object']['id']
|
||||
lookup_ids = [objid]
|
||||
elif event_json['data']['object']['object'] == "payment_intent":
|
||||
func = paymentintent_webhook
|
||||
objid = event_json['data']['object']['id']
|
||||
@@ -279,13 +283,13 @@ def charge_webhook(event, event_json, charge_id, rso):
|
||||
|
||||
with transaction.atomic():
|
||||
if payment:
|
||||
payment = OrderPayment.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=payment.pk)
|
||||
payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=payment.pk)
|
||||
else:
|
||||
payment = order.payments.filter(
|
||||
info__icontains=charge['id'],
|
||||
provider__startswith='stripe',
|
||||
amount=prov._amount_to_decimal(charge['amount']),
|
||||
).select_for_update(**LOCK_SELF_NO_KEY).last()
|
||||
).select_for_update(of=OF_SELF).last()
|
||||
if not payment:
|
||||
payment = order.payments.create(
|
||||
state=OrderPayment.PAYMENT_STATE_CREATED,
|
||||
@@ -346,6 +350,79 @@ def charge_webhook(event, event_json, charge_id, rso):
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
def source_webhook(event, event_json, source_id, rso):
|
||||
import stripe
|
||||
|
||||
from pretix.plugins.stripe.payment import StripeCC
|
||||
|
||||
prov = StripeCC(event)
|
||||
prov._init_api()
|
||||
try:
|
||||
src = stripe.Source.retrieve(source_id, **prov.api_kwargs)
|
||||
except stripe.error.StripeError:
|
||||
logger.exception('Stripe error on webhook. Event data: %s' % str(event_json))
|
||||
return HttpResponse('Charge not found', status=500)
|
||||
|
||||
metadata = src['metadata']
|
||||
if 'event' not in metadata:
|
||||
return HttpResponse('Event not given in charge metadata', status=200)
|
||||
|
||||
if int(metadata['event']) != event.pk:
|
||||
return HttpResponse('Not interested in this event', status=200)
|
||||
|
||||
with transaction.atomic():
|
||||
if rso and rso.payment:
|
||||
order = rso.payment.order
|
||||
payment = rso.payment
|
||||
elif rso:
|
||||
order = rso.order
|
||||
payment = None
|
||||
else:
|
||||
try:
|
||||
order = event.orders.get(id=metadata['order'])
|
||||
except Order.DoesNotExist:
|
||||
return HttpResponse('Order not found', status=200)
|
||||
payment = None
|
||||
|
||||
if payment:
|
||||
payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=payment.pk)
|
||||
else:
|
||||
payment = order.payments.filter(
|
||||
info__icontains=src['id'],
|
||||
provider__startswith='stripe',
|
||||
amount=prov._amount_to_decimal(src['amount']) if src['amount'] is not None else order.total,
|
||||
).select_for_update(of=OF_SELF).last()
|
||||
if not payment:
|
||||
payment = order.payments.create(
|
||||
state=OrderPayment.PAYMENT_STATE_CREATED,
|
||||
provider=SOURCE_TYPES.get(src['type'], 'stripe'),
|
||||
amount=prov._amount_to_decimal(src['amount']) if src['amount'] is not None else order.total,
|
||||
info=str(src),
|
||||
)
|
||||
|
||||
if payment.provider != prov.identifier:
|
||||
prov = payment.payment_provider
|
||||
prov._init_api()
|
||||
|
||||
order.log_action('pretix.plugins.stripe.event', data=event_json)
|
||||
go = (event_json['type'] == 'source.chargeable' and
|
||||
payment.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED) and
|
||||
src.status == 'chargeable')
|
||||
if go:
|
||||
try:
|
||||
prov._charge_source(None, source_id, payment)
|
||||
except PaymentException:
|
||||
logger.exception('Webhook error')
|
||||
elif src.status == 'failed':
|
||||
payment.fail(info=str(src))
|
||||
elif src.status == 'canceled' and payment.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED):
|
||||
payment.info = str(src)
|
||||
payment.state = OrderPayment.PAYMENT_STATE_CANCELED
|
||||
payment.save()
|
||||
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
def paymentintent_webhook(event, event_json, paymentintent_id, rso):
|
||||
import stripe
|
||||
|
||||
@@ -419,6 +496,59 @@ class StripeOrderView:
|
||||
}) + ('?paid=yes' if self.order.status == Order.STATUS_PAID else ''))
|
||||
|
||||
|
||||
@method_decorator(xframe_options_exempt, 'dispatch')
|
||||
class ReturnView(StripeOrderView, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
import stripe
|
||||
|
||||
prov = self.pprov
|
||||
prov._init_api()
|
||||
try:
|
||||
src = stripe.Source.retrieve(request.GET.get('source'), **prov.api_kwargs)
|
||||
except stripe.error.InvalidRequestError:
|
||||
logger.exception('Could not retrieve source')
|
||||
messages.error(self.request, _('Sorry, there was an error in the payment process. Please check the link '
|
||||
'in your emails to continue.'))
|
||||
return redirect_to_url(eventreverse(self.request.event, 'presale:event.index'))
|
||||
|
||||
if src.client_secret != request.GET.get('client_secret'):
|
||||
messages.error(self.request, _('Sorry, there was an error in the payment process. Please check the link '
|
||||
'in your emails to continue.'))
|
||||
return redirect_to_url(eventreverse(self.request.event, 'presale:event.index'))
|
||||
|
||||
with transaction.atomic():
|
||||
self.order.refresh_from_db()
|
||||
self.payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=self.payment.pk)
|
||||
if self.payment.state == OrderPayment.PAYMENT_STATE_CONFIRMED:
|
||||
if 'payment_stripe_token' in request.session:
|
||||
del request.session['payment_stripe_token']
|
||||
return self._redirect_to_order()
|
||||
|
||||
if src.status == 'chargeable':
|
||||
try:
|
||||
prov._charge_source(request, src.id, self.payment)
|
||||
except PaymentException as e:
|
||||
messages.error(request, str(e))
|
||||
return self._redirect_to_order()
|
||||
finally:
|
||||
if 'payment_stripe_token' in request.session:
|
||||
del request.session['payment_stripe_token']
|
||||
elif src.status == 'consumed':
|
||||
# Webhook was faster, wow! ;)
|
||||
if 'payment_stripe_token' in request.session:
|
||||
del request.session['payment_stripe_token']
|
||||
return self._redirect_to_order()
|
||||
elif src.status == 'pending':
|
||||
self.payment.state = OrderPayment.PAYMENT_STATE_PENDING
|
||||
self.payment.info = str(src)
|
||||
self.payment.save()
|
||||
else: # failed or canceled
|
||||
self.payment.fail(info=str(src))
|
||||
messages.error(self.request, _('We had trouble authorizing your card payment. Please try again and '
|
||||
'get in touch with us if this problem persists.'))
|
||||
return self._redirect_to_order()
|
||||
|
||||
|
||||
@method_decorator(xframe_options_exempt, 'dispatch')
|
||||
class ScaView(StripeOrderView, View):
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class CheckoutView(View):
|
||||
return self.redirect(previous_step.get_step_url(request) if previous_step else self.get_index_url(request))
|
||||
|
||||
if 'step' not in kwargs:
|
||||
utm_params = {k: v for k, v in request.GET.items() if k.startswith("utm_") or k == "gclid" or k == "_gl"}
|
||||
utm_params = {k: v for k, v in request.GET.items() if k.startswith("utm_")}
|
||||
return self.redirect(step.get_step_url(request) + '?' + urlencode(utm_params))
|
||||
is_selected = (step.identifier == kwargs.get('step', ''))
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ from pretix.base.models import Customer, InvoiceAddress, Order, OrderPosition
|
||||
from pretix.base.services.mail import mail
|
||||
from pretix.base.settings import PERSON_NAME_SCHEMES
|
||||
from pretix.base.signals import customer_created, customer_signed_in
|
||||
from pretix.helpers import LOCK_SELF_NO_KEY
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.compat import CompatDeleteView
|
||||
from pretix.helpers.http import redirect_to_url
|
||||
from pretix.multidomain.models import KnownDomain
|
||||
@@ -280,7 +280,7 @@ class SetPasswordView(FormView):
|
||||
def form_valid(self, form):
|
||||
with transaction.atomic():
|
||||
# Re-check token in transaction to prevent race condition
|
||||
self.customer = Customer.objects.select_for_update(**LOCK_SELF_NO_KEY).get(pk=self.customer.pk)
|
||||
self.customer = Customer.objects.select_for_update(of=OF_SELF).get(pk=self.customer.pk)
|
||||
if not TokenGenerator().check_token(self.customer, self.request.GET.get('token', '')):
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ from binascii import unhexlify
|
||||
from datetime import timedelta
|
||||
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||
from django.db import transaction
|
||||
from django.http import Http404, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
@@ -498,7 +499,9 @@ class KeysView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
privkey, pubkey = _get_or_create_server_keypair(request.organizer)
|
||||
kid = hashlib.sha256(pubkey.encode()).hexdigest()[:16]
|
||||
pubkey = RSA.import_key(pubkey)
|
||||
public_key = load_pem_public_key(pubkey.encode())
|
||||
assert isinstance(public_key, RSAPublicKey)
|
||||
public_numbers = public_key.public_numbers()
|
||||
|
||||
return JsonResponse({
|
||||
'keys': [
|
||||
@@ -507,8 +510,8 @@ class KeysView(View):
|
||||
'alg': 'RS256',
|
||||
'kid': kid,
|
||||
'use': 'sig',
|
||||
'e': self._encode_int(pubkey.e).decode().rstrip("="),
|
||||
'n': self._encode_int(pubkey.n).decode().rstrip("="),
|
||||
'e': self._encode_int(public_numbers.e).decode().rstrip("="),
|
||||
'n': self._encode_int(public_numbers.n).decode().rstrip("="),
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -152,9 +152,12 @@ export function createWidgetStore (config: {
|
||||
return ''
|
||||
},
|
||||
additionalURLParams (): string {
|
||||
if (!window.location.search.includes('utm_')) {
|
||||
return ''
|
||||
}
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
for (const [key] of params.entries()) {
|
||||
if (!key.startsWith('utm_') || key !== 'gclid' || key !== '_gl') {
|
||||
if (!key.startsWith('utm_')) {
|
||||
params.delete(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,51 +872,6 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
|
||||
with scopes_disabled():
|
||||
assert 2 == Item.objects.all().count()
|
||||
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/items/'.format(organizer.slug, event.slug),
|
||||
{
|
||||
"category": category.pk,
|
||||
"name": {
|
||||
"en": "Ticket"
|
||||
},
|
||||
"active": True,
|
||||
"description": None,
|
||||
"default_price": "23.00",
|
||||
"free_price": False,
|
||||
"tax_rate": "19.00",
|
||||
"tax_rule": taxrule.pk,
|
||||
"admission": True,
|
||||
"issue_giftcard": False,
|
||||
"position": 0,
|
||||
"picture": None,
|
||||
"available_from": None,
|
||||
"available_until": None,
|
||||
"require_voucher": False,
|
||||
"hide_without_voucher": False,
|
||||
"allow_cancel": True,
|
||||
"min_per_order": None,
|
||||
"max_per_order": None,
|
||||
"checkin_attention": False,
|
||||
"checkin_text": None,
|
||||
"has_variations": True,
|
||||
"addons": [
|
||||
{
|
||||
"addon_category": category.pk,
|
||||
"min_count": 0,
|
||||
"max_count": 0,
|
||||
"position": 0,
|
||||
"multi_allowed": False,
|
||||
"price_included": True
|
||||
}
|
||||
]
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.content.decode() == '{"addons":["The maximum count needs to be greater than zero."]}'
|
||||
with scopes_disabled():
|
||||
assert 2 == Item.objects.all().count()
|
||||
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/items/'.format(organizer.slug, event.slug),
|
||||
{
|
||||
@@ -1143,48 +1098,6 @@ def test_item_create_with_bundle(token_client, organizer, event, item, category,
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.content.decode() == '{"bundles":["The chosen variation does not belong to this item."]}'
|
||||
with scopes_disabled():
|
||||
v = item2.variations.create(value="foo")
|
||||
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/items/'.format(organizer.slug, event.slug),
|
||||
{
|
||||
"category": category.pk,
|
||||
"name": {
|
||||
"en": "Ticket"
|
||||
},
|
||||
"active": True,
|
||||
"description": None,
|
||||
"default_price": "23.00",
|
||||
"free_price": False,
|
||||
"tax_rate": "19.00",
|
||||
"tax_rule": taxrule.pk,
|
||||
"admission": True,
|
||||
"position": 0,
|
||||
"picture": None,
|
||||
"available_from": None,
|
||||
"available_until": None,
|
||||
"require_voucher": False,
|
||||
"hide_without_voucher": False,
|
||||
"allow_cancel": True,
|
||||
"min_per_order": None,
|
||||
"max_per_order": None,
|
||||
"checkin_attention": False,
|
||||
"checkin_text": None,
|
||||
"has_variations": True,
|
||||
"bundles": [
|
||||
{
|
||||
"bundled_item": item.pk,
|
||||
"bundled_variation": None,
|
||||
"count": 0,
|
||||
"designated_price": "3.00",
|
||||
}
|
||||
]
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.content.decode() == '{"bundles":["The count needs to be greater than zero."]}'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
@@ -30,7 +30,10 @@ from urllib.parse import quote
|
||||
import jwt
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from Crypto.PublicKey import RSA
|
||||
from cryptography.hazmat.primitives.asymmetric.rsa import (
|
||||
RSAPublicKey, RSAPublicNumbers,
|
||||
)
|
||||
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
from freezegun import freeze_time
|
||||
@@ -691,6 +694,11 @@ def test_keys_endpoint(env, client, ssoclient):
|
||||
|
||||
e = decode_int(data['keys'][0]['e'])
|
||||
n = decode_int(data['keys'][0]['n'])
|
||||
pubkey = RSA.construct((n, e))
|
||||
representation = pubkey.export_key('PEM').decode()
|
||||
pubkey = RSAPublicNumbers(e, n).public_key()
|
||||
assert isinstance(pubkey, RSAPublicKey)
|
||||
|
||||
representation = pubkey.public_bytes(
|
||||
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
|
||||
).decode()
|
||||
|
||||
assert representation.strip() == env[0].settings.sso_server_signing_key_rsa256_public.strip()
|
||||
Reference in new issue
Block a user