Skip to content

Commit

Permalink
Merge pull request #316 from SELab-2/backend_extras
Browse files Browse the repository at this point in the history
Backend extras
  • Loading branch information
LGDTimtou authored May 23, 2024
2 parents c37715d + 17ce0df commit 144ae22
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions api/views/groep.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ def groep_list(request, format=None):
Response: Een lijst van groepen of een nieuw aangemaakte groep.
"""
if request.method == "GET":
if has_permissions(request.user):
groepen = Groep.objects.all()
else:
groepen = Groep.objects.filter(studenten=request.user.id)
groepen = Groep.objects.all()

if "project" in request.GET:
try:
Expand Down Expand Up @@ -78,12 +75,10 @@ def groep_detail(request, id, format=None):
except Groep.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == "GET":
if has_permissions(request.user) or contains(groep.studenten, request.user):
serializer = GroepSerializer(groep)
return Response(serializer.data)
return Response(status=status.HTTP_403_FORBIDDEN)
serializer = GroepSerializer(groep)
return Response(serializer.data)

if has_permissions(request.user):
if has_permissions(request.user) or contains(groep.studenten, request.user):
if request.method in ["PUT", "PATCH"]:
if request.method == "PUT":
serializer = GroepSerializer(groep, data=request.data)
Expand All @@ -93,8 +88,9 @@ def groep_detail(request, id, format=None):
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

elif request.method == "DELETE":

if has_permissions(request.user):
if request.method == "DELETE":
groep.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
return Response(status=status.HTTP_403_FORBIDDEN)

0 comments on commit 144ae22

Please sign in to comment.