Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 导出增加<全名> #618 #835

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/api/bkuser_core/api/web/audit/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "--"

Expand All @@ -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=_("状态"))
Expand All @@ -57,12 +59,15 @@ def to_representation(self, obj):

category_id = extra_value.get("category_id")
category_display_name = category_name_map.get(category_id, PLACE_HOLDER)
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"),
"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),
}
Expand All @@ -79,7 +84,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)
Expand Down