Correctly delete mails with aliases
This commit is contained in:
parent
237ef6250d
commit
e8e9e9df8c
1 changed files with 10 additions and 1 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -638,20 +638,29 @@ async fn delete_mail(
|
|||
User(user): User,
|
||||
Form(delete): Form<Mail>,
|
||||
) -> Result<Redirect, Error> {
|
||||
let mut tx = state.db.begin().await?;
|
||||
|
||||
sqlx::query!("DELETE FROM alias WHERE dest = $1", delete.mail)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
let rows_affected = sqlx::query!(
|
||||
"DELETE FROM emails WHERE id = $1 AND mail = $2",
|
||||
user,
|
||||
delete.mail
|
||||
)
|
||||
.execute(&state.db)
|
||||
.execute(&mut *tx)
|
||||
.await?
|
||||
.rows_affected();
|
||||
|
||||
if rows_affected != 1 {
|
||||
tx.rollback().await?;
|
||||
tracing::warn!("Invalid number of rows affected in delete: {rows_affected}");
|
||||
return Err(Error::InternalError);
|
||||
}
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
Ok(Redirect::to("/"))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue