Skip to content

Commit

Permalink
fixed multiple return statements with one error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutvikrj26 committed Nov 8, 2023
1 parent a236062 commit 08f5c4f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions physionet-django/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,11 @@ def manage_co_hosts(request):
event = get_object_or_404(Event, slug=event_slug)

if not event.host == user:
return JsonResponse({'error': 'You are not the host of this event'}, status=403)

error_message = = 'You are not the host of this event'
if event.end_date < datetime.now().date():
return JsonResponse({'error': 'You cannot manage co-hosts of an event that has ended'}, status=403)

error_message = 'You cannot manage co-hosts of an event that has ended'
if not event.participants.filter(id=participant_id).exists():
return JsonResponse({'error': 'User is not a participant of this event'}, status=403)
error_message = 'User is not a participant of this event'

participant = event.participants.get(id=participant_id)

Expand Down Expand Up @@ -288,4 +286,8 @@ def manage_co_hosts(request):
return JsonResponse({'success': 'Cohost added successfully'})

messages.error(request, 'Invalid request')

if error_message:
return JsonResponse({'error': error_message}, status=403)

return redirect(event_home)

0 comments on commit 08f5c4f

Please sign in to comment.