Skip to main content

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