mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Add delete user endpoint
This commit is contained in:
parent
d227535383
commit
008a2a2271
3 changed files with 27 additions and 1 deletions
|
@ -29,3 +29,12 @@ class IsHead(BasePermission):
|
|||
|
||||
def has_permission(self, request, view):
|
||||
return bool(request.user and request.user.role == "head")
|
||||
|
||||
|
||||
class IsAdmin(BasePermission):
|
||||
"""
|
||||
Allows access only to users with admin role
|
||||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return bool(request.user and request.user.role == "admin")
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.urls import include, path
|
||||
|
||||
from .views import CustomUserDeleteView
|
||||
|
||||
urlpatterns = [
|
||||
path("", include("djoser.urls")),
|
||||
path("", include("djoser.urls.jwt")),
|
||||
path("users/delete/<int:pk>/", CustomUserDeleteView.as_view()),
|
||||
]
|
||||
|
|
16
docmanager_backend/accounts/views.py
Normal file
16
docmanager_backend/accounts/views.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from rest_framework import generics
|
||||
from .serializers import CustomUserSerializer
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from accounts.permissions import IsAdmin
|
||||
from .models import CustomUser
|
||||
|
||||
|
||||
class CustomUserDeleteView(generics.DestroyAPIView):
|
||||
"""
|
||||
Used by admin to delete users. Accepts the user id as a URL parameter
|
||||
"""
|
||||
|
||||
http_method_names = ["delete"]
|
||||
serializer_class = CustomUserSerializer
|
||||
queryset = CustomUser.objects.all()
|
||||
permission_classes = [IsAuthenticated, IsAdmin]
|
Loading…
Reference in a new issue