pub struct Admin { /* private fields */ }Expand description
The admin plugin: .plugin(Admin::new()).
Implementations§
Source§impl Admin
impl Admin
Sourcepub fn new() -> Self
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.
Sourcepub fn default_role(self, role: impl Into<String>) -> Self
pub fn default_role(self, role: impl Into<String>) -> Self
The role new users get (default "user").
Sourcepub fn admin_roles(
self,
roles: impl IntoIterator<Item = impl Into<String>>,
) -> Self
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.
Sourcepub fn admin_user_ids(
self,
ids: impl IntoIterator<Item = impl Into<Id>>,
) -> Self
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>.
Sourcepub fn impersonation_session_duration(self, duration: Duration) -> Self
pub fn impersonation_session_duration(self, duration: Duration) -> Self
How long an impersonation session lasts (default one hour).
Sourcepub fn default_ban_reason(self, reason: impl Into<String>) -> Self
pub fn default_ban_reason(self, reason: impl Into<String>) -> Self
The reason stored when a ban gives none (default "No reason").
Sourcepub fn default_ban_expires_in(self, duration: Duration) -> Self
pub fn default_ban_expires_in(self, duration: Duration) -> Self
How long bans last when the request gives no expiry (default: for good).
Sourcepub fn banned_user_message(self, message: impl Into<String>) -> Self
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.
Sourcepub fn role(self, name: impl Into<String>, permissions: Permissions) -> Self
pub fn role(self, name: impl Into<String>, permissions: Permissions) -> Self
Defines a role, or replaces a built-in one (admin, user).
Sourcepub fn roles_of<'a>(
&'a self,
role: Option<&'a str>,
) -> impl Iterator<Item = &'a str>
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.
Sourcepub fn has_role_defined(&self, role: &str) -> bool
pub fn has_role_defined(&self, role: &str) -> bool
Whether the role is defined.
Sourcepub fn is_admin(&self, user_id: &Id, role: Option<&str>) -> bool
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.
Sourcepub fn has_permission(
&self,
user_id: &Id,
role: Option<&str>,
permissions: &Permissions,
) -> bool
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.
Trait Implementations§
Source§impl Plugin for Admin
impl Plugin for Admin
Source§const ID: &'static str = "admin"
const ID: &'static str = "admin"
Source§type Requires = ()
type Requires = ()
(), (Organization,).Source§type UserFields = AdminUser
type UserFields = AdminUser
user; () for none.Source§type SessionFields = AdminSession
type SessionFields = AdminSession
session; () for none.Source§fn init<D: Adapter>(self: &Arc<Self>, app: &mut PluginBuilder<'_, D>)
fn init<D: Adapter>(self: &Arc<Self>, app: &mut PluginBuilder<'_, D>)
.build().Source§fn schema(&self, schema: &mut SchemaBuilder)
fn schema(&self, schema: &mut SchemaBuilder)
schema.model::<M>()) or columns. UserFields and SessionFields are
added automatically.