use std::fmt; use crate::db::{Operation, Role}; #[derive(Clone, Debug)] pub struct UserRef { pub username: String, pub domain: Option, } 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) } } } #[derive(Clone, Debug)] pub struct User { /// Username, without the domain part. Once set, cannot be edited. pub username: String, /// Domain of the user. Once set, cannot be edited. /// /// Service accounts may exist with an empty domain. pub domain: Option, pub password: String, /// Mail for the user. Computed from username/domain, cannot be edited. pub mail: String, pub role: Role, // 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) } } 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) } } }