flip_api.trusts_services.utils.audit_helper

Functions

audit_trust_action(...)

Insert an audit log row for a trust-registry mutation.

Module Contents

flip_api.trusts_services.utils.audit_helper.audit_trust_action(trust_id: uuid.UUID, trust_name: str, action: flip_api.domain.schemas.actions.TrustAuditAction, user_id: uuid.UUID | None, session: sqlmodel.Session) flip_api.db.models.main_models.TrustsAudit

Insert an audit log row for a trust-registry mutation.

Mirrors the project / model audit helpers in pattern — the caller is responsible for the surrounding transaction commit.

Parameters:
  • trust_id (UUID) – ID of the trust being audited. Stored as a bare UUID (no FK) so the row survives hard-delete of the trust.

  • trust_name (str) – Human-readable name at the time of the action. Denormalised here so audit queries remain meaningful after hard-delete.

  • action (TrustAuditAction) – The action performed.

  • user_id (UUID | None) – Cognito sub of the authenticated admin (UI path), or None when called from the deploy CLI.

  • session (Session) – SQLModel session — the helper does NOT commit.

Returns:

The newly-flushed audit row.

Return type:

TrustsAudit

Raises:

ValueError – If the audit row cannot be persisted.