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
27 changes: 17 additions & 10 deletions src/apps/api/views/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,23 @@ def get_queryset(self):
return CompetitionParticipant.objects.none()

def update(self, request, *args, **kwargs):
if request.method == 'PATCH':
if 'status' in request.data:
participation_status = request.data['status']
participant = self.get_object()
emails = {
'approved': send_participation_accepted_emails,
'denied': send_participation_denied_emails,
}
if participation_status in emails:
emails[participation_status](participant)
if request.method == 'PATCH' and 'status' in request.data:
participation_status = request.data['status']
participant = self.get_object()

# Check if the new status is the same as the current status
if participation_status == participant.status:
return Response(
{"error": f"Status is already set to `{participation_status}`"},
status=status.HTTP_400_BAD_REQUEST
)

emails = {
'approved': send_participation_accepted_emails,
'denied': send_participation_denied_emails,
}
if participation_status in emails:
emails[participation_status](participant)

return super().update(request, *args, **kwargs)

Expand Down
11 changes: 10 additions & 1 deletion src/static/riot/competitions/detail/participant_manager.tag
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
}
self.update_participants()
})
.fail((resp) => {
let errorMessage = 'An error occurred while updating the status.'
if (resp.responseJSON && resp.responseJSON.error) {
errorMessage = resp.responseJSON.error
}
toastr.error(errorMessage)
})
}

self.revoke_permission = id => {
Expand All @@ -178,7 +185,9 @@
}

self.approve_permission = id => {
self._update_status(id, 'approved')
if (confirm("Are you sure you want to accept this user's participation request?")) {
self._update_status(id, 'approved')
}
}

self.search_participants = () => {
Expand Down