From da4ad11a6965bd1279fd0e3d47d99663311841a4 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 16 Jun 2020 13:39:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9session=20command=20?= =?UTF-8?q?=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/command.py | 3 ++- apps/terminal/backends/command/serializers.py | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/terminal/api/command.py b/apps/terminal/api/command.py index a7798ce08..749da4fcb 100644 --- a/apps/terminal/api/command.py +++ b/apps/terminal/api/command.py @@ -26,7 +26,8 @@ class CommandQueryMixin: command_store = get_command_storage() permission_classes = [IsOrgAdminOrAppUser | IsOrgAuditor] filter_fields = [ - "asset", "system_user", "user", "session", + "asset", "system_user", "user", "session", "risk_level", + "input" ] default_days_ago = 5 diff --git a/apps/terminal/backends/command/serializers.py b/apps/terminal/backends/command/serializers.py index 657aa2356..4df584dbb 100644 --- a/apps/terminal/backends/command/serializers.py +++ b/apps/terminal/backends/command/serializers.py @@ -1,18 +1,26 @@ # ~*~ coding: utf-8 ~*~ +from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers +from .models import AbstractSessionCommand + class SessionCommandSerializer(serializers.Serializer): """使用这个类作为基础Command Log Serializer类, 用来序列化""" id = serializers.UUIDField(read_only=True) - user = serializers.CharField(max_length=64) - asset = serializers.CharField(max_length=128) - system_user = serializers.CharField(max_length=64) - input = serializers.CharField(max_length=128) - output = serializers.CharField(max_length=1024, allow_blank=True) - session = serializers.CharField(max_length=36) - risk_level = serializers.IntegerField(required=False) + user = serializers.CharField(max_length=64, label=_("User")) + asset = serializers.CharField(max_length=128, label=_("Asset")) + system_user = serializers.CharField(max_length=64, label=_("System user")) + input = serializers.CharField(max_length=128, label=_("Command")) + output = serializers.CharField(max_length=1024, allow_blank=True, label=_("Output")) + session = serializers.CharField(max_length=36, label=_("Session")) + risk_level = serializers.ChoiceField(required=False, label=_("Risk level"), choices=AbstractSessionCommand.RISK_LEVEL_CHOICES) + risk_level_display = serializers.SerializerMethodField() org_id = serializers.CharField(max_length=36, required=False, default='', allow_null=True, allow_blank=True) timestamp = serializers.IntegerField() + @staticmethod + def get_risk_level_display(obj): + risk_mapper = dict(AbstractSessionCommand.RISK_LEVEL_CHOICES) + return risk_mapper.get(obj.risk_level)