Files
pretix_original/src/tests/plugins/autocheckin/test_control.py
Raphael Michel df0b580dd6 Pluggable permissions (#5728)
* Data model draft

* Refactor query and assignment usages of old permissions

* Backend UI

* API serializer

* Big string replace

* Docs, tests and fixes for teams api

* Update docs for device auth

* Eliminate old names

* Make tests pass

* Use new permissions, remove inconsistencies

* Add test for translations

* Show plugin permissions

* Add permission for seating plans

* Fix plugin activation

* Fix failing test

* Refactor to permission groups

* Update doc/api/resources/devices.rst

Co-authored-by: luelista <weller@rami.io>

* Update doc/api/resources/events.rst

Co-authored-by: luelista <weller@rami.io>

* Update src/pretix/api/serializers/organizer.py

Co-authored-by: luelista <weller@rami.io>

* Fix typo

* Fix python version compat

* Replacement after rebase

* Add proper permission handling for exports

* Docs for exporters

* Runtime linting of permission names

* Fix typos

* Show export page even without orders permission

* More legacy compat

* Do not strongly validate before plugins are loaded

* Rebase migration

* Add permission for outgoing mails

* Review notes

* Update doc/api/resources/teams.rst

Co-authored-by: Richard Schreiber <schreiber@pretix.eu>

* Clean up logic around exporters

* Review and failures

* Fix migration leading to forbidden combination

* Handle permissions on event copying

* Remove print-statements

* Make test clearer

* Review feedback

* Add AnyPermissionOf

* migration safety

---------

Co-authored-by: luelista <weller@rami.io>
Co-authored-by: Richard Schreiber <schreiber@pretix.eu>
2026-03-17 14:43:56 +01:00

178 lines
6.7 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/>.
#
import datetime
from django_scopes import scopes_disabled
from tests.base import SoupTest, extract_form_fields
from pretix.base.models import Event, Item, Organizer, Team, User
from pretix.plugins.autocheckin.models import AutoCheckinRule
class AutoCheckinFormTest(SoupTest):
def setUp(self):
super().setUp()
self.user = User.objects.create_user("dummy@dummy.dummy", "dummy")
self.orga1 = Organizer.objects.create(name="CCC", slug="ccc")
self.orga2 = Organizer.objects.create(name="MRM", slug="mrm")
self.event1 = Event.objects.create(
organizer=self.orga1,
name="30C3",
slug="30c3",
plugins="pretix.plugins.autocheckin",
date_from=datetime.datetime(2013, 12, 26, tzinfo=datetime.timezone.utc),
)
self.item1 = Item.objects.create(
event=self.event1, name="Standard", default_price=0, position=1
)
t = Team.objects.create(
organizer=self.orga1,
all_organizer_permissions=True,
all_event_permissions=True,
all_events=True,
)
t.members.add(self.user)
t = Team.objects.create(
organizer=self.orga2,
all_organizer_permissions=True,
all_event_permissions=True,
all_events=True,
)
t.members.add(self.user)
self.client.login(email="dummy@dummy.dummy", password="dummy")
def test_create(self):
doc = self.get_doc(
"/control/event/%s/%s/autocheckin/add" % (self.orga1.slug, self.event1.slug)
)
form_data = extract_form_fields(doc.select(".container-fluid form")[0])
doc = self.post_doc(
"/control/event/%s/%s/autocheckin/add"
% (self.orga1.slug, self.event1.slug),
form_data,
)
assert doc.select(".alert-success")
assert self.event1.autocheckinrule_set.exists()
def test_delete(self):
acr = self.event1.autocheckinrule_set.create(
mode=AutoCheckinRule.MODE_PAID,
all_payment_methods=False,
limit_payment_methods=["manual"],
)
doc = self.get_doc(
"/control/event/%s/%s/autocheckin/%s/delete"
% (self.orga1.slug, self.event1.slug, acr.id)
)
form_data = extract_form_fields(doc.select(".container-fluid form")[0])
doc = self.post_doc(
"/control/event/%s/%s/autocheckin/%s/delete"
% (self.orga1.slug, self.event1.slug, acr.id),
form_data,
)
assert doc.select(".alert-success")
with scopes_disabled():
assert self.event1.autocheckinrule_set.count() == 0
def test_item_copy(self):
with scopes_disabled():
acr = self.event1.autocheckinrule_set.create(
mode=AutoCheckinRule.MODE_PAID, all_products=False
)
acr.limit_products.add(self.item1)
self.client.post(
"/control/event/%s/%s/items/add" % (self.orga1.slug, self.event1.slug),
{
"name_0": "Intermediate",
"default_price": "23.00",
"tax_rate": "19.00",
"copy_from": str(self.item1.pk),
"has_variations": "1",
},
)
with scopes_disabled():
acr.refresh_from_db()
i_new = Item.objects.get(name__icontains="Intermediate")
assert i_new in acr.limit_products.all()
def test_copy_event(self):
with scopes_disabled():
acr = self.event1.autocheckinrule_set.create(
list=self.event1.checkin_lists.create(name="Test"),
mode=AutoCheckinRule.MODE_PAID,
all_products=False,
all_sales_channels=False,
)
acr.limit_products.add(self.item1)
acr.limit_sales_channels.add(
self.orga1.sales_channels.get(identifier="web")
)
self.post_doc(
"/control/events/add",
{
"event_wizard-current_step": "foundation",
"event_wizard-prefix": "event_wizard",
"foundation-organizer": self.orga2.pk,
"foundation-locales": ("en",),
},
)
self.post_doc(
"/control/events/add",
{
"event_wizard-current_step": "basics",
"event_wizard-prefix": "event_wizard",
"basics-name_0": "33C3",
"basics-slug": "33c3",
"basics-date_from_0": "2016-12-27",
"basics-date_from_1": "10:00:00",
"basics-date_to_0": "2016-12-30",
"basics-date_to_1": "19:00:00",
"basics-location_0": "Hamburg",
"basics-currency": "EUR",
"basics-tax_rate": "19.00",
"basics-locale": "en",
"basics-timezone": "Europe/Berlin",
},
)
self.post_doc(
"/control/events/add",
{
"event_wizard-current_step": "copy",
"event_wizard-prefix": "event_wizard",
"copy-copy_from_event": self.event1.pk,
},
)
with scopes_disabled():
ev = Event.objects.get(slug="33c3")
i_new = ev.items.first()
acr_new = ev.autocheckinrule_set.get()
assert i_new in acr_new.limit_products.all()
assert list(acr_new.limit_sales_channels.all()) == [
self.orga2.sales_channels.get(identifier="web")
]
assert acr_new.list.event == ev