pub type UserId = String;
pub type SessionId = String;
#[derive(Debug, Clone, PartialEq)]
pub enum Permission {
Read,
Write,
Execute,
Admin,
}
#[derive(Debug, Clone)]
pub struct PermissionCheck {
pub user_id: UserId,
pub resource: String,
pub permission: Permission,
pub granted: bool,
}
impl PermissionCheck {
pub fn new(user_id: UserId, resource: &str, permission: Permission) -> Self {
Self {
user_id,
resource: resource.to_string(),
permission,
granted: false,
}
}
pub fn grant(mut self) -> Self {
self.granted = true;
self
}
pub fn is_allowed(&self) -> bool {
self.granted
}
}