Skip to content

Commit

Permalink
Add an endpoint to delete project (#337)
Browse files Browse the repository at this point in the history
* add delete endpoint

* only allow admins
  • Loading branch information
Pranshu1902 authored Oct 3, 2023
1 parent 47dccfb commit 774e59c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ayushma/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import filters
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
from rest_framework.mixins import (
CreateModelMixin,
DestroyModelMixin,
ListModelMixin,
RetrieveModelMixin,
)
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response

Expand All @@ -18,6 +23,7 @@ class ProjectViewSet(
ListModelMixin,
RetrieveModelMixin,
CreateModelMixin,
DestroyModelMixin,
):
queryset = Project.objects.all()
filter_backends = (filters.SearchFilter, DjangoFilterBackend)
Expand All @@ -31,6 +37,14 @@ class ProjectViewSet(
}
lookup_field = "external_id"

def destroy(self, request, *args, **kwargs):
if self.request.user.is_staff:
return super().destroy(request, *args, **kwargs)
return Response(
{"non_field_errors": "You do not have permission to delete this project"},
status=400,
)

def get_serializer_class(self):
if self.request.user.is_staff:
return ProjectUpdateSerializer
Expand Down

0 comments on commit 774e59c

Please sign in to comment.