MCPcopy Index your code
hub / github.com/Flagsmith/flagsmith / AuditLogRetrieveSerializer

Class AuditLogRetrieveSerializer

api/audit/serializers.py:38–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38class AuditLogRetrieveSerializer(serializers.ModelSerializer): # type: ignore[type-arg]
39 author = UserListSerializer()
40 environment = EnvironmentSerializerLight()
41 project = ProjectListSerializer()
42 change_details = serializers.SerializerMethodField()
43 change_type = serializers.SerializerMethodField()
44
45 class Meta:
46 model = AuditLog
47 fields = (
48 "id",
49 "created_date",
50 "log",
51 "author",
52 "environment",
53 "project",
54 "related_object_id",
55 "related_object_uuid",
56 "related_object_type",
57 "is_system_event",
58 "change_details",
59 "change_type",
60 )
61
62 @extend_schema_field(
63 {
64 "type": "array",
65 "items": {
66 "type": "object",
67 "properties": {
68 "field": {"type": "string"},
69 "old": {"type": ["string", "number", "boolean", "null"]},
70 "new": {"type": ["string", "number", "boolean", "null"]},
71 },
72 },
73 }
74 )
75 def get_change_details(self, instance: AuditLog) -> list[AuditLogChangeDetail]:
76 if history_record := instance.history_record:
77 return AuditLogChangeDetailsSerializer( # type: ignore[return-value]
78 instance=history_record.get_change_details(), # type: ignore[attr-defined]
79 many=True,
80 ).data
81
82 return []
83
84 def get_change_type(self, instance: AuditLog) -> ChangeType:
85 if not (history_record := instance.history_record):
86 return "UNKNOWN"
87
88 return { # type: ignore[return-value]
89 "+": "CREATE",
90 "-": "DELETE",
91 "~": "UPDATE",
92 }.get(
93 history_record.history_type # type: ignore[attr-defined]
94 )
95

Callers

nothing calls this directly

Calls 3

UserListSerializerClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…