"""审计日志写入。所有敏感操作(建工作区、邀请、加入、移除成员)都要留痕。""" from __future__ import annotations import uuid from typing import Any from sqlalchemy.ext.asyncio import AsyncSession from .models import AuditLog async def record( session: AsyncSession, *, workspace_id: uuid.UUID | None, actor_user_id: uuid.UUID | None, action: str, target_type: str = "", target_id: str = "", payload: dict[str, Any] | None = None, ip: str = "", ) -> None: session.add( AuditLog( workspace_id=workspace_id, actor_user_id=actor_user_id, action=action, target_type=target_type, target_id=target_id, payload=payload or {}, ip=ip, ) ) await session.flush()