diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 3a3b5157..d1bec8cb 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -283,24 +283,17 @@ impl User { self.updated_at = Utc::now().naive_utc(); db_run! {conn: - sqlite, mysql { - match diesel::replace_into(users::table) - .values(UserDb::to_db(self)) + mysql { + let value = UserDb::to_db(self); + diesel::insert_into(users::table) + .values(&value) + .on_conflict(diesel::dsl::DuplicatedKeys) + .do_update() + .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)) - .execute(conn) - .map_res("Error saving user") - } - Err(e) => Err(e.into()), - }.map_res("Error saving user") + .map_res("Error saving user") } - postgresql { + postgresql, sqlite { let value = UserDb::to_db(self); diesel::insert_into(users::table) // Insert or update .values(&value) 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 {