2026-09-01 19:06:33 +02:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2026-09-04 18:35:46 +02:00
|
|
|
use crate::db::{Operation, Role};
|
|
|
|
|
|
2026-09-01 19:06:33 +02:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct UserRef {
|
|
|
|
|
pub username: String,
|
2026-09-04 18:35:46 +02:00
|
|
|
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 {
|
2026-09-04 18:35:46 +02:00
|
|
|
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 {
|
2026-09-04 18:35:46 +02:00
|
|
|
/// Username, without the domain part. Once set, cannot be edited.
|
2026-09-01 19:06:33 +02:00
|
|
|
pub username: String,
|
2026-09-04 18:35:46 +02:00
|
|
|
/// 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,
|
2026-09-04 18:35:46 +02:00
|
|
|
/// Mail for the user. Computed from username/domain, cannot be edited.
|
2026-09-01 19:06:33 +02:00
|
|
|
pub mail: String,
|
2026-09-04 18:35:46 +02:00
|
|
|
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(),
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-04 18:35:46 +02:00
|
|
|
|
|
|
|
|
#[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 {
|
2026-09-04 18:35:46 +02:00
|
|
|
if let Some(domain) = &self.domain {
|
|
|
|
|
write!(f, "{}@{}", self.username, domain)
|
|
|
|
|
} else {
|
|
|
|
|
write!(f, "{}", self.username)
|
|
|
|
|
}
|
2026-09-01 19:06:33 +02:00
|
|
|
}
|
|
|
|
|
}
|