rustio_admin/lib.rs
1//! rustio-admin — Django Admin, but for Rust.
2//!
3//! This crate is the public face of the framework. Phase 2 ships the
4//! HTTP / router / server / ORM / migrations / templates core; later
5//! phases populate `auth` and `admin`.
6
7#![forbid(unsafe_code)]
8
9// public:
10pub mod admin;
11// public:
12pub mod auth;
13// public:
14pub mod background;
15// public:
16pub mod email;
17// public:
18pub mod error;
19// public:
20pub mod http;
21// public:
22pub mod middleware;
23// public:
24pub(crate) mod meta;
25pub mod migrations;
26pub(crate) mod multipart;
27// public:
28pub mod orm;
29// public:
30pub mod router;
31// public:
32pub mod server;
33// public:
34pub mod templates;
35
36// public:
37pub use crate::admin::{
38 register_admin_routes, Admin, AdminField, AdminModel, BulkAction, BulkActionContext,
39 BulkActionFailure, BulkActionResult, FieldType, FieldValidationError, Fieldset, Inline,
40 ModelAdmin,
41};
42// public:
43pub use crate::auth::{Identity, Role};
44// public:
45pub use crate::error::{Error, Result};
46// public:
47pub use crate::http::{FormData, Request, Response};
48// public:
49pub use crate::orm::{Db, DbOptions, Model, Row, Value};
50// public:
51pub use crate::router::{Next, Router};
52// public:
53pub use crate::server::Server;
54// public:
55pub use crate::templates::{embedded_template_names, embedded_template_source};
56
57// public:
58pub use rustio_admin_macros::RustioAdmin;
59
60// public: re-exported runtime dependencies.
61//
62// A downstream model crate depends on `rustio-admin` alone: the
63// `RustioAdmin` derive emits paths through these re-exports
64// (`::rustio_admin::chrono::…`, `::rustio_admin::rust_decimal::…`,
65// `::rustio_admin::uuid::…`), and a model's own field types resolve via
66// the bare type aliases below (`use rustio_admin::{Decimal, DateTime,
67// Utc, Uuid};`). This is what lets a scaffolded `Cargo.toml` drop its
68// direct `chrono` / `uuid` / `rust_decimal` / `sqlx` dependencies — the
69// framework already owns those versions, so re-exporting them keeps the
70// whole tree on one resolved copy and removes a class of version-skew
71// bugs. The crates are re-exported as modules (for the macro's
72// fully-qualified paths and for advanced handlers, e.g.
73// `rustio_admin::sqlx::query`); the type aliases are the ergonomic
74// surface model files actually name.
75pub use chrono;
76pub use rust_decimal;
77pub use sqlx;
78pub use uuid;
79// public: the field types a model declares, without a direct dep.
80pub use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
81pub use rust_decimal::Decimal;
82pub use uuid::Uuid;
83
84// `RustioAdmin` emits `::rustio_admin::*` paths in its expansion. That
85// resolves cleanly for downstream consumers, but inside this crate's
86// own compilation unit `rustio_admin` isn't a known extern. Aliasing
87// the crate to itself under `cfg(test)` lets the macro be exercised
88// from this crate's own tests without changing any non-test build.
89#[cfg(test)]
90extern crate self as rustio_admin;
91
92// internal: test-only re-export surface, gated by integration-test feature
93/// Test-only re-exports for the integration-test suite under
94/// `tests/integration_*.rs`. NOT part of the public API — the
95/// module is `#[doc(hidden)]` and gated behind the
96/// `integration-test` Cargo feature, so a regular
97/// `cargo build` / `cargo test --workspace` cannot reach it.
98///
99/// Re-exports the otherwise-`pub(crate)` runtime surface of
100/// `auth::recovery_admin` so the integration tests can exercise
101/// `record_failed_login`, `admin_set_temp_password`, etc. without
102/// promoting the internal API to permanent `pub` visibility.
103///
104/// Plus a `fake_request()` builder for runtime fns that take
105/// `&Request` (currently `lock_user_account`,
106/// `unlock_user_account`, `admin_revoke_sessions`,
107/// `issue_admin_reset_token`, `admin_set_temp_password`). The
108/// fake request has no headers — `client_ip` and
109/// `correlation_id_from` both return `None`, which is the
110/// neutral state for the audit + logging layers.
111///
112/// See `DESIGN_R2_ORGANISATIONAL.md` §10.3 for the integration-
113/// test plan.
114#[doc(hidden)]
115#[cfg(feature = "integration-test")]
116pub mod __integration {
117 // internal: test-only re-export
118 pub use crate::auth::recovery_admin::{
119 admin_revoke_sessions, admin_set_temp_password, check_account_lockout,
120 check_session_elevated, issue_admin_reset_token, lock_user_account,
121 promote_session_elevated, record_failed_login, record_successful_login,
122 unlock_user_account, AdminActor, AdminIssueOutcome, AdminRevokeOutcome, AdminTempPwOutcome,
123 LockDuration, LockOutcome, LockState, ThrottleOutcome, UnlockOutcome,
124 };
125 // R3 MFA — runtime fns + outcomes + key type + pure helpers the
126 // integration suite needs to drive enrolment / verify /
127 // consume / disable / regenerate flows. The `auth::mfa` module
128 // is `pub(crate)`, so this is the only door under the
129 // `integration-test` feature. See `DESIGN_R3_MFA.md` §13.3.
130 // internal: test-only re-export
131 pub use crate::auth::mfa::{
132 confirm_enrolment, consume_backup_code, current_step, disable_mfa, generate_totp,
133 promote_session_to_mfa_verified, provision_secret, regenerate_backup_codes,
134 verify_totp_for_user, BackupConsumeOutcome, DisableOutcome, EnrolOutcome, MfaKey,
135 ProvisionedSecret, RegenOutcome, VerifyOutcome, BACKUP_CODE_COUNT,
136 };
137 // internal: test-only wrapper for the pub(crate) hash helper
138 /// R4 emergency-recovery test-only helper — forwards to the
139 /// `pub(crate)` `auth::sessions::hash_token_for_storage` so
140 /// the integration suite can verify that an
141 /// `emergency_access`-issued URL stores its token in the
142 /// exact same format R1's consume path will look up later.
143 /// Catches the hex-vs-base64 drift surfaced during commit #8
144 /// (which the unit-test gate could not have seen — only a
145 /// live-DB or testcontainers run can). Wrapped rather than
146 /// `pub use`'d because the inner helper is `pub(crate)` and
147 /// cannot be re-exported under a stricter visibility.
148 /// See `DESIGN_R4_EMERGENCY.md` §9.2.
149 pub fn hash_token_for_storage(token: &str) -> String {
150 crate::auth::sessions::hash_token_for_storage(token)
151 }
152
153 // internal: test-only request builder
154 /// Construct a minimal [`crate::http::Request`] for integration
155 /// tests. POST to `/test`, no headers, no body, no params.
156 /// Adequate for runtime fns that read only `client_ip` (None)
157 /// and `correlation_id_from` (None) from the request.
158 pub fn fake_request() -> crate::http::Request {
159 use std::collections::HashMap;
160 crate::http::Request::__integration_test_fake("/test".to_string(), HashMap::new())
161 }
162}