roles are now better

This commit is contained in:
filipriec
2025-08-30 13:19:45 +02:00
parent 60eb1c9f51
commit d6fd672409
5 changed files with 57 additions and 24 deletions

View File

@@ -2,12 +2,44 @@
use canvas::{DataProvider, AppMode};
/// Strongly typed user roles
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UserRole {
Admin,
Moderator,
Accountant,
Viewer,
Unknown(String), // fallback for unexpected roles
}
impl UserRole {
pub fn from_str(s: &str) -> Self {
match s.trim().to_lowercase().as_str() {
"admin" => UserRole::Admin,
"moderator" => UserRole::Moderator,
"accountant" => UserRole::Accountant,
"viewer" => UserRole::Viewer,
other => UserRole::Unknown(other.to_string()),
}
}
pub fn as_str(&self) -> &str {
match self {
UserRole::Admin => "admin",
UserRole::Moderator => "moderator",
UserRole::Accountant => "accountant",
UserRole::Viewer => "viewer",
UserRole::Unknown(s) => s.as_str(),
}
}
}
/// Represents the authenticated session state
#[derive(Default)]
pub struct AuthState {
pub auth_token: Option<String>,
pub user_id: Option<String>,
pub role: Option<String>,
pub role: Option<UserRole>,
pub decoded_username: Option<String>,
}