Skip to content
Snippets Groups Projects
Commit 56e8d9d3 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

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

parent 57c02c31
No related branches found
Tags v1.2.1
No related merge requests found
...@@ -32,8 +32,8 @@ from django.db.models import Q ...@@ -32,8 +32,8 @@ from django.db.models import Q
from rest_framework import generics from rest_framework import generics
from rest_framework import permissions from rest_framework import permissions
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework import exceptions as drf_exceptions
from .serializers import FullTeamSerializer from .serializers import FullTeamSerializer
from .serializers import SimpleTeamSerializer from .serializers import SimpleTeamSerializer
...@@ -42,7 +42,7 @@ from .serializers import TeamUpdateSerializer ...@@ -42,7 +42,7 @@ from .serializers import TeamUpdateSerializer
from .models import Team from .models import Team
from .permissions import IsOwner, HasPrivacyLevel from .permissions import IsOwner, HasPrivacyLevel
from ..common.responses import BadRequestResponse, ForbiddenResponse from ..common.responses import BadRequestResponse
from ..common.mixins import CommonContextMixin from ..common.mixins import CommonContextMixin
...@@ -122,18 +122,13 @@ class TeamDetailView(CommonContextMixin, generics.RetrieveUpdateDestroyAPIView): ...@@ -122,18 +122,13 @@ class TeamDetailView(CommonContextMixin, generics.RetrieveUpdateDestroyAPIView):
context["user"] = self.request.user context["user"] = self.request.user
return context return context
def delete(self, request, owner_name, team_name): def perform_destroy(self, instance):
team = self.get_object() if not instance.deletable():
raise drf_exceptions.PermissionDenied(
# Check that the team can still be deleted
if not (team.deletable()):
return ForbiddenResponse(
"The team isn't deletable (it has been used to share %d objects with its members)" "The team isn't deletable (it has been used to share %d objects with its members)"
% team.total_shares() % instance.total_shares()
) )
return super().perform_destroy(instance)
team.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
def update(self, request, owner_name, team_name): def update(self, request, owner_name, team_name):
team = self.get_object() 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