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>
impl<A: AuthInstance> AdminApi<'_, A>
Sourcepub async fn create_user(
&self,
input: CreateUserInput,
) -> Result<UserView, AuthError>
pub async fn create_user( &self, input: CreateUserInput, ) -> Result<UserView, AuthError>
Creates a user with a role, a password and any user columns.
Sourcepub async fn list_users(
&self,
query: ListUsersQuery,
) -> Result<UserList, AuthError>
pub async fn list_users( &self, query: ListUsersQuery, ) -> Result<UserList, AuthError>
Lists users with search, filter, sort and pagination.
Sourcepub async fn set_role(
&self,
user_id: &Id,
role: impl Into<Roles>,
) -> Result<UserView, AuthError>
pub async fn set_role( &self, user_id: &Id, role: impl Into<Roles>, ) -> Result<UserView, AuthError>
Replaces a user’s roles.
Sourcepub async fn ban(&self, input: BanUserInput) -> Result<UserView, AuthError>
pub async fn ban(&self, input: BanUserInput) -> Result<UserView, AuthError>
Bans a user and revokes every session they have.
Sourcepub async fn update_user(
&self,
user_id: &Id,
data: Map<String, Json>,
) -> Result<UserView, AuthError>
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.
Sourcepub async fn set_user_password(
&self,
user_id: &Id,
new_password: &str,
) -> Result<(), AuthError>
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.
Sourcepub async fn remove_user(&self, user_id: &Id) -> Result<(), AuthError>
pub async fn remove_user(&self, user_id: &Id) -> Result<(), AuthError>
Deletes a user with their sessions and accounts.
Sourcepub async fn list_user_sessions(
&self,
user_id: &Id,
) -> Result<Vec<Map<String, Json>>, AuthError>
pub async fn list_user_sessions( &self, user_id: &Id, ) -> Result<Vec<Map<String, Json>>, AuthError>
A user’s unexpired sessions, as client JSON.
Sourcepub async fn revoke_user_session(
&self,
session_token: &str,
) -> Result<(), AuthError>
pub async fn revoke_user_session( &self, session_token: &str, ) -> Result<(), AuthError>
Revokes the session with this raw token.
Sourcepub async fn revoke_user_sessions(&self, user_id: &Id) -> Result<(), AuthError>
pub async fn revoke_user_sessions(&self, user_id: &Id) -> Result<(), AuthError>
Revokes every session of a user.
Sourcepub async fn has_permission(
&self,
user_id: &Id,
permissions: Permissions,
) -> Result<bool, AuthError>
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.
Sourcepub async fn impersonate(
&self,
headers: &HeaderMap,
user_id: &Id,
) -> Result<ApiResponse<SessionOutput>, AuthError>
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.
Sourcepub async fn stop_impersonating(
&self,
headers: &HeaderMap,
) -> Result<ApiResponse<SessionOutput>, AuthError>
pub async fn stop_impersonating( &self, headers: &HeaderMap, ) -> Result<ApiResponse<SessionOutput>, AuthError>
POST /admin/stop-impersonating for the impersonation session in headers.