mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-10-22 16:31:33 +00:00
[Update] 添加用户授权资产列表页的分页,搜索,排序 (#1963)
* [Update] 分页获取用户授权资产 * [Update] 修改前端-用户授权资产分页 * [Update] 用户授权资产支持搜索 * [Update] 用户授权资产支持排序 * [Update] 用户授权的节点with资产Api,对资产进行排序 * [Update] 获取用户授权的节点下的资产的api,进行分页、排序、查询 * [Update] 抽象用户授权资产列表的查询,排序 * [Update] 优化小细节 * [Update] 删除无用导入 * [Update] 修改AssetFilterMixins目录从common到perms * [Update] 资产授权规则列表: 添加分页、搜索 * [Update] 添加管理用户,系统用户列表分页、搜索 * [Update] 用户组列表添加分页,搜索 * [Update] 资产标签列表添加分页、搜索 * [Update] 网域网关列表添加分页、搜索 * [Update] 命令过滤列表添加分页、搜索,修改翻译小细节 * [Update] 删除前端注释initDataTable * [Update] 修改文案,资产组-节点 * [Update] 普通用户资产列表添加分页、搜索
This commit is contained in:
@@ -5,6 +5,7 @@ from django.shortcuts import get_object_or_404
|
||||
from rest_framework.views import APIView, Response
|
||||
from rest_framework.generics import ListAPIView, get_object_or_404, RetrieveUpdateAPIView
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.pagination import LimitOffsetPagination
|
||||
|
||||
from common.utils import set_or_append_attr_bulk
|
||||
from common.permissions import IsValidUser, IsOrgAdmin, IsOrgAdminOrAppUser
|
||||
@@ -15,6 +16,7 @@ from .hands import AssetGrantedSerializer, User, UserGroup, Asset, Node, \
|
||||
NodeGrantedSerializer, SystemUser, NodeSerializer
|
||||
from orgs.utils import set_to_root_org
|
||||
from . import serializers
|
||||
from .mixins import AssetsFilterMixin
|
||||
|
||||
|
||||
class AssetPermissionViewSet(viewsets.ModelViewSet):
|
||||
@@ -23,6 +25,7 @@ class AssetPermissionViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
queryset = AssetPermission.objects.all()
|
||||
serializer_class = serializers.AssetPermissionCreateUpdateSerializer
|
||||
pagination_class = LimitOffsetPagination
|
||||
permission_classes = (IsOrgAdmin,)
|
||||
|
||||
def get_serializer_class(self):
|
||||
@@ -31,10 +34,15 @@ class AssetPermissionViewSet(viewsets.ModelViewSet):
|
||||
return self.serializer_class
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
queryset = super().get_queryset().all()
|
||||
search = self.request.query_params.get('search')
|
||||
asset_id = self.request.query_params.get('asset')
|
||||
node_id = self.request.query_params.get('node')
|
||||
inherit_nodes = set()
|
||||
|
||||
if search:
|
||||
queryset = queryset.filter(name__icontains=search)
|
||||
|
||||
if not asset_id and not node_id:
|
||||
return queryset
|
||||
|
||||
@@ -53,15 +61,17 @@ class AssetPermissionViewSet(viewsets.ModelViewSet):
|
||||
_permissions = queryset.filter(nodes=n)
|
||||
set_or_append_attr_bulk(_permissions, "inherit", n.value)
|
||||
permissions.update(_permissions)
|
||||
return permissions
|
||||
|
||||
return list(permissions)
|
||||
|
||||
|
||||
class UserGrantedAssetsApi(ListAPIView):
|
||||
class UserGrantedAssetsApi(AssetsFilterMixin, ListAPIView):
|
||||
"""
|
||||
用户授权的所有资产
|
||||
"""
|
||||
permission_classes = (IsOrgAdminOrAppUser,)
|
||||
serializer_class = AssetGrantedSerializer
|
||||
pagination_class = LimitOffsetPagination
|
||||
|
||||
def change_org_if_need(self):
|
||||
if self.request.user.is_superuser or \
|
||||
@@ -84,6 +94,7 @@ class UserGrantedAssetsApi(ListAPIView):
|
||||
system_users_granted = [s for s in v if s.protocol == k.protocol]
|
||||
k.system_users_granted = system_users_granted
|
||||
queryset.append(k)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_permissions(self):
|
||||
@@ -122,7 +133,7 @@ class UserGrantedNodesApi(ListAPIView):
|
||||
return super().get_permissions()
|
||||
|
||||
|
||||
class UserGrantedNodesWithAssetsApi(ListAPIView):
|
||||
class UserGrantedNodesWithAssetsApi(AssetsFilterMixin, ListAPIView):
|
||||
"""
|
||||
用户授权的节点并带着节点下资产的api
|
||||
"""
|
||||
@@ -155,19 +166,25 @@ class UserGrantedNodesWithAssetsApi(ListAPIView):
|
||||
queryset.append(node)
|
||||
return queryset
|
||||
|
||||
def sort_assets(self, queryset):
|
||||
for node in queryset:
|
||||
node.assets_granted = super().sort_assets(node.assets_granted)
|
||||
return queryset
|
||||
|
||||
def get_permissions(self):
|
||||
if self.kwargs.get('pk') is None:
|
||||
self.permission_classes = (IsValidUser,)
|
||||
return super().get_permissions()
|
||||
|
||||
|
||||
class UserGrantedNodeAssetsApi(ListAPIView):
|
||||
class UserGrantedNodeAssetsApi(AssetsFilterMixin, ListAPIView):
|
||||
"""
|
||||
查询用户授权的节点下的资产的api, 与上面api不同的是,只返回某个节点下的资产
|
||||
"""
|
||||
permission_classes = (IsOrgAdminOrAppUser,)
|
||||
serializer_class = AssetGrantedSerializer
|
||||
|
||||
pagination_class = LimitOffsetPagination
|
||||
|
||||
def change_org_if_need(self):
|
||||
if self.request.user.is_superuser or \
|
||||
self.request.user.is_app or \
|
||||
@@ -189,6 +206,8 @@ class UserGrantedNodeAssetsApi(ListAPIView):
|
||||
assets = nodes.get(node, [])
|
||||
for asset, system_users in assets.items():
|
||||
asset.system_users_granted = system_users
|
||||
|
||||
assets = list(assets.keys())
|
||||
return assets
|
||||
|
||||
def get_permissions(self):
|
||||
|
Reference in New Issue
Block a user