Skip to main content

AdminApi

Struct AdminApi 

Source
pub struct AdminApi<'a, A> { /* private fields */ }
Expand description

Runs admin operations from server code. Calls are trusted: they need no session and skip the permission checks, but run the same hooks and events as the HTTP routes. Impersonation acts for a signed-in admin, so it takes the request’s headers.

Implementations§

Source§

impl<A: AuthInstance> AdminApi<'_, A>

Source

pub async fn create_user( &self, input: CreateUserInput, ) -> Result<UserView, AuthError>

Creates a user with a role, a password and any user columns.

Source

pub async fn list_users( &self, query: ListUsersQuery, ) -> Result<UserList, AuthError>

Lists users with search, filter, sort and pagination.

Source

pub async fn get_user(&self, id: &Id) -> Result<UserView, AuthError>

One user by id.

Source

pub async fn set_role( &self, user_id: &Id, role: impl Into<Roles>, ) -> Result<UserView, AuthError>

Replaces a user’s roles.

Source

pub async fn ban(&self, input: BanUserInput) -> Result<UserView, AuthError>

Bans a user and revokes every session they have.

Source

pub async fn unban(&self, user_id: &Id) -> Result<UserView, AuthError>

Lifts a user’s ban.

Source

pub async fn update_user( &self, user_id: &Id, data: Map<String, Json>, ) -> Result<UserView, AuthError>

Updates user columns by camelCase name, as /admin/update-user does.

Source

pub async fn set_user_password( &self, user_id: &Id, new_password: &str, ) -> Result<(), AuthError>

Sets a user’s password, creating their credential account if needed.

Source

pub async fn remove_user(&self, user_id: &Id) -> Result<(), AuthError>

Deletes a user with their sessions and accounts.

Source

pub async fn list_user_sessions( &self, user_id: &Id, ) -> Result<Vec<Map<String, Json>>, AuthError>

A user’s unexpired sessions, as client JSON.

Source

pub async fn revoke_user_session( &self, session_token: &str, ) -> Result<(), AuthError>

Revokes the session with this raw token.

Source

pub async fn revoke_user_sessions(&self, user_id: &Id) -> Result<(), AuthError>

Revokes every session of a user.

Source

pub async fn has_permission( &self, user_id: &Id, permissions: Permissions, ) -> Result<bool, AuthError>

Whether the user may do everything in permissions. Unknown users may do nothing.

Source

pub async fn impersonate( &self, headers: &HeaderMap, user_id: &Id, ) -> Result<ApiResponse<SessionOutput>, AuthError>

POST /admin/impersonate-user as the admin whose session cookie is in headers. The response’s cookies switch the browser to the user.

Source

pub async fn stop_impersonating( &self, headers: &HeaderMap, ) -> Result<ApiResponse<SessionOutput>, AuthError>

POST /admin/stop-impersonating for the impersonation session in headers.

Auto Trait Implementations§

§

impl<'a, A> Forget for AdminApi<'a, A>

§

impl<'a, A> Freeze for AdminApi<'a, A>
where &'a A: Freeze,

§

impl<'a, A> Move for AdminApi<'a, A>

§

impl<'a, A> RefUnwindSafe for AdminApi<'a, A>

§

impl<'a, A> Send for AdminApi<'a, A>
where &'a A: Send,

§

impl<'a, A> Sync for AdminApi<'a, A>
where &'a A: Sync,

§

impl<'a, A> Unpin for AdminApi<'a, A>
where &'a A: Unpin,

§

impl<'a, A> UnsafeUnpin for AdminApi<'a, A>

§

impl<'a, A> UnwindSafe for AdminApi<'a, A>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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