mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-08-14 20:33:41 +00:00
* perf: 添加应用树api * perf: perms tree * perf: 统一应用树 * perf: 修改icon * perf: stash it * perf: 优化应用账号 * perf: 基本完成应用账号重构 * perf: 修改翻译 Co-authored-by: ibuler <ibuler@qq.com>
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# coding: utf-8
|
|
#
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
|
from rest_framework.decorators import action
|
|
from rest_framework.response import Response
|
|
|
|
from common.tree import TreeNodeSerializer
|
|
from ..hands import IsOrgAdminOrAppUser
|
|
from .. import serializers
|
|
from ..models import Application
|
|
|
|
|
|
__all__ = ['ApplicationViewSet']
|
|
|
|
|
|
class ApplicationViewSet(OrgBulkModelViewSet):
|
|
model = Application
|
|
filterset_fields = {
|
|
'name': ['exact'],
|
|
'category': ['exact'],
|
|
'type': ['exact', 'in'],
|
|
}
|
|
search_fields = ('name', 'type', 'category')
|
|
permission_classes = (IsOrgAdminOrAppUser,)
|
|
serializer_classes = {
|
|
'default': serializers.ApplicationSerializer,
|
|
'get_tree': TreeNodeSerializer
|
|
}
|
|
|
|
@action(methods=['GET'], detail=False, url_path='tree')
|
|
def get_tree(self, request, *args, **kwargs):
|
|
show_count = request.query_params.get('show_count', '1') == '1'
|
|
queryset = self.filter_queryset(self.get_queryset())
|
|
tree_nodes = Application.create_tree_nodes(queryset, show_count=show_count)
|
|
serializer = self.get_serializer(tree_nodes, many=True)
|
|
return Response(serializer.data)
|