Skip to main content

AdminPlugin

Struct AdminPlugin 

Source
pub struct AdminPlugin { /* private fields */ }
Expand description

The admin panel plugin.

Register models via .register() and the plugin will mount a full admin UI under the configured prefix (default: /admin).

Implementations§

Source§

impl AdminPlugin

Source

pub fn new() -> Self

Create a new admin plugin with default settings.

Mounts at /admin and requires the "admin" role in the session. Links to the actuator UI under /actuator. Reads the user identifier from session key "user_id" (Autumn’s default auth.session_key).

Source

pub fn prefix(self, prefix: impl Into<String>) -> Self

Override the URL prefix (default: /admin).

Source

pub fn actuator_prefix(self, prefix: impl Into<String>) -> Self

Override the actuator mount prefix that dashboard links/polling target (default: /actuator). Must match config.actuator.prefix from your autumn config — the plugin cannot read it automatically because config is loaded after Plugin::build runs.

Source

pub fn auth_session_key(self, key: impl Into<String>) -> Self

Override the session key the role middleware reads to detect an authenticated user. Default: "user_id", matching Autumn’s default auth.session_key. Must match whatever your application populates after login — e.g. set this to "uid" if you configured auth.session_key = "uid".

The plugin can’t read config.auth.session_key automatically because config is loaded after Plugin::build runs.

Source

pub fn require_role(self, role: impl Into<Option<String>>) -> Self

Set the required session role for accessing the admin panel.

Pass None to disable role checks entirely. Authentication (a populated user_id session key) is always required when a role is set.

Source

pub fn register<M: AdminModel>(self, model: M) -> Self

Register a model for admin management.

The model must implement AdminModel, which provides field metadata, CRUD operations, and display configuration.

Source

pub fn with_runtime_config(self, svc: Arc<RuntimeConfigService>) -> Self

Enable the runtime config management page.

Mounts GET /config, POST /config/{key}/set, POST /config/{key}/unset, and GET /config/{key}/history under the admin prefix, and adds a “Runtime Config” item to the sidebar navigation.

Source

pub const fn with_step_up_mutations(self) -> Self

Require step-up (fresh) authentication before any mutating admin action.

When enabled, every POST (create/update) and DELETE (destroy) request to the admin panel is checked against the session’s last_strong_auth_at claim using the global step-up max-age configured in [auth.step_up] (default: 5 minutes). Requests without a valid fresh-auth claim are redirected to /reauth?return_to=… (HTML clients) or receive a 401 step_up_required problem-details response (JSON clients).

Highly recommended for production admin panels to reduce the blast radius of a hijacked admin session.

§Example
ⓘ
AdminPlugin::new()
    .register(UserAdmin::default())
    .with_step_up_mutations()
Source

pub const fn with_step_up_max_age(self, secs: u64) -> Self

Override the step-up freshness window for admin mutations.

Only meaningful when with_step_up_mutations is also called. Calls with_step_up_mutations implicitly.

§Example
ⓘ
AdminPlugin::new()
    .register(UserAdmin::default())
    .with_step_up_max_age(600) // 10-minute window
Source

pub fn with_impersonation(self, gate: ImpersonationGate) -> Self

Enable user impersonation (“log in as this user”) for this admin panel, gated by gate (issue #1394).

Opt-in in two senses. Without this call the impersonation routes are not mounted at all, and the core primitive (autumn_web::auth::impersonation) default-denies — so an app can never acquire impersonation by accident. With it, two routes appear:

RouteGuard
POST {prefix}/impersonate (body: user_id)admin role + step-up (if enabled) + gate
POST {prefix}/impersonate/stopnone — reverting must always work

Every admin page then renders the persistent “Viewing as … — Stop impersonating” banner. Put the same banner in your application layout with impersonation_banner_for so it is visible on the pages the operator is actually looking at.

Requires an audit sink. begin_impersonation refuses with 500 unless the app has an AuditLogger carrying at least one sink, because an unrecorded identity swap is the exact failure this feature exists to prevent. The plugin logs an error at startup when the sink is missing.

The gate is also where an app enforces its own boundaries — in particular tenancy, which the framework cannot infer: the policy receives the full PolicyContext, session and DB pool included.

§Example
ⓘ
use autumn_web::auth::impersonation::ImpersonationGate;

AdminPlugin::new()
    .register(UserAdmin::default())
    .with_impersonation(ImpersonationGate::allow_roles(["admin"]))

Trait Implementations§

Source§

impl Default for AdminPlugin

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Plugin for AdminPlugin

Source§

fn contract(&self) -> Option<PluginContract>

This plugin ships in lockstep with autumn-web — see lockstep_contract.

Source§

fn name(&self) -> Cow<'static, str>

Stable identifier used for duplicate-registration detection. Read more
Source§

fn build(self, app: AppBuilder) -> AppBuilder

Apply this plugin’s configuration to the builder. Read more
Source§

fn route_group(&self) -> Cow<'static, str>

The route group of the routes this plugin adds (#3544). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutumnCounterCaches for T
where T: 'static,

Source§

const HAS_COUNTER_CACHES: bool = false

Whether this model has any counter cache at all. Read more
Source§

fn counter_caches() -> &'static [CounterCacheSpec<Self>]

The model’s counter-cache specs, in declaration order.
Source§

impl<T> AutumnDependents for T
where T: ?Sized,

Source§

fn dependents() -> &'static [RuntimeDependentSpec]

The model’s dependent-cascade specs, in declaration order. Defaults to none; #[model] overrides via an inherent shadow when dependents exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<P> Plugins for P
where P: Plugin,

Source§

fn apply(self, app: AppBuilder) -> AppBuilder

Apply every plugin in this bundle to the builder, in declaration order.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> RepositoryHooksDefault for T
where T: Default,

Source§

fn autumn_default() -> T

Construct a hook instance for generated repository state.
Source§

impl<T, Conn> RunQueryDsl<Conn> for T

Source§

fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
where Conn: AsyncConnectionCore + Send, Self: ExecuteDsl<Conn> + 'query,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn load_stream<'conn, 'query, U>( self, conn: &'conn mut Conn, ) -> Self::LoadFuture<'conn>
where Conn: AsyncConnectionCore, U: 'conn, Self: LoadQuery<'query, Conn, U> + 'query,

Executes the given query, returning a [Stream] with the returned rows. Read more
Source§

fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
where U: Send, Conn: AsyncConnectionCore, Self: LoadQuery<'query, Conn, U> + 'query,

Runs the command, returning an Vec with the affected rows. Read more
Source§

fn first<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<<Self::Output as LoadQuery<'query, Conn, U>>::LoadFuture<'conn>, LoadNext<Pin<Box<<Self::Output as LoadQuery<'query, Conn, U>>::Stream<'conn>>>>>
where U: Send + 'conn, Conn: AsyncConnectionCore, Self: LimitDsl, Self::Output: LoadQuery<'query, Conn, U> + Send + 'query,

Attempts to load a single record. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more