Commit 35eff1c2 authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch 'fix/event-registration-fields' into 'master'

Fix organiser only decorator for registration views

See merge request !1222
parents 977cd118 a0d72d2f
......@@ -301,7 +301,7 @@ class RegistrationAdmin(DoNextTranslatedModelAdmin):
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('<int:pk>/fields/',
path('<int:registration>/fields/',
self.admin_site.admin_view(
admin_views.RegistrationAdminFields.as_view(admin=self)),
name='events_registration_fields'),
......
......@@ -98,7 +98,7 @@ class RegistrationAdminFields(FormView):
def dispatch(self, request, *args, **kwargs):
self.registration = get_object_or_404(
Registration, pk=self.kwargs['pk'])
Registration, pk=self.kwargs['registration'])
try:
if self.registration.event.has_fields():
return super().dispatch(request, *args, **kwargs)
......
......@@ -13,7 +13,7 @@ def organiser_only(view_function):
class OrganiserOnly(object):
"""
Decorator that denies access to the page if:
1. There is no `pk` in the request
1. There is no `pk` or `registration` in the request
2. The specified event does not exist
3. The user is no organiser of the specified event
"""
......@@ -21,15 +21,21 @@ class OrganiserOnly(object):
self.view_function = view_function
def __call__(self, request, *args, **kwargs):
pk = kwargs.get('pk')
if pk:
event = None
event = None
if 'pk' in kwargs:
try:
event = Event.objects.get(pk=kwargs.get('pk'))
except Event.DoesNotExist:
pass
elif 'registration' in kwargs:
try:
event = Event.objects.get(pk=pk)
event = Event.objects.get(
registration__pk=kwargs.get('registration'))
except Event.DoesNotExist:
pass
if event and services.is_organiser(request.member, event):
return self.view_function(request, *args, **kwargs)
if event and services.is_organiser(request.member, event):
return self.view_function(request, *args, **kwargs)
raise PermissionDenied
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment