mirror of
https://github.com/pretix/pretix.git
synced 2026-08-09 10:37:50 +00:00
* Add Reusable Media Exchange to Checkin API * isort * Remove debugging leftover * Apply suggestions from code review Co-authored-by: robbi5 <maxi@richt.name> * Add media_exchange_supported to CheckinRPCRedeemInputSerializer * SecurityProfiles: Add api-v1:reusablemedia-lookup and -detail for SCAN * Simplify media exchange checks * Apply suggestions from code review Co-authored-by: Raphael Michel <mail@raphaelmichel.de> * Wording: re-usable --> reusable * Deny checkins if media-exchange is required but device does not support it. * Remove media_exchange_supported-Flag: Checkin will always be denied if media needs to be exchanged; apps will fall back to explanation text * CheckinRPC: Also perform media exchange * Use media_policy from item, not as a checkinrpc parameter * my own review notes * Fixes, cleanup, rebase * block expired media * Fix query * add logging * Refactor link_action into media policy, gift card support * Block illegal policy-type combination * Drop add_to_reusable_medium, decide all by policy * Fix test failure * fix test on postgres * Expose reusable_media_usage_enforced to devies * Explicitly set update view --------- Co-authored-by: robbi5 <maxi@richt.name> Co-authored-by: Maximilian Richt <richt@pretix.eu> Co-authored-by: Raphael Michel <mail@raphaelmichel.de> Co-authored-by: Raphael Michel <michel@rami.io> Co-authored-by: Raphael Michel <michel@pretix.eu>
165 lines
5.4 KiB
Python
165 lines
5.4 KiB
Python
#
|
|
# 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/>.
|
|
#
|
|
from django.db import models
|
|
from django.db.models import Q
|
|
from django.utils.functional import cached_property
|
|
from django.utils.timezone import now
|
|
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
|
from django_scopes import ScopedManager
|
|
|
|
from pretix.base.media import MEDIA_TYPES
|
|
from pretix.base.models import LoggedModel
|
|
from pretix.base.models.customers import Customer
|
|
from pretix.base.models.giftcards import GiftCard
|
|
from pretix.base.models.orders import OrderPosition
|
|
from pretix.base.models.organizer import Organizer
|
|
|
|
|
|
class ReusableMediumQuerySet(models.QuerySet):
|
|
|
|
def active(self):
|
|
return self.filter(
|
|
Q(expires__isnull=True) | Q(expires__gte=now()),
|
|
active=True,
|
|
)
|
|
|
|
|
|
class ReusableMediumQuerySetManager(ScopedManager(organizer='organizer').__class__):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self._queryset_class = ReusableMediumQuerySet
|
|
|
|
def active(self):
|
|
return self.get_queryset().active()
|
|
|
|
|
|
class ReusableMedium(LoggedModel):
|
|
id = models.BigAutoField(primary_key=True)
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
updated = models.DateTimeField(auto_now=True)
|
|
|
|
organizer = models.ForeignKey(
|
|
Organizer,
|
|
related_name='reusable_media',
|
|
on_delete=models.PROTECT
|
|
)
|
|
|
|
type = models.CharField(
|
|
verbose_name=pgettext_lazy('reusable_medium', 'Media type'),
|
|
choices=((k, v) for k, v in MEDIA_TYPES.items()),
|
|
max_length=100,
|
|
)
|
|
identifier = models.CharField(
|
|
max_length=200,
|
|
verbose_name=pgettext_lazy('reusable_medium', 'Identifier'),
|
|
)
|
|
claim_token = models.CharField(
|
|
max_length=200,
|
|
verbose_name=pgettext_lazy('reusable_medium', 'Claim token'),
|
|
null=True, blank=True
|
|
)
|
|
label = models.CharField(
|
|
max_length=200,
|
|
verbose_name=pgettext_lazy('reusable_medium', 'Label'),
|
|
null=True, blank=True
|
|
)
|
|
|
|
active = models.BooleanField(
|
|
verbose_name=_('Active'),
|
|
default=True
|
|
)
|
|
expires = models.DateTimeField(
|
|
verbose_name=_('Expiration date'),
|
|
null=True, blank=True
|
|
)
|
|
|
|
customer = models.ForeignKey(
|
|
Customer,
|
|
null=True, blank=True,
|
|
related_name='reusable_media',
|
|
on_delete=models.SET_NULL,
|
|
verbose_name=_('Customer account'),
|
|
)
|
|
linked_orderpositions = models.ManyToManyField(
|
|
OrderPosition,
|
|
related_name='linked_media',
|
|
verbose_name=_('Linked tickets'),
|
|
help_text=_(
|
|
'If you link to more than one ticket, make sure there is no overlap in validity. '
|
|
'If multiple tickets are valid at once, this will lead to failed check-ins.'
|
|
)
|
|
)
|
|
linked_giftcard = models.ForeignKey(
|
|
GiftCard,
|
|
null=True, blank=True,
|
|
related_name='linked_media',
|
|
on_delete=models.SET_NULL,
|
|
verbose_name=_('Linked gift card'),
|
|
)
|
|
|
|
info = models.JSONField(
|
|
default=dict
|
|
)
|
|
notes = models.TextField(verbose_name=_('Notes'), null=True, blank=True)
|
|
|
|
objects = ReusableMediumQuerySetManager()
|
|
|
|
@cached_property
|
|
def media_type(self):
|
|
return MEDIA_TYPES[self.type]
|
|
|
|
@property
|
|
def is_expired(self):
|
|
return self.expires and self.expires < now()
|
|
|
|
def touch(self):
|
|
self.save(update_fields=['updated'])
|
|
|
|
class Meta:
|
|
unique_together = (("identifier", "type", "organizer"),)
|
|
indexes = [
|
|
models.Index(fields=("updated", "id"), name="pretixbase__updated_093277_idx"),
|
|
]
|
|
ordering = "identifier", "type", "organizer"
|
|
|
|
|
|
class MediumKeySet(models.Model):
|
|
organizer = models.ForeignKey('Organizer', on_delete=models.CASCADE, related_name='medium_key_sets')
|
|
public_id = models.BigIntegerField(
|
|
unique=True,
|
|
)
|
|
media_type = models.CharField(max_length=100)
|
|
active = models.BooleanField(default=True)
|
|
uid_key = models.BinaryField()
|
|
diversification_key = models.BinaryField()
|
|
|
|
objects = ScopedManager(organizer='organizer')
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["organizer", "media_type"],
|
|
condition=Q(active=True),
|
|
name="keyset_unique_active",
|
|
),
|
|
]
|