Skip to content

Commit

Permalink
chore(notifications): add global config to toggle email
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Feb 21, 2024
1 parent e4d5b84 commit adf96e8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/notifications/src/email_executor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use super::smtp::SmtpConfig;

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct EmailExecutorConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default)]
pub smtp: SmtpConfig,
}
8 changes: 6 additions & 2 deletions core/notifications/src/email_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use smtp::SmtpClient;

#[derive(Clone)]
pub struct EmailExecutor {
_config: EmailExecutorConfig,
config: EmailExecutorConfig,
smtp: SmtpClient,
settings: UserNotificationSettingsRepo,
}
Expand All @@ -25,14 +25,18 @@ impl EmailExecutor {
let smtp = SmtpClient::init(config.smtp.clone())?;

Ok(EmailExecutor {
_config: config,
config,
smtp,
settings,
})
}

#[instrument(name = "email_executor.notify", skip(self))]
pub async fn notify<T: NotificationEvent>(&self, event: &T) -> Result<(), EmailExecutorError> {
if !self.config.enabled {
return Ok(());
}

if let Some((settings, addr)) = self
.settings
.find_for_user_id(event.user_id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ impl NotificationEvent for IdentityVerificationApproved {
}

fn should_send_email(&self) -> bool {
false
true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl NotificationEvent for IdentityVerificationDeclined {
}

fn should_send_email(&self) -> bool {
false
true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ impl NotificationEvent for IdentityVerificationReviewPending {
}

fn should_send_email(&self) -> bool {
false
true
}
}

0 comments on commit adf96e8

Please sign in to comment.