fix: Forbid removing emails if they're required to register

This commit is contained in:
Ginger
2026-04-23 13:17:48 -04:00
parent 8171e3d614
commit 567d809efe
5 changed files with 30 additions and 4 deletions
+11 -3
View File
@@ -27,13 +27,21 @@ pub struct Service {
pub enum EmailRequirement {
/// Users may change their email, but cannot remove it entirely.
Always,
Required,
/// Users may change or remove their email.
Optional,
/// SMTP is not configured.
/// Users may not change their email at all.
Unavailable,
}
impl EmailRequirement {
#[must_use]
pub fn may_change(&self) -> bool { matches!(self, Self::Required | Self::Optional) }
#[must_use]
pub fn may_remove(&self) -> bool { matches!(self, Self::Optional) }
}
struct Data {
localpart_email: Arc<Map>,
email_localpart: Arc<Map>,
@@ -77,7 +85,7 @@ impl Service {
pub fn email_requirement(&self) -> EmailRequirement {
if let Some(smtp) = &self.services.config.smtp {
if smtp.require_email_for_registration || smtp.require_email_for_token_registration {
EmailRequirement::Always
EmailRequirement::Required
} else {
EmailRequirement::Optional
}