Files
smart-org/apps/api/app/application/services/audit_service.py
T
mjalmoudy94 717e53a7ce نسخهٔ وب مستقل — پلتفرم نیروی کار هوش مصنوعی
مخزن اختصاصی برنامهٔ وب؛ محتوای پوشهٔ web در ریشهٔ مخزن قرار گرفت.
تاریخچهٔ پروژهٔ ربات (agy-bot) در این مخزن وجود ندارد و هیچ وابستگی runtime به آن نیست.
2026-10-13 00:39:28 +03:30

38 lines
1003 B
Python

"""Audit helper used by the HTTP layer.
Every sensitive operation calls this. It is deliberately cheap (one INSERT) so
there is no excuse to skip it.
"""
from __future__ import annotations
from sqlalchemy.ext.asyncio import AsyncSession
from app.domain.audit.models import AuditEvent
from app.infrastructure.repositories.audit import AuditRepository
async def record_audit(
session: AsyncSession,
*,
action: str,
organization_id: str | None = None,
actor_user_id: str | None = None,
target_type: str = "",
target_id: str = "",
metadata: dict | None = None,
ip: str = "",
user_agent: str = "",
) -> AuditEvent:
event = AuditEvent(
action=action,
organization_id=organization_id,
actor_user_id=actor_user_id,
target_type=target_type,
target_id=target_id,
metadata_json=metadata or {},
ip_address=ip,
user_agent=user_agent,
)
return await AuditRepository(session).record(event=event)