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, pub is_system_default: bool, } impl Role { pub fn new(name: impl Into, permissions: HashSet, 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)) } }