fix - cant delete admin role

This commit is contained in:
2025-10-28 13:51:05 +03:30
parent a333a5e5a8
commit 7ffaff2c11
4 changed files with 24 additions and 2 deletions

View File

@@ -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 """