domain: add Identity & Access entities (User, Role, Permission, Group)

This commit is contained in:
2026-05-31 03:20:18 +02:00
parent aa432e6594
commit 656da7e945
11 changed files with 234 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
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))
}
}