27 lines
803 B
Rust
27 lines
803 B
Rust
use std::collections::HashSet;
|
|
use crate::value_objects::SystemId;
|
|
use super::permission::{Permission, PermissionAction, ResourceType};
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct Role {
|
|
pub role_id: SystemId,
|
|
pub name: String,
|
|
pub permissions: HashSet<Permission>,
|
|
pub is_system_default: bool,
|
|
}
|
|
|
|
impl Role {
|
|
pub fn new(name: impl Into<String>, permissions: HashSet<Permission>, is_system_default: bool) -> Self {
|
|
Self {
|
|
role_id: SystemId::new(),
|
|
name: name.into(),
|
|
permissions,
|
|
is_system_default,
|
|
}
|
|
}
|
|
|
|
pub fn has_permission(&self, action: PermissionAction, resource_type: ResourceType) -> bool {
|
|
self.permissions.contains(&Permission::new(action, resource_type))
|
|
}
|
|
}
|