From 92dfe19fe7530ace47f43619f24570aeef912eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E4=BD=A9=E7=8F=8A=5Bshiisa=5D?= Date: Thu, 8 Dec 2022 18:01:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=AF=BC=E5=87=BA=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0<=E5=85=A8=E5=90=8D>=20#618?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/bkuser_core/api/web/audit/serializers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/bkuser_core/api/web/audit/serializers.py b/src/api/bkuser_core/api/web/audit/serializers.py index 5b91a922c..e09a88fcf 100644 --- a/src/api/bkuser_core/api/web/audit/serializers.py +++ b/src/api/bkuser_core/api/web/audit/serializers.py @@ -15,6 +15,7 @@ from rest_framework import serializers from .constants import LOGIN_FAILED_REASON_MAP, OPERATION_ABOUT_PASSWORD, OPERATION_NAME_MAP, OPERATION_OBJ_NAME_MAP +from bkuser_core.profiles.models import Profile PLACE_HOLDER = "--" @@ -35,6 +36,7 @@ class GeneralLogListInputSLZ(LogListInputSLZ): class GeneralLogOutputSLZ(serializers.Serializer): id = serializers.IntegerField(help_text=_("ID")) extra_value = serializers.JSONField(help_text=_("额外信息")) + display_name = serializers.CharField(help_text=_("用户全名"), read_only=True) operator = serializers.CharField(help_text=_("操作者")) create_time = serializers.DateTimeField(help_text=_("创建时间")) status = serializers.CharField(help_text=_("状态")) @@ -57,12 +59,14 @@ def to_representation(self, obj): category_id = extra_value.get("category_id") category_display_name = category_name_map.get(category_id, PLACE_HOLDER) + display_name = Profile.objects.get(username=obj.operator).display_name return { "datetime": datetime.datetime.strptime(instance["create_time"], "%Y-%m-%dT%H:%M:%S.%fZ"), "operator": instance["operator"], "target_obj": instance["target_obj"], "category_display_name": category_display_name, + "display_name": display_name, "operation": instance["operation"], "client_ip": extra_value.get("client_ip", PLACE_HOLDER), } @@ -79,7 +83,7 @@ class LoginLogOutputSLZ(serializers.Serializer): # datetime = serializers.CharField(source="create_time", help_text=_("登录时间"), required=False) is_success = serializers.BooleanField(help_text=_("是否登录成功"), required=False) username = serializers.CharField(help_text=_("登录用户"), source="profile.username") - + display_name = serializers.CharField(help_text=_("用户全名"), source="profile.display_name") datetime = serializers.SerializerMethodField(help_text=_("登录时间"), required=False) category_display_name = serializers.SerializerMethodField(help_text=_("所属目录"), required=False) client_ip = serializers.SerializerMethodField(help_text=_("客户端 IP"), required=False) From 7f83ce20a11769e546fc5a455bff928b70696aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E4=BD=A9=E7=8F=8A=5Bshiisa=5D?= Date: Fri, 9 Dec 2022 17:32:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=AF=BC=E5=87=BA=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0<=E5=85=A8=E5=90=8D>=20#618?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/bkuser_core/api/web/audit/serializers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/bkuser_core/api/web/audit/serializers.py b/src/api/bkuser_core/api/web/audit/serializers.py index e09a88fcf..5cbb0a505 100644 --- a/src/api/bkuser_core/api/web/audit/serializers.py +++ b/src/api/bkuser_core/api/web/audit/serializers.py @@ -59,7 +59,8 @@ def to_representation(self, obj): category_id = extra_value.get("category_id") category_display_name = category_name_map.get(category_id, PLACE_HOLDER) - display_name = Profile.objects.get(username=obj.operator).display_name + operator_profile = Profile.objects.filter(username=obj.operator).first() + display_name = operator_profile.display_name if operator_profile else "" return { "datetime": datetime.datetime.strptime(instance["create_time"], "%Y-%m-%dT%H:%M:%S.%fZ"),