fix(cma): 工作台跨实体治本 · DAMA 回查收口 — 审计可归属 + 通知日志口径
DAMA 独立回查 dama-recheck-workbench-entity-isolation-20260922 的 §4b/§5 两处待办:
1. POST /api/cma/tenant/switch 审计行原来不可归属:
- user_id=None → 改为注入会话用户(user=Depends(require_auth_401))
- target_type/target_id 从 system_config/None 对齐为 entity/<entity_id>,
与 /auth/switch-entity 的 switch_entity 共用目标维度 ⇒ 按账套可过滤,零 DDL
- action 字面 switch_tenant_state 保留不合并(与会话级 switch_entity 语义不同),
口径登记 docs/audit-and-notification-caliber-20260922.md
2. /api/cma/notifications/logs 增加 policy/note 口径字段,前端发送记录表
empty-text 提示同一口径 —— 避免「B2 上线后 e1/e2 均 0 条」被当成页面故障
(现库 8 行历史记录全为 alert_id IS NULL 的 OKR 复盘提醒,无账套归属)
回归:tests/test_workbench_entity_isolation_20260922.py 22/22;全量 1370 passed;前端 vite build 通过
This commit is contained in:
@@ -298,6 +298,14 @@ class TestP0CurrentTenantConvergence:
|
||||
db.expire_all()
|
||||
n = db.query(OperationLog).filter(OperationLog.action == "switch_tenant_state").count()
|
||||
assert n == 1, f"switch 应落 1 条审计,实际 {n}"
|
||||
# 审计行必须可归属(2026-09-22 DAMA 独立回查 §4b):操作人 + 账套目标维度
|
||||
log = (db.query(OperationLog)
|
||||
.filter(OperationLog.action == "switch_tenant_state")
|
||||
.order_by(OperationLog.id.desc()).first())
|
||||
assert log.user_id is not None, "审计行 user_id 不得为 None(事后须能追操作人)"
|
||||
assert log.target_type == "entity" and log.target_id == 2, (
|
||||
f"审计须按账套可过滤(target_type/target_id),实际 {log.target_type}/{log.target_id}")
|
||||
assert (log.detail or {}).get("entity_id") == 2, f"detail 须含 entity_id:{log.detail}"
|
||||
# 全局键虽被改成 e2,e1 会话工作台仍只见 e1 数据
|
||||
codes1 = {k["kpi_code"] for k in
|
||||
client.get(f"{DASH}/my-kpis", headers=auth_header(t1)).json()["data"]}
|
||||
@@ -522,6 +530,10 @@ class TestB2NotificationLogScoping:
|
||||
assert titles2 == {"e2 通知"}, f"e2 会话通知日志混入他账套/无归属行:{titles2}"
|
||||
assert l1["total"] == 1 and l2["total"] == 1
|
||||
assert l1["entity_id"] == 1 and l2["entity_id"] == 2
|
||||
# 口径字段(2026-09-22 DAMA 回查 §5):空页要能解释成口径而非故障
|
||||
for l in (l1, l2):
|
||||
assert l["policy"] == "alert-linked-only", l
|
||||
assert "无父键" in l["note"] and "okr_review_reminder" in l["note"], l
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user