2018-04-06 03:27:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2020-05-09 03:28:39 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-04-06 03:27:52 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2022-11-10 06:44:23 +00:00
|
|
|
from common.drf.fields import LabeledChoiceField
|
2022-12-16 07:52:02 +00:00
|
|
|
from ops.models.job import JobAuditLog
|
|
|
|
from ops.serializers.job import JobExecutionSerializer
|
2019-08-21 12:27:21 +00:00
|
|
|
from terminal.models import Session
|
|
|
|
from . import models
|
2022-11-10 06:44:23 +00:00
|
|
|
from .const import (
|
2022-12-20 10:12:35 +00:00
|
|
|
ActionChoices, OperateChoices,
|
|
|
|
MFAChoices, LoginStatusChoices,
|
2022-11-11 07:11:10 +00:00
|
|
|
LoginTypeChoices,
|
2022-11-10 06:44:23 +00:00
|
|
|
)
|
2018-04-06 03:27:52 +00:00
|
|
|
|
|
|
|
|
2022-12-16 07:52:02 +00:00
|
|
|
class JobAuditLogSerializer(JobExecutionSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = JobAuditLog
|
2022-12-20 10:12:35 +00:00
|
|
|
read_only_fields = [
|
2022-12-20 12:23:42 +00:00
|
|
|
"id", "material", "time_cost", 'date_start',
|
|
|
|
'date_finished', 'date_created',
|
|
|
|
'is_finished', 'is_success', 'created_by',
|
2022-12-20 10:12:35 +00:00
|
|
|
]
|
2022-12-16 07:52:02 +00:00
|
|
|
fields = read_only_fields + []
|
|
|
|
|
|
|
|
|
2018-04-06 03:27:52 +00:00
|
|
|
class FTPLogSerializer(serializers.ModelSerializer):
|
2022-11-11 07:11:10 +00:00
|
|
|
operate = LabeledChoiceField(choices=OperateChoices.choices, label=_("Operate"))
|
2018-04-06 03:27:52 +00:00
|
|
|
|
|
|
|
class Meta:
|
2019-08-21 12:27:21 +00:00
|
|
|
model = models.FTPLog
|
2022-11-11 07:11:10 +00:00
|
|
|
fields_mini = ["id"]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_small = fields_mini + [
|
2022-12-20 10:12:35 +00:00
|
|
|
"user", "remote_addr", "asset", "account",
|
|
|
|
"org_id", "operate", "filename", "is_success",
|
2022-11-11 07:11:10 +00:00
|
|
|
"date_start",
|
2021-04-29 11:10:45 +00:00
|
|
|
]
|
|
|
|
fields = fields_small
|
2019-08-21 12:27:21 +00:00
|
|
|
|
|
|
|
|
2020-04-29 11:05:56 +00:00
|
|
|
class UserLoginLogSerializer(serializers.ModelSerializer):
|
2022-11-11 07:11:10 +00:00
|
|
|
mfa = LabeledChoiceField(choices=MFAChoices.choices, label=_("MFA"))
|
|
|
|
type = LabeledChoiceField(choices=LoginTypeChoices.choices, label=_("Type"))
|
|
|
|
status = LabeledChoiceField(choices=LoginStatusChoices.choices, label=_("Status"))
|
2020-05-06 11:35:19 +00:00
|
|
|
|
2019-08-21 12:27:21 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.UserLoginLog
|
2022-11-11 07:11:10 +00:00
|
|
|
fields_mini = ["id"]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_small = fields_mini + [
|
2022-12-07 10:58:57 +00:00
|
|
|
"username", "type", "ip",
|
|
|
|
"city", "user_agent", "mfa",
|
|
|
|
"reason", "reason_display",
|
|
|
|
"backend", "backend_display",
|
|
|
|
"status", "datetime",
|
2021-04-29 11:10:45 +00:00
|
|
|
]
|
|
|
|
fields = fields_small
|
2020-11-11 02:27:18 +00:00
|
|
|
extra_kwargs = {
|
2022-11-11 07:11:10 +00:00
|
|
|
"user_agent": {"label": _("User agent")},
|
|
|
|
"reason_display": {"label": _("Reason display")},
|
|
|
|
"backend_display": {"label": _("Authentication backend")},
|
2020-11-11 02:27:18 +00:00
|
|
|
}
|
2019-08-21 12:27:21 +00:00
|
|
|
|
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
class OperateLogActionDetailSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.OperateLog
|
|
|
|
fields = ('before', 'after')
|
|
|
|
|
|
|
|
|
2019-08-21 12:27:21 +00:00
|
|
|
class OperateLogSerializer(serializers.ModelSerializer):
|
2022-11-11 07:11:10 +00:00
|
|
|
action = LabeledChoiceField(choices=ActionChoices.choices, label=_("Action"))
|
2022-01-18 07:20:29 +00:00
|
|
|
|
2019-08-21 12:27:21 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.OperateLog
|
2022-11-11 07:11:10 +00:00
|
|
|
fields_mini = ["id"]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_small = fields_mini + [
|
2022-12-07 10:58:57 +00:00
|
|
|
"user", "action", "resource_type",
|
|
|
|
"resource_type_display", "resource",
|
|
|
|
"remote_addr", "datetime", "org_id",
|
2021-04-29 11:10:45 +00:00
|
|
|
]
|
|
|
|
fields = fields_small
|
2022-11-11 07:11:10 +00:00
|
|
|
extra_kwargs = {"resource_type_display": {"label": _("Resource Type")}}
|
2019-08-21 12:27:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PasswordChangeLogSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.PasswordChangeLog
|
2022-11-11 07:11:10 +00:00
|
|
|
fields = ("id", "user", "change_by", "remote_addr", "datetime")
|
2019-08-21 12:27:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SessionAuditSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Session
|
2022-11-11 07:11:10 +00:00
|
|
|
fields = "__all__"
|