llldap/src/db/user.rs

58 lines
1.4 KiB
Rust
Raw Normal View History

2026-09-01 19:06:33 +02:00
use std::fmt;
use crate::db::{Operation, Role};
2026-09-01 19:06:33 +02:00
#[derive(Clone, Debug)]
pub struct UserRef {
pub username: String,
pub domain: Option<String>,
2026-09-01 19:06:33 +02:00
}
impl fmt::Display for UserRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(domain) = &self.domain {
write!(f, "{}@{}", self.username, domain)
} else {
write!(f, "{}", self.username)
}
2026-09-01 19:06:33 +02:00
}
}
#[derive(Clone, Debug)]
pub struct User {
/// Username, without the domain part. Once set, cannot be edited.
2026-09-01 19:06:33 +02:00
pub username: String,
/// Domain of the user. Once set, cannot be edited.
///
/// Service accounts may exist with an empty domain.
pub domain: Option<String>,
2026-09-01 19:06:33 +02:00
pub password: String,
/// Mail for the user. Computed from username/domain, cannot be edited.
2026-09-01 19:06:33 +02:00
pub mail: String,
pub role: Role,
2026-09-01 19:06:33 +02:00
// recovery_mail: String,
}
impl User {
pub fn user_ref(&self) -> UserRef {
UserRef {
username: self.username.clone(),
domain: self.domain.clone(),
}
}
#[expect(unused)]
pub fn can_perform(&self, operation: &Operation) -> bool {
self.role.can_perform(operation)
}
2026-09-01 19:06:33 +02:00
}
impl fmt::Display for User {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(domain) = &self.domain {
write!(f, "{}@{}", self.username, domain)
} else {
write!(f, "{}", self.username)
}
2026-09-01 19:06:33 +02:00
}
}