[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
use labrinth::queue::email::EmailQueue;
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
use labrinth::util::anrok;
|
2025-05-09 07:27:55 -05:00
|
|
|
use labrinth::{LabrinthConfig, file_hosting, queue};
|
2023-10-06 09:57:33 -07:00
|
|
|
use labrinth::{check_env_vars, clickhouse};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2023-11-25 13:42:39 -08:00
|
|
|
pub mod api_common;
|
2023-10-12 17:52:24 -05:00
|
|
|
pub mod api_v2;
|
2023-10-30 11:14:38 -05:00
|
|
|
pub mod api_v3;
|
2023-10-12 17:52:24 -05:00
|
|
|
pub mod asserts;
|
2023-10-06 09:57:33 -07:00
|
|
|
pub mod database;
|
|
|
|
|
pub mod dummy_data;
|
|
|
|
|
pub mod environment;
|
|
|
|
|
pub mod pats;
|
2023-10-17 00:53:10 -07:00
|
|
|
pub mod permissions;
|
2023-10-06 09:57:33 -07:00
|
|
|
pub mod scopes;
|
2023-12-03 06:27:12 -08:00
|
|
|
pub mod search;
|
2023-10-06 09:57:33 -07:00
|
|
|
|
|
|
|
|
// Testing equivalent to 'setup' function, producing a LabrinthConfig
|
2023-10-17 00:53:10 -07:00
|
|
|
// If making a test, you should probably use environment::TestEnvironment::build() (which calls this)
|
2023-11-11 16:40:10 -08:00
|
|
|
pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig {
|
2023-10-06 09:57:33 -07:00
|
|
|
println!("Setting up labrinth config");
|
|
|
|
|
|
|
|
|
|
dotenvy::dotenv().ok();
|
|
|
|
|
|
|
|
|
|
if check_env_vars() {
|
|
|
|
|
println!("Some environment variables are missing!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let pool = db.pool.clone();
|
2025-09-14 11:44:52 -04:00
|
|
|
let ro_pool = db.ro_pool.clone();
|
2023-10-06 09:57:33 -07:00
|
|
|
let redis_pool = db.redis_pool.clone();
|
2024-01-05 08:20:56 -08:00
|
|
|
let search_config = db.search_config.clone();
|
2023-10-06 09:57:33 -07:00
|
|
|
let file_host: Arc<dyn file_hosting::FileHost + Send + Sync> =
|
|
|
|
|
Arc::new(file_hosting::MockHost::new());
|
|
|
|
|
let mut clickhouse = clickhouse::init_client().await.unwrap();
|
|
|
|
|
|
2024-10-18 16:07:35 -07:00
|
|
|
let maxmind_reader =
|
|
|
|
|
Arc::new(queue::maxmind::MaxMindIndexer::new().await.unwrap());
|
2023-10-06 09:57:33 -07:00
|
|
|
|
2025-03-15 09:28:20 -05:00
|
|
|
let stripe_client =
|
|
|
|
|
stripe::Client::new(dotenvy::var("STRIPE_API_KEY").unwrap());
|
|
|
|
|
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
let anrok_client = anrok::Client::from_env().unwrap();
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
let email_queue =
|
|
|
|
|
EmailQueue::init(pool.clone(), redis_pool.clone()).unwrap();
|
|
|
|
|
|
2023-10-06 09:57:33 -07:00
|
|
|
labrinth::app_setup(
|
|
|
|
|
pool.clone(),
|
2025-09-14 11:44:52 -04:00
|
|
|
ro_pool.clone(),
|
2023-10-06 09:57:33 -07:00
|
|
|
redis_pool.clone(),
|
2024-01-05 08:20:56 -08:00
|
|
|
search_config,
|
2023-10-06 09:57:33 -07:00
|
|
|
&mut clickhouse,
|
|
|
|
|
file_host.clone(),
|
2023-11-11 16:40:10 -08:00
|
|
|
maxmind_reader,
|
2025-03-15 09:28:20 -05:00
|
|
|
stripe_client,
|
Charge tax on products (#4361)
* Initial Anrok integration
* Query cache, fmt, clippy
* Fmt
* Use payment intent function in edit_subscription
* Attach Anrok client, use payments in index_billing
* Integrate Anrok with refunds
* Bug fixes
* More bugfixes
* Fix resubscriptions
* Medal promotion bugfixes
* Use stripe metadata constants everywhere
* Pre-fill values in products_tax_identifiers
* Cleanup billing route module
* Cleanup
* Email notification for tax charge
* Don't charge tax on users which haven't been notified of tax change
* Fix taxnotification.amount templates
* Update .env.docker-compose
* Update .env.local
* Clippy
* Fmt
* Query cache
* Periodically update tax amount on upcoming charges
* Fix queries
* Skip indexing tax amount on charges if no charges to process
* chore: query cache, clippy, fmt
* Fix a lot of things
* Remove test code
* chore: query cache, clippy, fmt
* Fix money formatting
* Fix conflicts
* Extra documentation, handle tax association properly
* Track loss in tax drift
* chore: query cache, clippy, fmt
* Add subscription.id variable
* chore: query cache, clippy, fmt
* chore: query cache, clippy, fmt
2025-09-25 12:29:29 +01:00
|
|
|
anrok_client,
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
email_queue,
|
2025-03-15 09:28:20 -05:00
|
|
|
false,
|
2023-10-06 09:57:33 -07:00
|
|
|
)
|
|
|
|
|
}
|
2023-10-30 11:14:38 -05:00
|
|
|
|
|
|
|
|
pub fn get_json_val_str(val: impl serde::Serialize) -> String {
|
|
|
|
|
serde_json::to_value(val)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.as_str()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string()
|
|
|
|
|
}
|