Full-stack self-hosted finance app with FastAPI backend and React frontend. Features: - Accounts, transactions, budgets, investments with GBP base currency - CSV import with auto-detection for 10 UK bank formats - ML predictions: spending forecast, net worth projection, Monte Carlo - 7 selectable themes (Obsidian, Arctic, Midnight, Vault, Terminal, Synthwave, Ledger) - Receipt/document attachments on transactions (JPEG, PNG, WebP, PDF) - AES-256-GCM field encryption, RS256 JWT, TOTP 2FA, RLS, audit log - Encrypted nightly backups + key rotation script - Mobile-responsive layout with bottom nav Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
990 B
Python
38 lines
990 B
Python
"""
|
|
Append-only audit log writer.
|
|
"""
|
|
from __future__ import annotations
|
|
import uuid
|
|
from datetime import datetime, timezone
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
async def write_audit(
|
|
db: "AsyncSession",
|
|
*,
|
|
user_id: uuid.UUID | None,
|
|
action: str,
|
|
resource_type: str | None = None,
|
|
resource_id: uuid.UUID | None = None,
|
|
ip_address: str | None = None,
|
|
user_agent: str | None = None,
|
|
metadata: dict[str, Any] | None = None,
|
|
success: bool = True,
|
|
) -> None:
|
|
from app.db.models.audit_log import AuditLog
|
|
log = AuditLog(
|
|
user_id=user_id,
|
|
action=action,
|
|
resource_type=resource_type,
|
|
resource_id=resource_id,
|
|
ip_address=ip_address,
|
|
user_agent=user_agent,
|
|
meta=metadata or {},
|
|
success=success,
|
|
created_at=datetime.now(timezone.utc),
|
|
)
|
|
db.add(log)
|
|
# Note: caller is responsible for committing
|