role childs service add to BaseViewSet
This commit is contained in:
@@ -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 """
|
||||
|
||||
15
apps/authorization/services/role_child.py
Normal file
15
apps/authorization/services/role_child.py
Normal 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
|
||||
Reference in New Issue
Block a user