mirror of https://github.com/jumpserver/jumpserver
commit
47f2df0a5b
|
@ -98,11 +98,7 @@ class IDSpmFilter(filters.BaseFilterBackend):
|
||||||
resources_id = cache.get(cache_key)
|
resources_id = cache.get(cache_key)
|
||||||
if resources_id is None or not isinstance(resources_id, list):
|
if resources_id is None or not isinstance(resources_id, list):
|
||||||
return queryset
|
return queryset
|
||||||
if isinstance(queryset, list):
|
queryset = queryset.filter(id__in=resources_id)
|
||||||
# CommandViewSet
|
|
||||||
queryset = [q for q in queryset if q['id'] in resources_id]
|
|
||||||
else:
|
|
||||||
queryset = queryset.filter(id__in=resources_id)
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import time
|
import time
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.shortcuts import HttpResponse
|
from django.shortcuts import HttpResponse
|
||||||
|
from django.core.cache import cache
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from rest_framework.fields import DateTimeField
|
from rest_framework.fields import DateTimeField
|
||||||
|
@ -13,7 +14,7 @@ from django.template import loader
|
||||||
from orgs.utils import current_org
|
from orgs.utils import current_org
|
||||||
from common.permissions import IsOrgAdminOrAppUser, IsOrgAuditor
|
from common.permissions import IsOrgAdminOrAppUser, IsOrgAuditor
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
from common.mixins import ExtraFilterFieldsMixin
|
from common import const
|
||||||
from ..backends import (
|
from ..backends import (
|
||||||
get_command_storage, get_multi_command_storage,
|
get_command_storage, get_multi_command_storage,
|
||||||
SessionCommandSerializer,
|
SessionCommandSerializer,
|
||||||
|
@ -63,8 +64,23 @@ class CommandQueryMixin:
|
||||||
)
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def filter_queryset_spm(self, queryset):
|
||||||
|
spm = self.request.query_params.get('spm')
|
||||||
|
if not spm:
|
||||||
|
return queryset
|
||||||
|
cache_key = const.KEY_CACHE_RESOURCES_ID.format(spm)
|
||||||
|
resources_id = cache.get(cache_key)
|
||||||
|
if resources_id is None or not isinstance(resources_id, list):
|
||||||
|
return queryset
|
||||||
|
if isinstance(queryset, list):
|
||||||
|
queryset = [q for q in queryset if q['id'] in resources_id]
|
||||||
|
else:
|
||||||
|
queryset = queryset.filter(id__in=resources_id)
|
||||||
|
return queryset
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
# 解决es存储命令时,父类根据filter_fields过滤出现异常的问题,返回的queryset类型list
|
# 解决es存储命令时,父类根据filter_fields过滤出现异常的问题,返回的queryset类型list
|
||||||
|
queryset = self.filter_queryset_spm(queryset)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def get_date_range(self):
|
def get_date_range(self):
|
||||||
|
@ -87,7 +103,7 @@ class CommandQueryMixin:
|
||||||
return date_from_st, date_to_st
|
return date_from_st, date_to_st
|
||||||
|
|
||||||
|
|
||||||
class CommandViewSet(ExtraFilterFieldsMixin, CommandQueryMixin, viewsets.ModelViewSet):
|
class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet):
|
||||||
"""接受app发送来的command log, 格式如下
|
"""接受app发送来的command log, 格式如下
|
||||||
{
|
{
|
||||||
"user": "admin",
|
"user": "admin",
|
||||||
|
|
Loading…
Reference in New Issue