From the ROADMAP adjudication (12 of 13 DO items; D2 is a commit action). Backend: - B3: pytest suite (auth, entity CRUD, rollup) + dev deps + pytest config - B4: cap document uploads at TEN31_MAX_UPLOAD_SIZE (default 50MB), stream- checked with partial-file cleanup, 413 on overflow - B7: type AuditLog.detail as dict|list|str|None to match the JSON column - B10: index foreign-key columns (migration a7b8c9d0e1f2 + index=True) - B11: cli delete-user logs file-removal errors instead of swallowing them Frontend: - F2: distinguish "server unreachable" from "logged out"; retry prompt - F4: confirm before destructive holdings-replace on import; step progress - F6: expandable audit-log detail with full JSON - F7: empty-state on the Investments page - F8: shared role helpers (WRITER_ROLES/canEditRound/isApprover), used by EntitiesList, AuditLog, Import, ValuationWorkflow Deploy: - D5: run tsc --noEmit before packaging (build script) - D6: TEN31_LOG_LEVEL env var (defaults to info) Verified: 8/8 backend tests pass; alembic upgrades to head with 13 FK indexes; upload limit rejects oversized + cleans up; frontend tsc + vite build clean; dev server serves and proxies to the API.
35 lines
876 B
Python
35 lines
876 B
Python
"""Audit log helper. Every state-changing endpoint must call record_audit."""
|
|
|
|
import json
|
|
from typing import Any
|
|
|
|
from sqlmodel import Session
|
|
|
|
from ten31portal.models import AuditLog
|
|
|
|
|
|
def record_audit(
|
|
session: Session,
|
|
actor_user_id: int | None,
|
|
action: str,
|
|
object_type: str,
|
|
object_id: int | None = None,
|
|
detail: Any = None,
|
|
) -> AuditLog:
|
|
"""Write one audit log entry and flush it.
|
|
|
|
``detail`` is a small JSON-serializable payload describing the change (typically a dict of
|
|
changed fields, sometimes an identifying value on delete, or None). It is persisted to a
|
|
JSON column on AuditLog.
|
|
"""
|
|
entry = AuditLog(
|
|
actor_user_id=actor_user_id,
|
|
action=action,
|
|
object_type=object_type,
|
|
object_id=object_id,
|
|
detail=detail,
|
|
)
|
|
session.add(entry)
|
|
session.flush()
|
|
return entry
|