Unsubscribe link in emails sent
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::{
|
||||
idempotency::{IdempotencyKey, save_response, try_processing},
|
||||
routes::{AdminError, AppError},
|
||||
startup::AppState,
|
||||
templates::MessageTemplate,
|
||||
templates::{EmailTemplate, MessageTemplate, StandaloneEmailTemplate},
|
||||
};
|
||||
use anyhow::Context;
|
||||
use askama::Template;
|
||||
@@ -27,8 +27,7 @@ pub struct BodyData {
|
||||
pub async fn insert_newsletter_issue(
|
||||
transaction: &mut Transaction<'static, Postgres>,
|
||||
title: &str,
|
||||
text_content: &str,
|
||||
html_content: &str,
|
||||
email_template: &dyn EmailTemplate,
|
||||
) -> Result<Uuid, sqlx::Error> {
|
||||
let newsletter_issue_id = Uuid::new_v4();
|
||||
let query = sqlx::query!(
|
||||
@@ -40,8 +39,8 @@ pub async fn insert_newsletter_issue(
|
||||
"#,
|
||||
newsletter_issue_id,
|
||||
title,
|
||||
text_content,
|
||||
html_content
|
||||
email_template.text(),
|
||||
email_template.html(),
|
||||
);
|
||||
transaction.execute(query).await?;
|
||||
Ok(newsletter_issue_id)
|
||||
@@ -56,9 +55,10 @@ pub async fn enqueue_delivery_tasks(
|
||||
r#"
|
||||
INSERT INTO issue_delivery_queue (
|
||||
newsletter_issue_id,
|
||||
subscriber_email
|
||||
subscriber_email,
|
||||
unsubscribe_token
|
||||
)
|
||||
SELECT $1, email
|
||||
SELECT $1, email, unsubscribe_token
|
||||
FROM subscriptions
|
||||
WHERE status = 'confirmed'
|
||||
"#,
|
||||
@@ -71,7 +71,9 @@ pub async fn enqueue_delivery_tasks(
|
||||
#[tracing::instrument(name = "Publishing a newsletter", skip(connection_pool, form))]
|
||||
pub async fn publish_newsletter(
|
||||
State(AppState {
|
||||
connection_pool, ..
|
||||
connection_pool,
|
||||
base_url,
|
||||
..
|
||||
}): State<AppState>,
|
||||
Extension(AuthenticatedUser { user_id, .. }): Extension<AuthenticatedUser>,
|
||||
Form(form): Form<BodyData>,
|
||||
@@ -90,7 +92,13 @@ pub async fn publish_newsletter(
|
||||
}
|
||||
};
|
||||
|
||||
let issue_id = insert_newsletter_issue(&mut transaction, &form.title, &form.text, &form.html)
|
||||
let email_template = StandaloneEmailTemplate {
|
||||
base_url: &base_url,
|
||||
text_content: &form.text,
|
||||
html_content: &form.html,
|
||||
};
|
||||
|
||||
let issue_id = insert_newsletter_issue(&mut transaction, &form.title, &email_template)
|
||||
.await
|
||||
.context("Failed to store newsletter issue details.")?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user