feat(system): expose platform audit log + polish audit drawers

The system_settings update, system admin promote/revoke, and
apply-default-storage-quota routes have been writing audit rows since
the prior commits, but with TenantID=0 (system-scope). The per-tenant
GET /tenants/:id/audit-log endpoint filters by tenant_id and never
returns them, so until now those rows existed only in the DB with no UI
surface. This commit closes the loop:

Backend:
- GET /api/v1/system/admin/audit-log: new SystemAdmin-gated endpoint
  reusing AuditLogService.List with tenant_id=0. Same cursor-paged
  shape and query params (after_id / limit / action / outcome / actor)
  as the per-tenant feed, so the frontend reuses the same client logic.
- Wired through RegisterSystemAdminRoutes (mounted on the existing
  adminRoutes group so it inherits the SystemAdmin() guard). The
  handler dependency is optional: nil auditLogHandler skips the route,
  mirroring RegisterTenantRoutes' /audit-log handling.

Frontend — new platform audit drawer in SystemSettings.vue:
- "审计日志" entry button in the section header opens a side drawer
  (880px) listing system-scope events. Lazy-loaded on first open;
  refresh is explicit via a button inside the drawer.
- Table columns: stacked date/time (so 50 events in the same minute
  remain distinguishable), stacked actor/role, action tag, structured
  target (subject key + diff line), outcome. The dead request column
  (system actions don't go through middleware path capture) is dropped
  in favour of richer target rendering.
- Per-action target formatters:
    * system.setting_changed: subject = registry key, diff = `old → new`
      (JSON-encoded, 80-char truncation). Reset shows `old → (空)`.
    * tenant_storage_quota bulk apply: subject = "批量同步", diff =
      "applied to N tenants (X GB)".
    * system.admin_promoted / revoked: subject = "name (email)", diff
      annotates idempotent / noop branches so an audit reader can tell
      a real grant from a probe.
- Click-to-expand row reveals the full audit context: actor UUID,
  target_user_id / target_type / target_id, and raw details JSON in
  monospaced scroll-capped block. No psql round-trip needed for
  forensic spot checks.
- Sticky thead pinned to the scroll container so column labels survive
  long scrolls. Cells vertical-aligned middle to keep single-line tag
  cells visually balanced against multi-line target cells. No zebra
  stripes — the stacked content already provides row separation, and
  stripes on top read as noise.

Frontend — same polish back-ported to TenantMembers.vue audit drawer:
- Same drawer width, stacked time / actor cells, structured target +
  diff layout, expandable raw-details row, sticky thead, vertical-
  align middle, no stripes. Refresh button reformulated as a text
  button with label (was an outlined square icon-only).
- request_path column kept (rbac.access_denied carries meaningful
  paths) but empty values render as a placeholder dash so they don't
  read as broken.
- Diff line now covers rbac.invitation_sent / invitation_revoked role
  in addition to the existing role_changed / access_denied details.

API:
- frontend/src/api/system/index.ts: listSystemAuditLog() reuses the
  AuditLog / ListAuditLogParams types from @/api/tenant/audit-log
  (re-exported) so consumers don't need to cross-import.

i18n (zh-CN / en-US / ko-KR / ru-RU):
- system.globalSettings.audit.*: full drawer copy + per-action labels
  (system.setting_changed / admin_promoted / admin_revoked) + target
  diff templates + expanded-row labels.
- tenantMember.audit.expanded.*: expanded-row labels added so the
  shared drawer treatment renders cleanly under tenant scope.
This commit is contained in:
wizardchen
2026-05-26 20:04:08 +08:00
committed by lyingbug
parent 9cce0c8e5e
commit acdc0a526f
9 changed files with 1534 additions and 55 deletions
+57
View File
@@ -1895,6 +1895,56 @@ export default {
success: "已将 {count} 个租户的存储配额更新为 {gb} GB",
failed: "应用到所有租户失败",
},
audit: {
tabLabel: "审计日志",
description:
"记录平台级操作:系统设置变更、系统管理员授予/回收、配额批量同步等。按时间倒序展示。",
refresh: "刷新",
retry: "重试",
loading: "加载中...",
end: "已经到底了。",
empty: "暂无平台级审计事件。",
forbidden: "无权查看平台审计日志。",
systemActor: "系统",
errors: {
generic: "加载审计日志失败",
},
actorRole: {
system_admin: "系统管理员",
},
columns: {
time: "时间",
actor: "操作人",
action: "事件",
target: "目标",
path: "请求",
outcome: "结果",
},
action: {
"system.setting_changed": "系统设置变更",
"system.admin_promoted": "授予系统管理员",
"system.admin_revoked": "回收系统管理员",
},
outcome: {
success: "成功",
denied: "拒绝",
},
target: {
bulkQuota: "批量同步:默认存储配额",
bulkQuotaDiff: "应用到 {count} 个租户({gb} GB)",
promoteIdempotent: "目标已是系统管理员(幂等)",
revokeNoop: "目标本就不是系统管理员(幂等)",
requiredRole: "需要角色:{role}",
valueNull: "(空)",
},
expanded: {
actorId: "操作人 ID",
targetUserId: "目标用户 ID",
targetType: "目标类型",
targetId: "目标 ID",
details: "原始详情",
},
},
},
},
mcp: {
@@ -4701,6 +4751,13 @@ export default {
success: "成功",
denied: "拒绝",
},
expanded: {
actorId: "操作人 ID",
targetUserId: "目标用户 ID",
targetType: "目标类型",
targetId: "目标 ID",
details: "原始详情",
},
},
},
tenantInvitation: {