d5279b124f
Storage Persistence Guard / storage-persistence-audit (push) Has been cancelled
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled
Client Quality Gates / Shared client and Web (pull_request) Has been cancelled
Client Quality Gates / macOS Desktop (pull_request) Has been cancelled
Storage Persistence Guard / storage-persistence-audit (pull_request) Has been cancelled
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { getDictLabel, statusDict } from "../../dictionaries";
|
||
import type { AuditEvent } from "..";
|
||
import { auditExportColumns } from "./auditExportColumns";
|
||
import { TEXT } from "../../locales";
|
||
|
||
export interface AuditExportRow {
|
||
[key: string]: string;
|
||
}
|
||
|
||
const extractStatusLabel = (obj?: Record<string, any>) => {
|
||
if (!obj) return "";
|
||
if (obj.status) return getDictLabel(statusDict, obj.status) || obj.status;
|
||
return "";
|
||
};
|
||
|
||
export const formatAuditRow = (event: AuditEvent): AuditExportRow => {
|
||
const beforeStatus = extractStatusLabel(event.before);
|
||
const afterStatus = extractStatusLabel(event.after);
|
||
const descriptionParts: string[] = [];
|
||
descriptionParts.push(`${event.actorName} ${event.actionText}`);
|
||
if (event.targetTypeLabel || event.targetName || event.targetId) {
|
||
const targetIdentifier = event.targetName || event.targetId;
|
||
descriptionParts.push(
|
||
`${TEXT.audit.objectLabel}${event.targetTypeLabel || ""}${
|
||
targetIdentifier ? `(${targetIdentifier})` : ""
|
||
}`
|
||
);
|
||
}
|
||
if (event.diffText?.length) {
|
||
descriptionParts.push(`${TEXT.audit.changeLabel}${event.diffText.join(";")}`);
|
||
}
|
||
|
||
return {
|
||
timestamp: event.timestamp || "",
|
||
actorName: event.actorName || "",
|
||
actorId: event.actorId || "",
|
||
actorRoleLabel: event.actorRoleLabel || "",
|
||
eventLabel: event.eventLabel || "",
|
||
targetTypeLabel: event.targetTypeLabel || "",
|
||
targetIdentifier: event.targetName || event.targetId || "",
|
||
description: descriptionParts.join(";"),
|
||
beforeStatus,
|
||
afterStatus,
|
||
resultLabel: event.resultLabel || "",
|
||
reason: event.reason || "",
|
||
ip: event.clientIp || "",
|
||
ipLocation: event.ipLocation || "",
|
||
clientSource: event.clientSourceLabel || "",
|
||
clientType: [event.clientType, event.clientVersion, event.clientPlatform].filter(Boolean).join("/") || "",
|
||
userAgent: event.userAgent || "",
|
||
remark: event.diffText?.join(";") || "",
|
||
};
|
||
};
|
||
|
||
export const formatAuditRows = (events: AuditEvent[]): AuditExportRow[] => {
|
||
return events.map((ev) => formatAuditRow(ev)).map((row) => {
|
||
const ordered: AuditExportRow = {};
|
||
auditExportColumns.forEach((col) => {
|
||
ordered[col.key] = row[col.key] ?? "";
|
||
});
|
||
return ordered;
|
||
});
|
||
};
|