Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions reports/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def test_export_persons_csv_data(
PERSONS_BATCH_COUNT = 2
person_1, person_2 = PersonFactory.create_batch(PERSONS_BATCH_COUNT)

admin_user = UserFactory(is_staff=True)
user = UserFactory(is_staff=False)
admin_user = UserFactory(is_event_staff=True)
user = UserFactory(is_event_staff=False)

user_api_client = APIClient()
user_api_client.force_authenticate(user=user)
Expand Down Expand Up @@ -427,7 +427,7 @@ def test_auditlog_access_logging(
self,
):
PERSON_BATCH_COUNT = 2
admin_user = UserFactory(is_staff=True)
admin_user = UserFactory(is_event_staff=True)
PersonFactory.create_batch(
PERSON_BATCH_COUNT,
)
Expand Down Expand Up @@ -458,8 +458,8 @@ def test_export_organisation_csv_data(self):
person_1 = PersonFactory.create(organisations=[org1])
person_2 = PersonFactory.create(organisations=[org2])

admin_user = UserFactory(is_staff=True)
user = UserFactory(is_staff=False)
admin_user = UserFactory(is_event_staff=True)
user = UserFactory(is_event_staff=False)

user_api_client = APIClient()
user_api_client.force_authenticate(user=user)
Expand Down Expand Up @@ -536,8 +536,8 @@ def test_export_enrolment_csv_data(self):
study_group=StudyGroupFactory(group_size=2, amount_of_adult=1),
)

admin_user = UserFactory(is_staff=True)
user = UserFactory(is_staff=False)
admin_user = UserFactory(is_event_staff=True)
user = UserFactory(is_event_staff=False)

user_api_client = APIClient()
user_api_client.force_authenticate(user=user)
Expand Down
13 changes: 11 additions & 2 deletions reports/views/csv_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from drf_spectacular.utils import extend_schema, OpenApiExample, OpenApiResponse
from rest_framework import generics
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAdminUser
from rest_framework.permissions import BasePermission

from common.utils import (
get_client_ip,
Expand All @@ -33,6 +33,15 @@
logger = logging.getLogger(__name__)


class IsEventAdminUser(BasePermission):
"""
Allows access only to event admin users.
"""

def has_permission(self, request, view):
return bool(request.user and request.user.is_event_staff)


class ExportReportCsvView(ExportReportViewMixin, generics.GenericAPIView):
"""
A generic API view that provides functionality to export model data as a CSV file.
Expand All @@ -49,7 +58,7 @@ class ExportReportCsvView(ExportReportViewMixin, generics.GenericAPIView):
model = None
serializer_class = None
authentication_classes = [KultusApiTokenAuthentication, SessionAuthentication]
permission_classes = [IsAdminUser]
permission_classes = [IsEventAdminUser]
csv_dialect = csv.excel
csv_delimiter = ";"

Expand Down