Skip to content

Commit 4414bee

Browse files
committed
Prevent unregistered clubs from selling tickets, display events from clubs which require reapproval
1 parent c092ec7 commit 4414bee

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

backend/clubs/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class Club(models.Model):
355355
created_at = models.DateTimeField(auto_now_add=True)
356356
updated_at = models.DateTimeField(auto_now=True)
357357

358+
# signifies the existence of a previous instance within history with approved=True
358359
ghost = models.BooleanField(default=False)
359360
history = HistoricalRecords(cascade_delete_history=True)
360361

backend/clubs/views.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ def directory(self, request, *args, **kwargs):
17621762
"""
17631763
serializer = ClubMinimalSerializer(
17641764
Club.objects.all()
1765-
.exclude(Q(approved=False) | Q(archived=True))
1765+
.exclude((~Q(approved=True) & Q(ghost=False)) | Q(archived=True))
17661766
.order_by(Lower("name")),
17671767
many=True,
17681768
)
@@ -2463,7 +2463,19 @@ def add_to_cart(self, request, *args, **kwargs):
24632463
type: boolean
24642464
---
24652465
"""
2466-
event = self.get_object()
2466+
event = self.get_object().select_related("club")
2467+
# As clubs cannot go from historically approved to unapproved, we can
2468+
# check here without checking further on in the checkout process
2469+
# (the only exception is archiving a club, which is checked)
2470+
if not event.club.approved and not event.club.ghost:
2471+
return Response(
2472+
{
2473+
"detail": """This club has not been approved
2474+
and cannot sell tickets.""",
2475+
"success": False,
2476+
},
2477+
status=status.HTTP_403_FORBIDDEN,
2478+
)
24672479
cart, _ = Cart.objects.get_or_create(owner=self.request.user)
24682480

24692481
# Check if the event has already ended
@@ -5236,6 +5248,7 @@ def cart(self, request, *args, **kwargs):
52365248

52375249
tickets_to_replace = cart.tickets.filter(
52385250
Q(owner__isnull=False)
5251+
| Q(event__club__archived=True)
52395252
| Q(holder__isnull=False)
52405253
| Q(event__end_time__lt=now)
52415254
| Q(event__ticket_drop_time__gt=timezone.now())
@@ -5370,6 +5383,7 @@ def initiate_checkout(self, request, *args, **kwargs):
53705383
# are locked, we shouldn't block.
53715384
tickets = cart.tickets.select_for_update(skip_locked=True).filter(
53725385
Q(holder__isnull=True) | Q(holder=self.request.user),
5386+
event__club__archived=False,
53735387
owner__isnull=True,
53745388
event__ticket_drop_time__lt=timezone.now(),
53755389
buyable=True,

frontend/pages/events/[id].tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ const EventPage: React.FC<EventPageProps> = ({
269269
event.ticket_drop_time !== null &&
270270
new Date(event.ticket_drop_time) > new Date()
271271

272+
const historicallyApproved = club.approved !== true && !club.is_ghost
273+
272274
return (
273275
<>
274276
<Modal
@@ -390,17 +392,20 @@ const EventPage: React.FC<EventPageProps> = ({
390392
disabled={
391393
totalAvailableTickets === 0 ||
392394
endTime < DateTime.now() ||
393-
notDroppedYet
395+
notDroppedYet ||
396+
historicallyApproved
394397
}
395398
onClick={() => setShowTicketModal(true)}
396399
>
397-
{endTime < DateTime.now()
398-
? 'Event Ended'
399-
: notDroppedYet
400-
? 'Tickets Not Available Yet'
401-
: totalAvailableTickets === 0
402-
? 'Sold Out'
403-
: 'Get Tickets'}
400+
{historicallyApproved
401+
? 'Club Not Approved'
402+
: endTime < DateTime.now()
403+
? 'Event Ended'
404+
: notDroppedYet
405+
? 'Tickets Not Available Yet'
406+
: totalAvailableTickets === 0
407+
? 'Sold Out'
408+
: 'Get Tickets'}
404409
</button>
405410
</Card>
406411
)}

frontend/pages/events/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export const getServerSideProps = (async (ctx) => {
3737
// TODO: Add caching
3838
const [baseProps, clubs, events] = await Promise.all([
3939
getBaseProps(ctx),
40-
doApiRequest('/clubs/directory/?format=json', data)
41-
.then((resp) => resp.json() as Promise<Club[]>)
42-
.then((resp) => resp.filter(({ approved }) => approved)),
40+
doApiRequest('/clubs/directory/?format=json', data).then(
41+
(resp) => resp.json() as Promise<Club[]>,
42+
),
4343
doApiRequest(`/events/?${params.toString()}`, data).then(
4444
(resp) => resp.json() as Promise<ClubEvent[]>,
4545
),

0 commit comments

Comments
 (0)