mirror of https://github.com/jumpserver/jumpserver
fix: Solve the problem that log details cannot be viewed in non-default organizations
parent
5390fbacec
commit
9f8256f885
|
@ -257,27 +257,26 @@ class OperateLogViewSet(OrgReadonlyModelViewSet):
|
|||
return super().get_serializer_class()
|
||||
|
||||
def get_queryset(self):
|
||||
extra_org_ids = set()
|
||||
if str(current_org.id) == Organization.DEFAULT_ID:
|
||||
extra_org_ids.update(Organization.INTERNAL_IDS)
|
||||
current_org_id = str(current_org.id)
|
||||
|
||||
if self.is_action_detail:
|
||||
extra_org_ids.add(Organization.SYSTEM_ID)
|
||||
with tmp_to_root_org():
|
||||
queryset = OperateLog.objects.all()
|
||||
if current_org_id != Organization.ROOT_ID:
|
||||
filtered_org_ids = {current_org_id}
|
||||
if current_org_id == Organization.DEFAULT_ID:
|
||||
filtered_org_ids.update(Organization.INTERNAL_IDS)
|
||||
if self.is_action_detail:
|
||||
filtered_org_ids.update(Organization.SYSTEM_ID)
|
||||
queryset = OperateLog.objects.filter(org_id__in=filtered_org_ids)
|
||||
|
||||
if extra_org_ids:
|
||||
with tmp_to_root_org():
|
||||
qs = OperateLog.objects.filter(org_id__in=extra_org_ids)
|
||||
else:
|
||||
qs = OperateLog.objects.all()
|
||||
|
||||
es_config = settings.OPERATE_LOG_ELASTICSEARCH_CONFIG
|
||||
if es_config:
|
||||
engine_mod = import_module(TYPE_ENGINE_MAPPING['es'])
|
||||
store = engine_mod.OperateLogStore(es_config)
|
||||
if store.ping(timeout=2):
|
||||
qs = ESQuerySet(store)
|
||||
qs.model = OperateLog
|
||||
return qs
|
||||
es_config = settings.OPERATE_LOG_ELASTICSEARCH_CONFIG
|
||||
if es_config:
|
||||
engine_mod = import_module(TYPE_ENGINE_MAPPING['es'])
|
||||
store = engine_mod.OperateLogStore(es_config)
|
||||
if store.ping(timeout=2):
|
||||
queryset = ESQuerySet(store)
|
||||
queryset.model = OperateLog
|
||||
return queryset
|
||||
|
||||
|
||||
class PasswordChangeLogViewSet(OrgReadonlyModelViewSet):
|
||||
|
|
|
@ -15,6 +15,7 @@ from common.drf.filters import (
|
|||
IDNotFilterBackend, NotOrRelFilterBackend, LabelFilterBackend
|
||||
)
|
||||
from common.utils import get_logger, lazyproperty
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from .action import RenderToJsonMixin
|
||||
from .serializer import SerializerMixin
|
||||
|
||||
|
@ -132,7 +133,8 @@ class QuerySetMixin:
|
|||
serializer_class = self.get_serializer_class()
|
||||
if page and serializer_class:
|
||||
ids = [str(obj.id) for obj in page]
|
||||
page = model.objects.filter(id__in=ids)
|
||||
with tmp_to_root_org():
|
||||
page = model.objects.filter(id__in=ids)
|
||||
page = self.setup_eager_loading(page, is_paginated=True)
|
||||
page_mapper = {str(obj.id): obj for obj in page}
|
||||
page = [page_mapper.get(_id) for _id in ids if _id in page_mapper]
|
||||
|
|
Loading…
Reference in New Issue