diff options
Diffstat (limited to 'src/db/queries.rs')
| -rw-r--r-- | src/db/queries.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/db/queries.rs b/src/db/queries.rs index 18f91cd..23b95ec 100644 --- a/src/db/queries.rs +++ b/src/db/queries.rs @@ -82,6 +82,13 @@ pub fn audit( } /// An audit row to append inside someone else's transaction. +/// +/// Build one with [`AuditEntry::human`] or [`AuditEntry::system`] rather than +/// by writing the literal: `actor_kind` is a closed set and the timestamp is +/// not the caller's to improvise (§6 m-4). Three review sites had each +/// hand-built this struct, and their `detail` shapes drifted until the log +/// could not answer, for two of the three, which candidate bytes the decision +/// was about. #[derive(Debug)] pub struct AuditEntry<'a> { pub at: &'a str, @@ -93,6 +100,31 @@ pub struct AuditEntry<'a> { pub detail: serde_json::Value, } +impl<'a> AuditEntry<'a> { + /// A decision a named human made (§11: every approval is attributable). + pub fn human( + at: &'a str, + actor: &'a str, + action: &'a str, + entity: &'a str, + entity_id: &'a str, + detail: serde_json::Value, + ) -> Self { + Self { at, actor_kind: "human", actor, action, entity, entity_id, detail } + } + + /// Something the server did by itself: a publish, a requeue, a watcher tick. + pub fn system( + at: &'a str, + action: &'a str, + entity: &'a str, + entity_id: &'a str, + detail: serde_json::Value, + ) -> Self { + Self { at, actor_kind: "system", actor: "", action, entity, entity_id, detail } + } +} + /// Append an audit row inside a caller's transaction (I10). This is the variant /// every multi-statement mutation uses: the record of a decision commits with /// the decision or not at all, so there is no window where an audit row |
