From e17fc9fff0fff0dc9eded1492fa061ae33073158 Mon Sep 17 00:00:00 2001 From: JustTemmie <47639983+JustTemmie@users.noreply.github.com> Date: Sun, 13 Jul 2025 16:11:47 +0200 Subject: [PATCH 1/4] fix: add a friend via uesrname instead of their UUID --- src/api/v1/me/friends/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/api/v1/me/friends/mod.rs b/src/api/v1/me/friends/mod.rs index f946616..217e32b 100644 --- a/src/api/v1/me/friends/mod.rs +++ b/src/api/v1/me/friends/mod.rs @@ -1,15 +1,10 @@ -use ::uuid::Uuid; use actix_web::{HttpRequest, HttpResponse, get, post, web}; use serde::Deserialize; pub mod uuid; use crate::{ - Data, - api::v1::auth::check_access_token, - error::Error, - objects::Me, - utils::{get_auth_header, global_checks}, + api::v1::auth::check_access_token, error::Error, objects::Me, utils::{get_auth_header, global_checks, user_uuid_from_identifier}, Data }; /// Returns a list of users that are your friends @@ -34,7 +29,7 @@ pub async fn get(req: HttpRequest, data: web::Data) -> Result Date: Sun, 13 Jul 2025 16:17:54 +0200 Subject: [PATCH 2/4] fix: linter :( why you one line the import D: --- src/api/v1/me/friends/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/v1/me/friends/mod.rs b/src/api/v1/me/friends/mod.rs index 217e32b..5980adc 100644 --- a/src/api/v1/me/friends/mod.rs +++ b/src/api/v1/me/friends/mod.rs @@ -4,7 +4,11 @@ use serde::Deserialize; pub mod uuid; use crate::{ - api::v1::auth::check_access_token, error::Error, objects::Me, utils::{get_auth_header, global_checks, user_uuid_from_identifier}, Data + Data, + api::v1::auth::check_access_token, + error::Error, + objects::Me, + utils::{get_auth_header, global_checks, user_uuid_from_identifier}, }; /// Returns a list of users that are your friends -- 2.47.3 From d775723b7b11afc7e6cb8497fac404497c0f926e Mon Sep 17 00:00:00 2001 From: JustTemmie <47639983+JustTemmie@users.noreply.github.com> Date: Sun, 13 Jul 2025 16:20:03 +0200 Subject: [PATCH 3/4] fix: require username, instead of username OR email --- src/api/v1/me/friends/mod.rs | 4 ++-- src/utils.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api/v1/me/friends/mod.rs b/src/api/v1/me/friends/mod.rs index 5980adc..8de0a5d 100644 --- a/src/api/v1/me/friends/mod.rs +++ b/src/api/v1/me/friends/mod.rs @@ -8,7 +8,7 @@ use crate::{ api::v1::auth::check_access_token, error::Error, objects::Me, - utils::{get_auth_header, global_checks, user_uuid_from_identifier}, + utils::{get_auth_header, global_checks, user_uuid_from_username} }; /// Returns a list of users that are your friends @@ -73,7 +73,7 @@ pub async fn post( let me = Me::get(&mut conn, uuid).await?; - let target_uuid = user_uuid_from_identifier(&mut conn, &json.username).await?; + let target_uuid = user_uuid_from_username(&mut conn, &json.username).await?; me.add_friend(&mut conn, target_uuid).await?; Ok(HttpResponse::Ok().finish()) diff --git a/src/utils.rs b/src/utils.rs index 7a5581a..01a7f0d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -168,6 +168,26 @@ pub async fn user_uuid_from_identifier( } } +pub async fn user_uuid_from_username( + conn: &mut Conn, + identifier: &String, +) -> Result { + if USERNAME_REGEX.is_match(identifier) { + use users::dsl; + let user_uuid = dsl::users + .filter(dsl::username.eq(identifier)) + .select(dsl::uuid) + .get_result(conn) + .await?; + + Ok(user_uuid) + } else { + Err(Error::BadRequest( + "Please provide a valid username".to_string(), + )) + } +} + pub async fn global_checks(data: &Data, user_uuid: Uuid) -> Result<(), Error> { if data.config.instance.require_email_verification { let mut conn = data.pool.get().await?; -- 2.47.3 From 384f5e404fac5a44cf51b573e2a4a7772a590bdd Mon Sep 17 00:00:00 2001 From: JustTemmie <47639983+JustTemmie@users.noreply.github.com> Date: Sun, 13 Jul 2025 16:21:07 +0200 Subject: [PATCH 4/4] fix: change function paramater name to match function name --- src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 01a7f0d..072143f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -170,12 +170,12 @@ pub async fn user_uuid_from_identifier( pub async fn user_uuid_from_username( conn: &mut Conn, - identifier: &String, + username: &String, ) -> Result { - if USERNAME_REGEX.is_match(identifier) { + if USERNAME_REGEX.is_match(username) { use users::dsl; let user_uuid = dsl::users - .filter(dsl::username.eq(identifier)) + .filter(dsl::username.eq(username)) .select(dsl::uuid) .get_result(conn) .await?; -- 2.47.3