规范审计日志目标名称展示

- 药品运输审计日志写入运单号、批号或中心名称作为可读目标名\n- FAQ 分类审计日志写入分类名称,删除时提前保留展示名称\n- 前端审计归一化隐藏 UUID-only 目标名,并清理旧文本中的 UUID 标识\n- 新增审计归一化测试覆盖 FAQ 分类和药品运输记录
This commit is contained in:
Cheng Zhou
2026-06-04 16:30:54 +08:00
parent 4ea0e88c98
commit 0b3a4d4d31
4 changed files with 72 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
import { normalizeAuditEvent } from ".";
describe("normalizeAuditEvent", () => {
it("removes UUID tokens from legacy audit detail text", () => {
const event = normalizeAuditEvent(
{
action: "DELETE_FAQ_CATEGORY",
detail: "FAQ 分类 295c4072-3868-416e-9a35-24a63a3f97fb 已删除",
operator_id: "operator-1",
operator_role: "ADMIN",
entity_type: "faq_category",
entity_id: "295c4072-3868-416e-9a35-24a63a3f97fb",
created_at: "2026-06-04T11:16:04Z",
},
{}
);
expect(event.diffText).toEqual(["FAQ 分类已删除"]);
expect(event.targetName).toBe("");
});
it("keeps readable shipment identifiers but hides UUID-only shipment identifiers", () => {
const event = normalizeAuditEvent(
{
action: "CREATE_DRUG_SHIPMENT",
detail: "药品运输 835d6a00-f696-4aec-a35d-8c359be201d2 已创建",
operator_id: "operator-1",
operator_role: "ADMIN",
entity_type: "drug_shipment",
entity_id: "835d6a00-f696-4aec-a35d-8c359be201d2",
created_at: "2026-06-04T10:27:02Z",
},
{}
);
expect(event.diffText).toEqual(["药品运输已创建"]);
expect(event.targetName).toBe("");
});
});
+12 -2
View File
@@ -111,7 +111,17 @@ const normalizeLegacyDetailLine = (line: string): string => {
}
if (text === "立项配置已发布") return "立项配置已发布";
if (text.includes("siteEnrollmentPlans")) return text.replaceAll("siteEnrollmentPlans", "中心入组计划");
return text;
return removeUuidOnlyIdentifier(text);
};
const uuidTextPattern = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
const removeUuidOnlyIdentifier = (text: string): string => {
return text.replace(new RegExp(`\\s+${uuidTextPattern}\\s+(?=已(?:创建|更新|删除))`, "g"), "");
};
const isUuidText = (value: unknown): boolean => {
return new RegExp(`^${uuidTextPattern}$`).test(String(value || "").trim());
};
const splitAuditDetailSegments = (line: string): string[] => {
@@ -280,7 +290,7 @@ export const normalizeAuditEvent = (raw: any, userMap: Record<string, string>):
targetType: raw.entity_type || "",
targetTypeLabel: dict.targetLabel,
targetId: raw.entity_id || "",
targetName: detailObj.targetName || raw.entity_id || "",
targetName: detailObj.targetName || (isUuidText(raw.entity_id) ? "" : raw.entity_id || ""),
actionText: dict.actionText,
before,
after,