Compare commits

...
Author SHA1 Message Date
Phin Wolkwitz d9e2b86f06 Fix tests 2026-11-19 16:58:23 +01:00
Phin Wolkwitz f5ef575f57 Add permission tests, refactor gates tests 2026-11-19 16:30:47 +01:00
Phin Wolkwitz c9ade09b18 Add tests 2026-11-19 12:27:42 +01:00
Phin Wolkwitz ddb2f1915f Sort imports 2026-11-19 11:40:31 +01:00
Phin WolkwitzandRichard Schreiber fc7b4207f6 Apply suggestions from code review
Co-authored-by: Richard Schreiber <wiffbi@gmail.com>
2026-11-19 11:34:30 +01:00
Phin Wolkwitz 49bbffdc58 API: Add an endpoint for gates 2026-11-18 20:55:20 +01:00
Lukas Bockstaller d78fb1a6bb we are only running chromium tests, no need to install all other browsers (#6787) 2026-11-18 14:40:07 +01:00
dependabot[bot]andLukas Bockstaller ce850787f6 Update pytest requirement from ==9.1.* to ==9.2.* (#6752)
* Update pytest requirement from ==9.1.* to ==9.2.*

Updates the requirements on [pytest](https://github.com/pytest-dev/pytest) to permit the latest version.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/9.1.0.dev0...9.2.0)

---
updated-dependencies:
- dependency-name: pytest
  dependency-version: 9.2.0
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* pytest-base-url became an optional dependency

https://github.com/microsoft/playwright-pytest/pull/334

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lukas Bockstaller <bockstaller@pretix.eu>
2026-11-18 14:39:56 +01:00
dependabot[bot] dd941ec9f8 Update css-inline requirement from ==0.23.* to ==0.24.* (#6782) 2026-11-18 13:52:23 +01:00
dependabot[bot] 0a19009743 Update kombu requirement from ==5.6.* to ==5.7.* (#6783) 2026-11-18 13:52:14 +01:00
Lukas Bockstaller 7f046e16a2 fix: pass request object to the request parameter of the form (#6786) 2026-11-18 12:04:34 +01:00
10 changed files with 380 additions and 11 deletions

No files matched your search

+1 -1
View File
@@ -123,7 +123,7 @@ jobs:
working-directory: ./src
run: make all compress
- name: Install Playwright browsers
run: playwright install --with-deps
run: playwright install chromium --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
+195
View File
@@ -0,0 +1,195 @@
Gate resource
-------------
The gate resource contains the following public fields:
.. rst-class:: rest-resource-table
===================================== ========================== =======================================================
Field Type Description
===================================== ========================== =======================================================
id integer Internal ID of the gate within this organizer
name string gate name
identifier string Internal identifier to make it easier to match the data with other sources
===================================== ========================== =======================================================
Endpoints
----------------
.. http:get:: /api/v1/organizers/(organizer)/gates/
Returns a list of all gates within a given organizer.
**Example request**:
.. sourcecode:: http
GET /api/v1/organizers/bigevents/gates/ HTTP/1.1
Host: pretix.eu
Accept: application/json, text/javascript
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"name": "Main door",
"identifier": "west_entry"
}
]
}
:param organizer: The ``slug`` field of the organizer to fetch
:statuscode 200: no error
:statuscode 401: Authentication failure
:statuscode 403: The requested organizer does not exist **or** you have no permission to view this resource.
.. http:get:: /api/v1/organizers/(organizer)/gates/(id)/
Returns information on one gate, identified by its ID.
**Example request**:
.. sourcecode:: http
GET /api/v1/organizers/bigevents/gates/1/ HTTP/1.1
Host: pretix.eu
Accept: application/json, text/javascript
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json
{
"id": 1,
"name": "Main door",
"identifier": "west_entry"
}
:param organizer: The ``slug`` field of the organizer to fetch
:param id: The ``id`` of the gate to fetch
:statuscode 200: no error
:statuscode 401: Authentication failure
:statuscode 403: The requested organizer does not exist **or** you have no permission to view this resource.
.. http:post:: /api/v1/organizers/(organizer)/gates/
Creates a new gate
You can supply the following fields of the resource:
* ``name``
* ``identifier`` (optional, if you do not supply one, it will be auto-generated)
**Example request**:
.. sourcecode:: http
POST /api/v1/organizers/bigevents/gates/ HTTP/1.1
Host: pretix.eu
Accept: application/json, text/javascript
Content-Type: application/json
{
"name": "South gate",
"identifier": "south_entry",
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 201 Created
Vary: Accept
Content-Type: application/json
{
"id": 2,
"name": "South gate",
"identifier": "south_entry"
}
:param organizer: The ``slug`` field of the organizer to create a gate for
:statuscode 201: no error
:statuscode 400: The gate could not be created due to invalid submitted data.
:statuscode 401: Authentication failure
:statuscode 403: The requested organizer/gate does not exist **or** you have no permission to create this resource.
.. http:patch:: /api/v1/organizers/(organizer)/gates/(id)/
Update a gate.
**Example request**:
.. sourcecode:: http
PATCH /api/v1/organizers/bigevents/gates/1/ HTTP/1.1
Host: pretix.eu
Accept: application/json, text/javascript
Content-Type: application/json
Content-Length: 94
{
"name": "Foo"
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json
{
"id": 2,
"name": "Foo",
"identifier": "south_entry"
}
:param organizer: The ``slug`` field of the organizer to modify
:param id: The ``id`` field of the gate to modify
:statuscode 200: no error
:statuscode 400: The gate could not be modified due to invalid submitted data
:statuscode 401: Authentication failure
:statuscode 403: The requested organizer/gate does not exist **or** you have no permission to change this resource.
.. http:delete:: /api/v1/organizers/(organizer)/gates/(id)/
Delete a gate.
**Example request**:
.. sourcecode:: http
DELETE /api/v1/organizers/bigevents/gates/1/ HTTP/1.1
Host: pretix.eu
Accept: application/json, text/javascript
**Example response**:
.. sourcecode:: http
HTTP/1.1 204 No Content
Vary: Accept
:param organizer: The ``slug`` field of the organizer to modify
:param id: The ``id`` field of the gate to delete
:statuscode 204: no error
:statuscode 401: Authentication failure
:statuscode 403: The requested organizer/gate does not exist **or** you have no permission to change it **or** this gate cannot be deleted since it is currently in use.
+4 -3
View File
@@ -34,7 +34,7 @@ dependencies = [
"celery==5.6.*",
"chardet==5.2.*",
"cryptography>=50.0.2",
"css-inline==0.23.*",
"css-inline==0.24.*",
"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.6.*",
"kombu==5.7.*",
"libsass==0.23.*",
"lxml",
"markdown==3.11.2",
@@ -123,7 +123,8 @@ dev = [
"pytest-sugar",
"pytest-xdist==3.8.*",
"pytest-playwright",
"pytest==9.1.*",
"pytest-base-url",
"pytest==9.2.*",
"playwright",
"responses",
"pypdfium2"
+8 -1
View File
@@ -41,7 +41,7 @@ from pretix.api.serializers.settings import SettingsSerializer
from pretix.base.auth import get_auth_backends
from pretix.base.i18n import get_language_without_region
from pretix.base.models import (
Customer, Device, EventMetaProperty, GiftCard, GiftCardTransaction,
Customer, Device, EventMetaProperty, Gate, GiftCard, GiftCardTransaction,
Membership, MembershipType, OrderPosition, Organizer, ReusableMedium,
SalesChannel, SeatingPlan, Team, TeamAPIToken, TeamInvite, User,
)
@@ -477,6 +477,13 @@ class DeviceSerializer(serializers.ModelSerializer):
del self.fields['initialization_token']
class GateSerializer(serializers.ModelSerializer):
class Meta:
model = Gate
fields = ('id', 'name', 'identifier')
class TeamInviteSerializer(serializers.ModelSerializer):
class Meta:
model = TeamInvite
+1
View File
@@ -62,6 +62,7 @@ orga_router.register(r'membershiptypes', organizer.MembershipTypeViewSet)
orga_router.register(r'reusablemedia', media.ReusableMediaViewSet)
orga_router.register(r'teams', organizer.TeamViewSet)
orga_router.register(r'devices', organizer.DeviceViewSet)
orga_router.register(r'gates', organizer.GateViewSet)
orga_router.register(r'orders', order.OrganizerOrderViewSet)
orga_router.register(r'invoices', order.InvoiceViewSet)
orga_router.register(r'scheduled_exports', exporters.ScheduledOrganizerExportViewSet)
+50 -4
View File
@@ -44,16 +44,16 @@ from pretix.api.models import OAuthAccessToken
from pretix.api.pagination import TotalOrderingFilter
from pretix.api.serializers.organizer import (
CustomerCreateSerializer, CustomerSerializer, DeviceSerializer,
EventMetaPropertiesSerializer, GiftCardSerializer,
EventMetaPropertiesSerializer, GateSerializer, GiftCardSerializer,
GiftCardTransactionSerializer, MembershipSerializer,
MembershipTypeSerializer, OrganizerSerializer, OrganizerSettingsSerializer,
SalesChannelSerializer, SeatingPlanSerializer, TeamAPITokenSerializer,
TeamInviteSerializer, TeamMemberSerializer, TeamSerializer,
)
from pretix.base.models import (
Customer, Device, Event, EventMetaProperty, GiftCard, GiftCardTransaction,
LogEntry, Membership, MembershipType, Organizer, SalesChannel, SeatingPlan,
Team, TeamAPIToken, TeamInvite, User,
Customer, Device, Event, EventMetaProperty, Gate, GiftCard,
GiftCardTransaction, LogEntry, Membership, MembershipType, Organizer,
SalesChannel, SeatingPlan, Team, TeamAPIToken, TeamInvite, User,
)
from pretix.base.plugins import (
PLUGIN_LEVEL_EVENT, PLUGIN_LEVEL_EVENT_ORGANIZER_HYBRID,
@@ -571,6 +571,52 @@ class DeviceViewSet(mixins.CreateModelMixin,
return inst
class GateViewSet(viewsets.ModelViewSet):
serializer_class = GateSerializer
queryset = Gate.objects.none()
permission = 'organizer.devices:read'
write_permission = 'organizer.devices:write'
def get_queryset(self):
return self.request.organizer.gates.order_by('pk')
def get_serializer_context(self):
ctx = super().get_serializer_context()
ctx['organizer'] = self.request.organizer
return ctx
@transaction.atomic()
def perform_destroy(self, instance):
instance.log_action(
'pretix.gate.deleted',
user=self.request.user,
auth=self.request.auth,
data={'id': instance.pk}
)
instance.delete()
@transaction.atomic()
def perform_create(self, serializer):
inst = serializer.save(organizer=self.request.organizer)
inst.log_action(
'pretix.gate.created',
user=self.request.user,
auth=self.request.auth,
data=merge_dicts(self.request.data, {'id': inst.pk})
)
@transaction.atomic()
def perform_update(self, serializer):
inst = serializer.save()
inst.log_action(
'pretix.gate.changed',
user=self.request.user,
auth=self.request.auth,
data=self.request.data
)
return inst
class OrganizerSettingsView(views.APIView):
permission = None
write_permission = 'organizer.settings.general:write'
+1 -1
View File
@@ -267,7 +267,7 @@ class CustomerStep(CartMixin, TemplateFlowStep):
else None
),
prefix='login',
request=self.request.event,
request=self.request,
)
for field in f.fields.values():
field._show_required = field.required
+11 -1
View File
@@ -40,7 +40,7 @@ from django.utils.timezone import now
from django_scopes import scopes_disabled
from rest_framework.test import APIClient
from pretix.base.models import Device, Event, Organizer, Team, User
from pretix.base.models import Device, Event, Gate, Organizer, Team, User
from pretix.base.models.devices import generate_api_token
@@ -132,6 +132,16 @@ def device(organizer):
)
@pytest.fixture
@scopes_disabled()
def gate(organizer):
return Gate.objects.create(
organizer=organizer,
name='Entry',
identifier='entry'
)
@pytest.fixture
def user():
return User.objects.create_user('dummy@dummy.dummy', 'dummy')
+96
View File
@@ -0,0 +1,96 @@
#
# 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 pytest
from django_scopes import scopes_disabled
from pretix.base.models import Gate
TEST_RES = {
"name": "Entry",
"identifier": "entry"
}
@pytest.mark.django_db
def test_gate_list(token_client, organizer, gate):
res = dict(TEST_RES)
resp = token_client.get('/api/v1/organizers/{}/gates/'.format(organizer.slug))
assert resp.status_code == 200
gate.refresh_from_db()
res["id"] = gate.pk
assert [res] == resp.data['results']
@pytest.mark.django_db
def test_gate_detail(token_client, organizer, gate):
res = dict(TEST_RES)
resp = token_client.get('/api/v1/organizers/{}/gates/{}/'.format(organizer.slug, gate.id))
assert resp.status_code == 200
gate.refresh_from_db()
res["id"] = gate.pk
assert res == resp.data
TEST_GATE_CREATE_PAYLOAD = {
"name": "Second entry",
"identifier": "entry_2"
}
@pytest.mark.django_db
def test_gate_create(token_client, organizer):
resp = token_client.post(
'/api/v1/organizers/{}/gates/'.format(organizer.slug),
TEST_GATE_CREATE_PAYLOAD,
format='json'
)
assert resp.status_code == 201
with scopes_disabled():
g = Gate.objects.get(id=resp.data['id'])
assert g.name == TEST_GATE_CREATE_PAYLOAD.get('name')
assert g.identifier == TEST_GATE_CREATE_PAYLOAD.get('identifier')
@pytest.mark.django_db
def test_gate_update(token_client, organizer, gate):
resp = token_client.patch(
'/api/v1/organizers/{}/gates/{}/'.format(organizer.slug, gate.id),
{
'name': 'Main entry'
},
format='json'
)
assert resp.status_code == 200
gate.refresh_from_db()
assert gate.name == 'Main entry'
assert gate.identifier == TEST_RES.get('identifier')
@pytest.mark.django_db
def test_gate_delete(token_client, organizer, gate):
resp = token_client.delete(
'/api/v1/organizers/{}/gates/{}/'.format(organizer.slug, gate.id),
)
assert resp.status_code == 204
with scopes_disabled():
assert organizer.gates.count() == 0
+13
View File
@@ -255,6 +255,12 @@ org_permission_sub_urls = [
('get', 'organizer.devices:read', 'devices/1/', 404),
('put', 'organizer.devices:write', 'devices/1/', 404),
('patch', 'organizer.devices:write', 'devices/1/', 404),
('get', 'organizer.devices:read', 'gates/', 200),
('post', 'organizer.devices:write', 'gates/', 400),
('get', 'organizer.devices:read', 'gates/1/', 404),
('put', 'organizer.devices:write', 'gates/1/', 404),
('patch', 'organizer.devices:write', 'gates/1/', 404),
('delete', 'organizer.devices:write', 'gates/1/', 404),
('get', 'organizer.teams:write', 'teams/', 200),
('post', 'organizer.teams:write', 'teams/', 400),
('get', 'organizer.teams:write', 'teams/{team_id}/', 200),
@@ -320,6 +326,13 @@ def test_organizer_not_allowed_device(device_client, organizer):
assert resp.status_code == 403
@pytest.mark.django_db
def test_organizer_not_allowed_gate(token_client, organizer):
o2 = Organizer.objects.create(slug='o2', name='Organizer 2')
resp = token_client.get('/api/v1/organizers/{}/gates/'.format(o2.slug))
assert resp.status_code == 403
@pytest.mark.django_db
def test_organizer_not_existing(token_client, organizer):
resp = token_client.get('/api/v1/organizers/{}/events/'.format('o2'))