Skip to content

Commit c08780f

Browse files
committed
fixed leave
1 parent 42a05d4 commit c08780f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

projects/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,21 @@ class LeaveProject(generics.GenericAPIView):
504504
permission_classes = [IsAuthenticated]
505505

506506
def delete(self, request, project_pk: int) -> Response:
507+
current_user_id = self.request.user.id
507508
collaborator = get_object_or_404(
508509
Collaborator.objects.all(),
509510
project_id=project_pk,
510-
user_id=self.request.user.id,
511+
user_id=current_user_id,
511512
)
513+
project = Project.objects.get(id=project_pk).select_related("leader")
514+
if project.leader.id == current_user_id:
515+
return Response(
516+
{
517+
"error": "You can't leave if you are a leader of a project. "
518+
"Please, switch leadership!"
519+
},
520+
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
521+
)
512522
collaborator.delete()
513523
return Response(status=204)
514524

0 commit comments

Comments
 (0)