Skip to main content

Admin

Struct Admin 

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

The admin plugin: .plugin(Admin::new()).

Implementations§

Source§

impl Admin

Source

pub fn new() -> Self

The default config: roles admin (every admin action but impersonating admins) and user (none), new users get user, and admin counts as an admin role.

Source

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

The role new users get (default "user").

Source

pub fn admin_roles( self, roles: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Roles whose holders count as admins (default ["admin"]): they can’t be impersonated without user:impersonate-admins, and they pass RequireRole<_, role::Admin>. Each must be a defined role; .build() panics otherwise, like Better Auth.

Source

pub fn admin_user_ids( self, ids: impl IntoIterator<Item = impl Into<Id>>, ) -> Self

Users who are admins whatever their role: every permission check passes for them, and they pass RequireRole<_, role::Admin>.

Source

pub fn impersonation_session_duration(self, duration: Duration) -> Self

How long an impersonation session lasts (default one hour).

Source

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

The reason stored when a ban gives none (default "No reason").

Source

pub fn default_ban_expires_in(self, duration: Duration) -> Self

How long bans last when the request gives no expiry (default: for good).

Source

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

What a banned user’s sign-in answers with, before the ban’s reason.

Source

pub fn role(self, name: impl Into<String>, permissions: Permissions) -> Self

Defines a role, or replaces a built-in one (admin, user).

Source

pub fn roles_of<'a>( &'a self, role: Option<&'a str>, ) -> impl Iterator<Item = &'a str>

The role names in a user.role value, or the default role when it is empty.

Source

pub fn has_role_defined(&self, role: &str) -> bool

Whether the role is defined.

Source

pub fn is_admin(&self, user_id: &Id, role: Option<&str>) -> bool

Whether this user is an admin: listed in admin_user_ids, or holding an admin role.

Source

pub fn has_permission( &self, user_id: &Id, role: Option<&str>, permissions: &Permissions, ) -> bool

Whether a user with this id and user.role value may do everything in permissions: true for admin_user_ids, else when one of their roles grants it all.

Source

pub fn has_role(&self, user_id: &Id, role: Option<&str>, name: &str) -> bool

Whether the user holds name, counting every admin as holding each admin role.

Trait Implementations§

Source§

impl Clone for Admin

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Admin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Admin

Source§

fn default() -> Self

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

impl Plugin for Admin

Source§

const ID: &'static str = "admin"

Unique id, used in error messages, schema ownership and derived keys.
Source§

type Requires = ()

Plugins that must be registered before this one, as a tuple: (), (Organization,).
Source§

type UserFields = AdminUser

Columns this plugin adds to user; () for none.
Source§

type SessionFields = AdminSession

Columns this plugin adds to session; () for none.
Source§

fn init<D: Adapter>(self: &Arc<Self>, app: &mut PluginBuilder<'_, D>)

Registers endpoints, hooks, gates, resolvers, events, rate limits and error codes. Runs once, inside .build().
Source§

fn schema(&self, schema: &mut SchemaBuilder)

Adds tables (schema.model::<M>()) or columns. UserFields and SessionFields are added automatically.

Auto Trait Implementations§

§

impl Forget for Admin

§

impl Freeze for Admin

§

impl Move for Admin

§

impl RefUnwindSafe for Admin

§

impl Send for Admin

§

impl Sync for Admin

§

impl Unpin for Admin

§

impl UnsafeUnpin for Admin

§

impl UnwindSafe for Admin

Blanket Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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