fedimovies/src/admin/roles.rs

16 lines
468 B
Rust
Raw Normal View History

2023-04-25 13:49:35 +00:00
use fedimovies_models::users::types::Role;
2023-04-10 21:20:47 +00:00
use crate::errors::ValidationError;
pub const ALLOWED_ROLES: [&str; 3] = ["admin", "user", "read_only_user"];
pub fn role_from_str(role_str: &str) -> Result<Role, ValidationError> {
let role = match role_str {
"user" => Role::NormalUser,
"admin" => Role::Admin,
"read_only_user" => Role::ReadOnlyUser,
2023-04-26 10:55:42 +00:00
_ => return Err(ValidationError("unknown role".to_string())),
2023-04-10 21:20:47 +00:00
};
Ok(role)
}