Module actix_web_grants::proc_macro[][src]

Procedural macros for checking user permissions or roles.

Examples

use actix_web::{HttpResponse};
use actix_web_grants::proc_macro::{has_permissions, has_roles};

// User should be ADMIN with OP_GET_SECRET permission
#[has_permissions["ROLE_ADMIN", "OP_GET_SECRET"]]
async fn macro_secured() -> HttpResponse {
    HttpResponse::Ok().body("some secured info")
}

// Role - is permission with prefix "ROLE_".
// User should be ADMIN and MANAGER
#[has_roles["ADMIN", "MANAGER"]]
async fn role_macro_secured() -> HttpResponse {
    HttpResponse::Ok().body("some secured info")
}

Attribute Macros

has_any_permission

Macro to сheck that the user has any of the specified permissions.

has_any_role

Macro to сheck that the user has any the specified roles. Role - is permission with prefix “ROLE_”.

has_permissions

Macro to сheck that the user has all the specified permissions.

has_roles

Macro to сheck that the user has all the specified roles. Role - is permission with prefix “ROLE_”.