Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ tower-http = "0.6.8"
tower = "0.5.3"
tower-sessions = { version = "0.15", features = ["memory-store"] }
time = { version = "0.3.47", features = ["serde"] }

lettre = { version = "0.11.19", default-features = false, features = [
"builder",
"smtp-transport",
"tokio1",
"tokio1-rustls",
"ring",
"rustls-platform-verifier"
] }
#====
sea-orm = "1.1.19"
sea-orm-migration = "1.1.19"
Expand Down
1 change: 1 addition & 0 deletions ceres/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod group;
pub mod issue;
pub mod label;
pub mod merge_queue;
pub mod notification;
pub mod tag;
pub mod third_party;
pub mod user;
32 changes: 32 additions & 0 deletions ceres/src/model/notification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct NotificationEventTypeInfo {
pub code: String,
pub category: String,
pub description: String,
pub system_required: bool,
pub default_enabled: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UserNotificationPreferenceItem {
pub event_type_code: String,
pub enabled: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UserNotificationConfig {
pub enabled: bool,
pub delivery_mode: String,
pub email: String,
pub preferences: Vec<UserNotificationPreferenceItem>,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UpdateUserNotificationConfig {
pub enabled: Option<bool>,
pub delivery_mode: Option<String>,
pub preferences: Option<Vec<UserNotificationPreferenceItem>>,
}
4 changes: 3 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pgp = { workspace = true }
cedar-policy = { workspace = true }
redis = { workspace = true }
rkyv = { workspace = true}
toml = { workspace = true }
toml = { workspace = true }
async-trait = { workspace = true }
lettre = { workspace = true }
51 changes: 51 additions & 0 deletions common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ pub struct Config {
pub orion_server: Option<OrionServerConfig>,
#[serde(default)]
pub sidebar: SidebarConfig,
#[serde(default)]
pub mail: Option<MailConfig>,
}

impl Config {
Expand Down Expand Up @@ -137,6 +139,7 @@ impl Config {
object_storage: ObjectStorageConfig::default(),
orion_server: None,
sidebar: SidebarConfig::default(),
mail: None,
}
}

Expand Down Expand Up @@ -266,6 +269,29 @@ impl Default for LogConfig {
}
}

#[derive(Deserialize, Debug, Clone)]
pub struct MailConfig {
#[serde(default)]
pub enabled: bool,
pub smtp_host: String,
#[serde(default = "default_smtp_port")]
pub smtp_port: u16,
#[serde(default)]
pub username: Option<String>,
#[serde(default)]
pub password: Option<String>,
pub from: String,
#[serde(default = "default_starttls")]
pub starttls: bool,
}

fn default_smtp_port() -> u16 {
587
}
fn default_starttls() -> bool {
true
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DbConfig {
pub db_type: String,
Expand Down Expand Up @@ -1069,4 +1095,29 @@ mod test {
};
assert!(config.validate().is_ok());
}

#[test]
fn test_mail_config_deserialize() {
use serde::Deserialize;
#[derive(Deserialize)]
struct Wrapper {
mail: MailConfig,
}

let toml = r#"
[mail]
enabled = true
smtp_host = "smtp.example.com"
smtp_port = 587
from = "[email protected]"
starttls = true
"#;

let parsed: Wrapper = toml::from_str(toml).expect("MailConfig should deserialize");
assert!(parsed.mail.enabled);
assert_eq!(parsed.mail.smtp_host, "smtp.example.com");
assert_eq!(parsed.mail.smtp_port, 587);
assert_eq!(parsed.mail.from, "[email protected]");
assert!(parsed.mail.starttls);
}
}
Loading
Loading