1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// adminx-audit/src/lib.rs
//
// Audit logging for adminx. Register it and every create / update / delete that
// goes through the default `Resource` CRUD is recorded with who did it and a
// per-column before/after diff; leave it out and adminx behaves exactly as it
// did, issuing not one extra query.
//
// Storage-agnostic: rows are written through adminx-core's `Storage` trait, so
// the same crate works over SeaORM (SQL) or MongoDB. The one asymmetry is table
// creation — see `migrate_sql`.
//
// ## Startup order
//
// ```ignore
// adminx_seaorm::init(&db_url).await?; // 1. storage
// adminx_core::seed(adminx_audit::migrate_sql()).await?; // 2. SQL table (SQL backends only)
// adminx_audit::init(AuditConfig::default()); // 3. register the auditor
// configure_auth(AuthConfig { /* ... */ }); // 4. turn auth on
// register_resource(Box::new(MyResource));
// adminx_audit::register_resources(); // 5. the in-panel viewer (optional)
// ```
//
// ## What is and isn't recorded
//
// The hook lives on the `Resource` trait's default `create` / `update` /
// `delete`, because only that layer holds the `ReqCtx` that identifies the
// actor. A resource that *extends* the defaults keeps its recording as long as
// it delegates to `adminx_core::crud::{create, update, delete}` rather than
// copying the body — `adminx-rbac`'s `PermissionResource` does exactly that. A
// resource that replaces them outright records nothing unless it emits its own
// entry; see [`adminx_core::audit::emit`].
//
// Writes that bypass adminx entirely (a migration, psql, another service) are
// invisible to this crate by construction. If you need those too, the answer is
// database triggers, not an application-level log.
pub use AuditVersionResource;
pub use ;
/// How the auditor behaves when it cannot write.
/// Register the auditor with adminx-core. Call after storage is set (and, on a
/// SQL backend, after running [`migrate_sql`]).
///
/// Set-once, matching `set_storage` / `set_authorizer`: a second call is ignored
/// with a warning.
/// SQL `CREATE TABLE IF NOT EXISTS` + index statements for the audit table. Run
/// once on a SQL backend via `adminx_core::seed(adminx_audit::migrate_sql())`.
/// Mongo needs nothing (collections auto-create).
/// Register the read-only in-panel log viewer at `/adminx/adminx-audit-versions/list`.
/// Optional — omit it to keep the log out of the UI and query it directly.