perf: 修改 swagger 查询 (#9616)

* perf: 修改 swagger 查询

* perf: 修改 operate log

---------

Co-authored-by: ibuler <ibuler@qq.com>
Co-authored-by: Jiangjie.Bai <bugatti_it@163.com>
pull/9619/head
fit2bot 2023-02-17 21:11:06 +08:00 committed by GitHub
parent 1035e27201
commit 9ed1b8fc86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 20 deletions

View File

@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-
#
from rest_framework.generics import ListAPIView
from django.shortcuts import get_object_or_404
from django.db.models import Q
from django.shortcuts import get_object_or_404
from rest_framework.generics import ListAPIView
from assets.models import Asset
from common.utils import get_logger
from users.models import User, UserGroup
from users.serializers import UserSerializer, UserGroupSerializer
from users.filters import UserFilter
from orgs.mixins import generics
from perms.filters import AssetPermissionFilter
from perms.models import AssetPermission
from perms.serializers import AssetPermissionSerializer
from perms.filters import AssetPermissionFilter
from orgs.mixins import generics
from assets.models import Asset
from users.filters import UserFilter
from users.models import User, UserGroup
from users.serializers import UserSerializer, UserGroupSerializer
logger = get_logger(__file__)
__all__ = [
@ -56,6 +56,7 @@ class AssetPermUserListApi(BaseAssetPermUserOrUserGroupListApi):
class AssetPermUserGroupListApi(BaseAssetPermUserOrUserGroupListApi):
serializer_class = UserGroupSerializer
queryset = UserGroup.objects.none()
def get_queryset(self):
perms = self.get_asset_related_perms()
@ -124,4 +125,3 @@ class AssetPermUserGroupPermissionsListApi(BaseAssetRelatedPermissionListApi):
user_group_id = self.kwargs.get('perm_user_group_id')
user_group = get_object_or_404(UserGroup, pk=user_group_id)
return user_group

View File

@ -21,12 +21,9 @@ logger = logging.getLogger(__name__)
def default_node():
try:
from assets.models import Node
root = Node.org_root()
return Node.objects.filter(id=root.id)
except:
return None
from orgs.utils import current_org
from ..node import Node
return Node(id=current_org.id)
class AssetManager(OrgManager):

View File

@ -11,7 +11,7 @@ from accounts.serializers import AccountSerializerCreateValidateMixin
from accounts.serializers import AuthValidateMixin
from common.serializers import WritableNestedModelSerializer, SecretReadableMixin, CommonModelSerializer
from common.serializers.fields import LabeledChoiceField
from common.utils import lazyproperty, decrypt_password
from common.utils import lazyproperty
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
from ...const import Category, AllTypes
from ...models import Asset, Node, Platform, Label, Protocol
@ -25,6 +25,8 @@ __all__ = [
class AssetProtocolsSerializer(serializers.ModelSerializer):
port = serializers.IntegerField(required=False, allow_null=True, max_value=65535, min_value=1)
class Meta:
model = Protocol
fields = ['name', 'port']

View File

@ -12,8 +12,8 @@ from common.api import JMSGenericViewSet
from common.drf.filters import DatetimeRangeFilter
from common.plugins.es import QuerySet as ESQuerySet
from orgs.mixins.api import OrgGenericViewSet, OrgBulkModelViewSet
from orgs.utils import current_org, tmp_to_root_org
from orgs.models import Organization
from orgs.utils import current_org, tmp_to_root_org
from users.models import User
from .backends import TYPE_ENGINE_MAPPING
from .const import ActivityChoices
@ -135,8 +135,11 @@ class OperateLogViewSet(RetrieveModelMixin, ListModelMixin, OrgGenericViewSet):
date_range_filter_fields = [
('datetime', ('date_from', 'date_to'))
]
filterset_fields = ['user', 'action', 'resource_type', 'resource', 'remote_addr']
search_fields = ['resource']
filterset_fields = [
'user', 'action', 'resource_type', 'resource',
'remote_addr'
]
search_fields = ['resource', 'user']
ordering = ['-datetime']
def get_serializer_class(self):

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
#
from datetime import datetime
import uuid
from datetime import datetime
from django.db import models
from django.utils.translation import ugettext_lazy as _