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
9pub mod admin;
10pub mod auth;
11pub mod background;
12pub mod email;
13pub mod error;
14pub mod http;
15pub mod middleware;
16pub mod migrations;
17pub mod orm;
18pub mod router;
19pub mod server;
20pub mod templates;
21
22pub use crate::admin::{
23    register_admin_routes, Admin, AdminField, AdminModel, FieldType, Fieldset, ModelAdmin,
24};
25pub use crate::auth::{Identity, Role};
26pub use crate::error::{Error, Result};
27pub use crate::http::{FormData, Request, Response};
28pub use crate::orm::{Db, DbOptions, Model, Row, Value};
29pub use crate::router::{Next, Router};
30pub use crate::server::Server;
31
32pub use rustio_admin_macros::RustioAdmin;
33
34// `RustioAdmin` emits `::rustio_admin::*` paths in its expansion. That
35// resolves cleanly for downstream consumers, but inside this crate's
36// own compilation unit `rustio_admin` isn't a known extern. Aliasing
37// the crate to itself under `cfg(test)` lets the macro be exercised
38// from this crate's own tests without changing any non-test build.
39#[cfg(test)]
40extern crate self as rustio_admin;
41
42/// Test-only re-exports for the integration-test suite under
43/// `tests/integration_*.rs`. NOT part of the public API โ€” the
44/// module is `#[doc(hidden)]` and gated behind the
45/// `integration-test` Cargo feature, so a regular
46/// `cargo build` / `cargo test --workspace` cannot reach it.
47///
48/// Re-exports the otherwise-`pub(crate)` runtime surface of
49/// `auth::recovery_admin` so the integration tests can exercise
50/// `record_failed_login`, `admin_set_temp_password`, etc. without
51/// promoting the internal API to permanent `pub` visibility.
52///
53/// Plus a `fake_request()` builder for runtime fns that take
54/// `&Request` (currently `lock_user_account`,
55/// `unlock_user_account`, `admin_revoke_sessions`,
56/// `issue_admin_reset_token`, `admin_set_temp_password`). The
57/// fake request has no headers โ€” `client_ip` and
58/// `correlation_id_from` both return `None`, which is the
59/// neutral state for the audit + logging layers.
60///
61/// See `DESIGN_R2_ORGANISATIONAL.md` ยง10.3 for the integration-
62/// test plan.
63#[doc(hidden)]
64#[cfg(feature = "integration-test")]
65pub mod __integration {
66    pub use crate::auth::recovery_admin::{
67        admin_revoke_sessions, admin_set_temp_password, check_account_lockout,
68        check_session_elevated, issue_admin_reset_token, lock_user_account,
69        promote_session_elevated, record_failed_login, record_successful_login,
70        unlock_user_account, AdminActor, AdminIssueOutcome, AdminRevokeOutcome, AdminTempPwOutcome,
71        LockDuration, LockOutcome, LockState, ThrottleOutcome, UnlockOutcome,
72    };
73
74    /// Construct a minimal [`crate::http::Request`] for integration
75    /// tests. POST to `/test`, no headers, no body, no params.
76    /// Adequate for runtime fns that read only `client_ip` (None)
77    /// and `correlation_id_from` (None) from the request.
78    pub fn fake_request() -> crate::http::Request {
79        use std::collections::HashMap;
80        crate::http::Request::__integration_test_fake("/test".to_string(), HashMap::new())
81    }
82}