domain: add Identity & Access entities (User, Role, Permission, Group)
This commit is contained in:
26
crates/domain/src/entities/role.rs
Normal file
26
crates/domain/src/entities/role.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user