Files
AIPortPilot/backend/app/core/audit.py
T
selfrelease fad458b2a7 docs(uiux): UIUX 设计方案大改 + 5 份作业指导书对齐 + 开发任务文档
- UIUX 文档:填充 19 个缺口(多主体画像/健康度/AI+看板/增长域/洞察域/创始人端/OODA/助推/商密)
- UIUX 文档:插入 6 个新章节(十四~十九),旧章节重编号为二十~三十一,更新目录和交叉引用
- 作业指导书 x5:导航改为 6 域分组,新增 Context Bar/工作模式/Insight Rail/决策线程/多工作区等 UI 概念
- 新建 docs/2-task-uiux.md:50 个代码落地开发任务,按 P0-P6 分优先级 + 8 Sprint 规划
- 后端/前端:大量新增模型、路由、组件(来自之前 Phase 开发)
2026-07-19 11:53:38 +08:00

48 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""审计日志装饰器。
自动记录 CREATE/UPDATE/DELETE 操作。
"""
import functools
import logging
from datetime import datetime, timezone
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.audit import AuditLog
logger = logging.getLogger(__name__)
async def log_audit(
db: AsyncSession,
user_id: str,
action: str,
target_type: str,
target_id: str,
detail: dict | None = None,
tenant_id: str | None = None,
) -> None:
"""记录审计日志。
Args:
db: 数据库会话
user_id: 操作用户 ID
action: 操作类型(login/view/create/update/delete/export/ai_call
target_type: 资源类型(映射到 resource_type 字段)
target_id: 资源 ID(映射到 resource_id 字段)
detail: 操作详情字典
tenant_id: 租户 ID
"""
audit = AuditLog(
tenant_id=tenant_id or "",
user_id=user_id,
action=action,
resource_type=target_type,
resource_id=target_id,
detail_json=detail,
created_at=datetime.now(timezone.utc),
)
db.add(audit)
await db.flush()