Skip to content
Snippets Groups Projects
Commit 96203c44 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[team][api] Replace custom delete with perform_destroy hook

parent 5fc28dc7
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !327. Comments created here will be created in the context of that merge request.
......@@ -32,8 +32,8 @@ from django.db.models import Q
from rest_framework import generics
from rest_framework import permissions
from rest_framework.response import Response
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework import exceptions as drf_exceptions
from .serializers import FullTeamSerializer
from .serializers import SimpleTeamSerializer
......@@ -42,7 +42,7 @@ from .serializers import TeamUpdateSerializer
from .models import Team
from .permissions import IsOwner, HasPrivacyLevel
from ..common.responses import BadRequestResponse, ForbiddenResponse
from ..common.responses import BadRequestResponse
from ..common.mixins import CommonContextMixin
......@@ -122,18 +122,13 @@ class TeamDetailView(CommonContextMixin, generics.RetrieveUpdateDestroyAPIView):
context["user"] = self.request.user
return context
def delete(self, request, owner_name, team_name):
team = self.get_object()
# Check that the team can still be deleted
if not (team.deletable()):
return ForbiddenResponse(
def perform_destroy(self, instance):
if not instance.deletable():
raise drf_exceptions.PermissionDenied(
"The team isn't deletable (it has been used to share %d objects with its members)"
% team.total_shares()
% instance.total_shares()
)
team.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
return super().perform_destroy(instance)
def update(self, request, owner_name, team_name):
team = self.get_object()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment