Skip to content

Commit ac31a7c

Browse files
authored
Merge pull request #402 from PROCOLLAB-github/fix/leave-project
fixed leave
2 parents b327947 + c08780f commit ac31a7c

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
@@ -537,11 +537,21 @@ class LeaveProject(generics.GenericAPIView):
537537
permission_classes = [IsAuthenticated]
538538

539539
def delete(self, request, project_pk: int) -> Response:
540+
current_user_id = self.request.user.id
540541
collaborator = get_object_or_404(
541542
Collaborator.objects.all(),
542543
project_id=project_pk,
543-
user_id=self.request.user.id,
544+
user_id=current_user_id,
544545
)
546+
project = Project.objects.get(id=project_pk).select_related("leader")
547+
if project.leader.id == current_user_id:
548+
return Response(
549+
{
550+
"error": "You can't leave if you are a leader of a project. "
551+
"Please, switch leadership!"
552+
},
553+
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
554+
)
545555
collaborator.delete()
546556
return Response(status=204)
547557

0 commit comments

Comments
 (0)