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// `RustioAdmin` emits `::rustio_admin::*` paths in its expansion. That
61// resolves cleanly for downstream consumers, but inside this crate's
62// own compilation unit `rustio_admin` isn't a known extern. Aliasing
63// the crate to itself under `cfg(test)` lets the macro be exercised
64// from this crate's own tests without changing any non-test build.
65#[cfg(test)]
66extern crate self as rustio_admin;
67
68// internal: test-only re-export surface, gated by integration-test feature
69/// Test-only re-exports for the integration-test suite under
70/// `tests/integration_*.rs`. NOT part of the public API — the
71/// module is `#[doc(hidden)]` and gated behind the
72/// `integration-test` Cargo feature, so a regular
73/// `cargo build` / `cargo test --workspace` cannot reach it.
74///
75/// Re-exports the otherwise-`pub(crate)` runtime surface of
76/// `auth::recovery_admin` so the integration tests can exercise
77/// `record_failed_login`, `admin_set_temp_password`, etc. without
78/// promoting the internal API to permanent `pub` visibility.
79///
80/// Plus a `fake_request()` builder for runtime fns that take
81/// `&Request` (currently `lock_user_account`,
82/// `unlock_user_account`, `admin_revoke_sessions`,
83/// `issue_admin_reset_token`, `admin_set_temp_password`). The
84/// fake request has no headers — `client_ip` and
85/// `correlation_id_from` both return `None`, which is the
86/// neutral state for the audit + logging layers.
87///
88/// See `DESIGN_R2_ORGANISATIONAL.md` §10.3 for the integration-
89/// test plan.
90#[doc(hidden)]
91#[cfg(feature = "integration-test")]
92pub mod __integration {
93 // internal: test-only re-export
94 pub use crate::auth::recovery_admin::{
95 admin_revoke_sessions, admin_set_temp_password, check_account_lockout,
96 check_session_elevated, issue_admin_reset_token, lock_user_account,
97 promote_session_elevated, record_failed_login, record_successful_login,
98 unlock_user_account, AdminActor, AdminIssueOutcome, AdminRevokeOutcome, AdminTempPwOutcome,
99 LockDuration, LockOutcome, LockState, ThrottleOutcome, UnlockOutcome,
100 };
101 // R3 MFA — runtime fns + outcomes + key type + pure helpers the
102 // integration suite needs to drive enrolment / verify /
103 // consume / disable / regenerate flows. The `auth::mfa` module
104 // is `pub(crate)`, so this is the only door under the
105 // `integration-test` feature. See `DESIGN_R3_MFA.md` §13.3.
106 // internal: test-only re-export
107 pub use crate::auth::mfa::{
108 confirm_enrolment, consume_backup_code, current_step, disable_mfa, generate_totp,
109 promote_session_to_mfa_verified, provision_secret, regenerate_backup_codes,
110 verify_totp_for_user, BackupConsumeOutcome, DisableOutcome, EnrolOutcome, MfaKey,
111 ProvisionedSecret, RegenOutcome, VerifyOutcome, BACKUP_CODE_COUNT,
112 };
113 // internal: test-only wrapper for the pub(crate) hash helper
114 /// R4 emergency-recovery test-only helper — forwards to the
115 /// `pub(crate)` `auth::sessions::hash_token_for_storage` so
116 /// the integration suite can verify that an
117 /// `emergency_access`-issued URL stores its token in the
118 /// exact same format R1's consume path will look up later.
119 /// Catches the hex-vs-base64 drift surfaced during commit #8
120 /// (which the unit-test gate could not have seen — only a
121 /// live-DB or testcontainers run can). Wrapped rather than
122 /// `pub use`'d because the inner helper is `pub(crate)` and
123 /// cannot be re-exported under a stricter visibility.
124 /// See `DESIGN_R4_EMERGENCY.md` §9.2.
125 pub fn hash_token_for_storage(token: &str) -> String {
126 crate::auth::sessions::hash_token_for_storage(token)
127 }
128
129 // internal: test-only request builder
130 /// Construct a minimal [`crate::http::Request`] for integration
131 /// tests. POST to `/test`, no headers, no body, no params.
132 /// Adequate for runtime fns that read only `client_ip` (None)
133 /// and `correlation_id_from` (None) from the request.
134 pub fn fake_request() -> crate::http::Request {
135 use std::collections::HashMap;
136 crate::http::Request::__integration_test_fake("/test".to_string(), HashMap::new())
137 }
138}