fix - cant delete admin role
This commit is contained in:
@@ -13,6 +13,7 @@ from apps.authorization.api.v1.serializers import (
|
||||
UserRelationSerializer,
|
||||
PageSerializer
|
||||
)
|
||||
from apps.authorization.exception import AdminRoleDeleteException
|
||||
from apps.authorization.models import (
|
||||
Role,
|
||||
Permissions,
|
||||
@@ -41,6 +42,15 @@ class RoleViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet):
|
||||
serializer = self.get_serializer(role, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
def destroy(self, request, pk=None, *args, **kwargs):
|
||||
""" soft delete of role except Admin """
|
||||
|
||||
role = self.get_object()
|
||||
if role.type.key == 'ADM':
|
||||
raise AdminRoleDeleteException()
|
||||
role.soft_delete()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class PageViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||
""" add website pages to system to set permission on it """
|
||||
|
||||
8
apps/authorization/exception.py
Normal file
8
apps/authorization/exception.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
|
||||
class AdminRoleDeleteException(APIException):
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = 'نقش ادمین قابلیت حذف شدن ندارد' # noqa
|
||||
default_code = 'admin_role_delete_exception'
|
||||
Reference in New Issue
Block a user