diff --git a/apps/common/drf/filters.py b/apps/common/drf/filters.py index 7740cadba..8be3be56e 100644 --- a/apps/common/drf/filters.py +++ b/apps/common/drf/filters.py @@ -98,7 +98,11 @@ class IDSpmFilter(filters.BaseFilterBackend): resources_id = cache.get(cache_key) if resources_id is None or not isinstance(resources_id, list): return queryset - queryset = queryset.filter(id__in=resources_id) + if isinstance(queryset, list): + # CommandViewSet + queryset = [q for q in queryset if q['id'] in resources_id] + else: + queryset = queryset.filter(id__in=resources_id) return queryset diff --git a/apps/terminal/api/command.py b/apps/terminal/api/command.py index d18c70858..94466e258 100644 --- a/apps/terminal/api/command.py +++ b/apps/terminal/api/command.py @@ -13,6 +13,7 @@ from django.template import loader from orgs.utils import current_org from common.permissions import IsOrgAdminOrAppUser, IsOrgAuditor from common.utils import get_logger +from common.mixins import ExtraFilterFieldsMixin from ..backends import ( get_command_storage, get_multi_command_storage, SessionCommandSerializer, @@ -86,7 +87,7 @@ class CommandQueryMixin: return date_from_st, date_to_st -class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet): +class CommandViewSet(ExtraFilterFieldsMixin, CommandQueryMixin, viewsets.ModelViewSet): """接受app发送来的command log, 格式如下 { "user": "admin",