role childs service add to BaseViewSet

This commit is contained in:
2025-10-28 09:39:22 +03:30
parent 1204fad1a0
commit 714e9abc1c
4 changed files with 34 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
class RoleViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
class RoleViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet):
""" Crud Operations For User Roles """
queryset = Role.objects.all()
@@ -33,6 +33,14 @@ class RoleViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
filter_backends = [filters.SearchFilter]
search_fields = ['role_name', 'type__name']
def list(self, request, *args, **kwargs):
""" all roles """
role = self.paginate_queryset(self.get_queryset().order_by('-modify_date'))
if role is not None: # noqa
serializer = self.get_serializer(role, many=True)
return self.get_paginated_response(serializer.data)
class PageViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
""" add website pages to system to set permission on it """

View File

@@ -0,0 +1,15 @@
import typing
from apps.authorization.models import Role
def get_all_role_child(role: Role = None) -> typing.Any:
"""
get all child of an role
"""
descendants = []
children = role.child.all()
for child in children:
descendants.append(child)
descendants.extend(get_all_org_child(child))
return descendants