mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-20 17:49:32 +00:00
fix: View replay generate multiple operation logs
This commit is contained in:
parent
df64145adc
commit
6c374cb41f
@ -4,6 +4,7 @@ import os
|
|||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.cache import cache
|
||||||
from django.core.files.storage import default_storage
|
from django.core.files.storage import default_storage
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
from django.http import FileResponse
|
from django.http import FileResponse
|
||||||
@ -213,7 +214,7 @@ class SessionViewSet(OrgBulkModelViewSet):
|
|||||||
|
|
||||||
class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet):
|
class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet):
|
||||||
serializer_class = serializers.ReplaySerializer
|
serializer_class = serializers.ReplaySerializer
|
||||||
download_cache_key = "SESSION_REPLAY_DOWNLOAD_{}"
|
view_replay_cache_key = "SESSION_REPLAY_VIEW_{}"
|
||||||
session = None
|
session = None
|
||||||
rbac_perms = {
|
rbac_perms = {
|
||||||
'create': 'terminal.upload_sessionreplay',
|
'create': 'terminal.upload_sessionreplay',
|
||||||
@ -283,10 +284,14 @@ class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet):
|
|||||||
detail = i18n_fmt(
|
detail = i18n_fmt(
|
||||||
REPLAY_OP, self.request.user, _('View'), str(session)
|
REPLAY_OP, self.request.user, _('View'), str(session)
|
||||||
)
|
)
|
||||||
|
key = self.view_replay_cache_key.format(session_id)
|
||||||
|
if cache.get(key):
|
||||||
|
return
|
||||||
record_operate_log_and_activity_log(
|
record_operate_log_and_activity_log(
|
||||||
[session.asset_id], ActionChoices.view, detail, Session,
|
[session.asset_id], ActionChoices.view, detail, Session,
|
||||||
resource_display=f'{session.asset}', resource_type=_('Session replay')
|
resource_display=f'{session.asset}', resource_type=_('Session replay')
|
||||||
)
|
)
|
||||||
|
cache.set(key, 1, 10)
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def retrieve(self, request, *args, **kwargs):
|
||||||
session_id = kwargs.get('pk')
|
session_id = kwargs.get('pk')
|
||||||
|
Loading…
Reference in New Issue
Block a user