From 118fc8c42fdbaea53d47d1f234a5c6ff71f71f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E5=B9=BF?= Date: Wed, 25 Sep 2019 16:31:58 +0800 Subject: [PATCH] Dev beta (#3281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 修改发送command日志 * [Update] 修复用户树显示资产数量不对的bug --- apps/assets/models/node.py | 4 ---- apps/audits/serializers.py | 1 + apps/audits/signals_handler.py | 6 +++++- apps/common/utils/common.py | 2 +- apps/jumpserver/settings.py | 2 +- apps/perms/api/user_permission/mixin.py | 2 +- apps/terminal/models.py | 10 ++++++++++ 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index 46e06c63e..d1628be76 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -257,10 +257,6 @@ class NodeAssetsMixin: @lazyproperty def assets_amount(self): - """ - 获取节点下所有资产数量速度太慢,所以需要重写,使用cache等方案 - :return: - """ amount = self.tree().assets_amount(self.key) return amount diff --git a/apps/audits/serializers.py b/apps/audits/serializers.py index 70b69b880..7dcd94d73 100644 --- a/apps/audits/serializers.py +++ b/apps/audits/serializers.py @@ -36,3 +36,4 @@ class SessionAuditSerializer(serializers.ModelSerializer): class Meta: model = Session fields = '__all__' + diff --git a/apps/audits/signals_handler.py b/apps/audits/signals_handler.py index cb87e2b9e..0f201b464 100644 --- a/apps/audits/signals_handler.py +++ b/apps/audits/signals_handler.py @@ -9,7 +9,8 @@ from rest_framework.renderers import JSONRenderer from jumpserver.utils import current_request from common.utils import get_request_ip, get_logger, get_syslogger from users.models import User -from terminal.models import Session +from terminal.models import Session, Command +from terminal.backends.command.serializers import SessionCommandSerializer from . import models from . import serializers @@ -88,6 +89,9 @@ def on_audits_log_create(sender, instance=None, **kwargs): elif sender == Session: category = "host_session_log" serializer = serializers.SessionAuditSerializer + elif sender == Command: + category = "session_command_log" + serializer = SessionCommandSerializer else: return diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index 667f166b3..f17125435 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -225,4 +225,4 @@ class lazyproperty: else: value = self.func(instance) setattr(instance, self.func.__name__, value) - return value \ No newline at end of file + return value diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index dd3fb170f..d726b4bcb 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -286,7 +286,7 @@ LOGGING = { 'handlers': ['console', 'file'], 'level': "INFO", }, - 'jms_audits': { + 'jms.audits': { 'handlers': ['syslog'], 'level': 'INFO' }, diff --git a/apps/perms/api/user_permission/mixin.py b/apps/perms/api/user_permission/mixin.py index a25e49251..8d65a884c 100644 --- a/apps/perms/api/user_permission/mixin.py +++ b/apps/perms/api/user_permission/mixin.py @@ -36,7 +36,7 @@ class UserNodeTreeMixin: assets_amount = self.tree.assets_amount(node.key) if assets_amount == 0 and node.key != Node.empty_key: continue - node._assets_amount = assets_amount + node.assets_amount = assets_amount data = ParserNode.parse_node_to_tree_node(node) _queryset.append(data) return _queryset diff --git a/apps/terminal/models.py b/apps/terminal/models.py index 8cfd5ef87..f7f2994ed 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -4,6 +4,7 @@ import os import uuid from django.db import models +from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ from django.utils import timezone from django.conf import settings @@ -267,7 +268,16 @@ class Task(models.Model): db_table = "terminal_task" +class CommandManager(models.Manager): + def bulk_create(self, objs, **kwargs): + resp = super().bulk_create(objs, **kwargs) + for i in objs: + post_save.send(i.__class__, instance=i, created=True) + return resp + + class Command(AbstractSessionCommand): + objects = CommandManager() class Meta: db_table = "terminal_command"