Skip to main content

authorize

Function authorize 

Source
pub async fn authorize(
    conn: &mut PgConnection,
    action: Action,
    user_id: Option<Uuid>,
    resource: Resource,
) -> AuthorizationResult<AuthorizationToken>
Expand description

Checks whether the user may perform action on resource, fetching their roles.

The returned token is the only way to build a controller response, so only call this from a controller function:

let token = authorize(&mut conn, Action::Edit, Some(user.id), Resource::Page(*page_id)).await?;
token.authorized_ok(web::Json(cms_page_info))