Fix two database errors (#3483)

* Fixes error when an admin tries transferring project ownership
* Fixes error when trying to delete a user when they previously have a transaction

Co-authored-by: Jai Agrawal <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Emma Alexia 2025-04-13 01:21:02 -04:00 committed by GitHub
parent edd09b0b16
commit f2ec89e62b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 13 deletions

View File

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE charges\n SET user_id = $1\n WHERE user_id = $2\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Int8"
]
},
"nullable": []
},
"hash": "f1f93419f4394c702f256fe3e5de0368ee972ed20bd4d4b2490c655fde999dda"
}

View File

@ -657,6 +657,18 @@ impl User {
.execute(&mut **transaction)
.await?;
sqlx::query!(
"
UPDATE charges
SET user_id = $1
WHERE user_id = $2
",
deleted_user as UserId,
id as UserId,
)
.execute(&mut **transaction)
.await?;
sqlx::query!(
"
DELETE FROM user_backup_codes

View File

@ -936,9 +936,15 @@ pub async fn transfer_ownership(
let mut transaction = pool.begin().await?;
// The following are the only places new_is_owner is modified.
if let Some(former_owner) =
TeamMember::get_from_team_full(id.into(), &**pool, &redis)
.await?
.into_iter()
.find(|x| x.is_owner)
{
TeamMember::edit_team_member(
id.into(),
current_user.id.into(),
former_owner.user_id,
None,
None,
None,
@ -949,6 +955,7 @@ pub async fn transfer_ownership(
&mut transaction,
)
.await?;
}
TeamMember::edit_team_member(
id.into(),