From e4e5a400ba2014adfb8bf4bc48f6d98d57edd09e Mon Sep 17 00:00:00 2001 From: Timshel Date: Mon, 1 Sep 2025 18:20:17 +0200 Subject: [PATCH 1/4] Admin delete SSO association prompt --- src/static/scripts/admin_users.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/static/scripts/admin_users.js b/src/static/scripts/admin_users.js index 71015d1d..be30e105 100644 --- a/src/static/scripts/admin_users.js +++ b/src/static/scripts/admin_users.js @@ -33,11 +33,11 @@ function deleteSSOUser(event) { alert("Required parameters not found!"); return false; } - const input_email = prompt(`To delete user "${email}", please type the email below`); + const input_email = prompt(`To delete user "${email}" SSO association, please type the email below`); if (input_email != null) { if (input_email == email) { _delete(`${BASE_URL}/admin/users/${id}/sso`, - "User SSO Associtation deleted correctly", + "User SSO association deleted correctly", "Error deleting user SSO association" ); } else { From 5cb8fee0add8ee78440d13f9a3d28bfcdd89d6c5 Mon Sep 17 00:00:00 2001 From: Timshel Date: Mon, 1 Sep 2025 19:01:53 +0200 Subject: [PATCH 2/4] User.save don't use replace_into --- src/db/models/user.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 3a3b5157..076eb77d 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -284,21 +284,22 @@ impl User { db_run! {conn: sqlite, mysql { - match diesel::replace_into(users::table) - .values(UserDb::to_db(self)) + let value = UserDb::to_db(self); + // Don't use replace_into() since it wants to delete the record first. + match diesel::update(users::table) + .filter(users::uuid.eq(&self.uuid)) + .set(&value) .execute(conn) { - Ok(_) => Ok(()), - // Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first. - Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => { - diesel::update(users::table) - .filter(users::uuid.eq(&self.uuid)) - .set(UserDb::to_db(self)) + Ok(1) => Ok(()), + Ok(_) => { + diesel::insert_into(users::table) + .values(value) .execute(conn) .map_res("Error saving user") } Err(e) => Err(e.into()), - }.map_res("Error saving user") + }.map_res("Error updating user") } postgresql { let value = UserDb::to_db(self); From 113a5cae9f45a2aa48af284838d54603f3cb58d3 Mon Sep 17 00:00:00 2001 From: Timshel Date: Tue, 16 Sep 2025 17:13:33 +0200 Subject: [PATCH 3/4] User.save use upsert with sqlite --- src/db/models/user.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 076eb77d..054896eb 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -283,7 +283,7 @@ impl User { self.updated_at = Utc::now().naive_utc(); db_run! {conn: - sqlite, mysql { + mysql { let value = UserDb::to_db(self); // Don't use replace_into() since it wants to delete the record first. match diesel::update(users::table) @@ -301,7 +301,7 @@ impl User { Err(e) => Err(e.into()), }.map_res("Error updating user") } - postgresql { + postgresql, sqlite { let value = UserDb::to_db(self); diesel::insert_into(users::table) // Insert or update .values(&value) From ba6176d36d40aa4174da6d39f6aea9aa9fd78909 Mon Sep 17 00:00:00 2001 From: Timshel Date: Tue, 16 Sep 2025 19:31:00 +0200 Subject: [PATCH 4/4] User.save use upsert with mysql --- src/db/models/user.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 054896eb..d1bec8cb 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -285,21 +285,13 @@ impl User { db_run! {conn: mysql { let value = UserDb::to_db(self); - // Don't use replace_into() since it wants to delete the record first. - match diesel::update(users::table) - .filter(users::uuid.eq(&self.uuid)) + diesel::insert_into(users::table) + .values(&value) + .on_conflict(diesel::dsl::DuplicatedKeys) + .do_update() .set(&value) .execute(conn) - { - Ok(1) => Ok(()), - Ok(_) => { - diesel::insert_into(users::table) - .values(value) - .execute(conn) - .map_res("Error saving user") - } - Err(e) => Err(e.into()), - }.map_res("Error updating user") + .map_res("Error saving user") } postgresql, sqlite { let value = UserDb::to_db(self);