mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-04-27 11:12:54 +00:00
perf: Asset account filter
This commit is contained in:
parent
f1c98fda34
commit
314da330c0
@ -59,6 +59,7 @@ class NodeFilterBackend(filters.BaseFilterBackend):
|
||||
|
||||
class AccountFilterSet(UUIDFilterMixin, BaseFilterSet):
|
||||
ip = drf_filters.CharFilter(field_name="address", lookup_expr="exact")
|
||||
name = drf_filters.CharFilter(field_name="name", lookup_expr="exact")
|
||||
hostname = drf_filters.CharFilter(field_name="name", lookup_expr="exact")
|
||||
username = drf_filters.CharFilter(field_name="username", lookup_expr="exact")
|
||||
address = drf_filters.CharFilter(field_name="asset__address", lookup_expr="exact")
|
||||
|
@ -11,6 +11,7 @@ from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.status import HTTP_200_OK
|
||||
|
||||
from accounts.filters import AccountFilterSet
|
||||
from accounts.serializers import AccountSerializer
|
||||
from accounts.tasks import push_accounts_to_assets_task, verify_accounts_connectivity_task
|
||||
from assets import serializers
|
||||
@ -176,6 +177,17 @@ class AssetViewSet(SuggestionMixin, BaseAssetViewSet):
|
||||
pk = self.kwargs.get("pk")
|
||||
asset = get_object_or_404(self.model, pk=pk)
|
||||
queryset = asset.all_accounts.all()
|
||||
|
||||
filterset = AccountFilterSet(
|
||||
data=self.request.query_params,
|
||||
queryset=queryset,
|
||||
request=self.request,
|
||||
)
|
||||
|
||||
if not filterset.is_valid():
|
||||
return Response(filterset.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
queryset = filterset.qs
|
||||
return self.get_paginated_response_from_queryset(queryset)
|
||||
|
||||
@action(methods=['post'], detail=False, url_path='sync-platform-protocols')
|
||||
|
@ -174,6 +174,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer, ResourceLabelsMixin, Writa
|
||||
'address': {'label': _('Address')},
|
||||
'nodes_display': {'label': _('Node path')},
|
||||
'nodes': {'allow_empty': True, 'label': _("Nodes")},
|
||||
'directory_services': {'required': False, 'label': _("Directory services")},
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user