Don't consider a user's name taken by self (#376)

* Don't consider a user's name taken if self

* Fix incorrect types

* try-use more idiomatic Option tech

* true if `None`

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
John Paul 2022-06-26 00:50:41 -04:00 committed by GitHub
parent 16e7194dfe
commit e74b4b35b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,13 +182,17 @@ pub async fn user_edit(
let mut transaction = pool.begin().await?; let mut transaction = pool.begin().await?;
if let Some(username) = &new_user.username { if let Some(username) = &new_user.username {
let user_option = let existing_user_id_option =
crate::database::models::User::get_id_from_username_or_id( crate::database::models::User::get_id_from_username_or_id(
username, &**pool, username, &**pool,
) )
.await?; .await?;
if user_option.is_none() { if existing_user_id_option
.map(UserId::from)
.map(|id| id == user.id)
.unwrap_or(true)
{
sqlx::query!( sqlx::query!(
" "
UPDATE users UPDATE users