Skip to content

Commit

Permalink
Prevent registering for event without time places
Browse files Browse the repository at this point in the history
Also prevent admins, because if a standalone event were to be changed to repeating, there would be no time places to transfer the tickets to
(after having implemented the changes mentioned in #563).
  • Loading branch information
ddabble committed Oct 28, 2022
1 parent 6333885 commit f2dffbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def standalone(self):
return self.event_type == self.Type.STANDALONE

def can_register(self, user: User, *, fail_if_not_standalone):
# Admins should always be allowed
# Registering for an event with no time places should never be allowed - no matter the `event_type`
if not self.timeplaces.exists():
return False

# Admins should always be allowed (except for the above case)
if user.has_perm('news.cancel_ticket'):
return True

Expand Down
4 changes: 4 additions & 0 deletions news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ def setup(self, request, *args, **kwargs):
time_place_pk = self.kwargs.get('time_place_pk')
if time_place_pk is None:
self.ticket_time_place = None
# Raise an error if the event has no time places (see the first `timeplaces` check in `Event.can_register()`)
if not self.event.timeplaces.exists():
raise Http404("Cannot register for an event with no time places")

self.ticket_event = self.event
else:
self.ticket_time_place = get_object_or_404(TimePlace, pk=time_place_pk, event=self.event)
Expand Down

0 comments on commit f2dffbf

Please sign in to comment.