git-subtree-dir: fiscal git-subtree-mainline:d95165fc8fgit-subtree-split:102ba84500
12 lines
598 B
Python
12 lines
598 B
Python
"""Immutable audit events for human control-plane actions."""
|
|
|
|
from .events import sanitize_event
|
|
from .models import AuditEvent
|
|
|
|
|
|
def record_audit(session, *, admin_user_id: int | None, action: str, target_type: str, target_id: str, context: dict | None = None, tenant_id: int | None = None, severity: str = "INFO"):
|
|
_, safe_context = sanitize_event(action, context or {})
|
|
event = AuditEvent(admin_user_id=admin_user_id, tenant_id=tenant_id, action=action, target_type=target_type, target_id=str(target_id), context=safe_context, severity=severity)
|
|
session.add(event)
|
|
return event
|