diff --git a/src/api_v1/note.rs b/src/api_v1/note.rs index cf32842..ce80eb3 100644 --- a/src/api_v1/note.rs +++ b/src/api_v1/note.rs @@ -11,6 +11,7 @@ use crate::service::MagnetarService; use crate::web::auth::MaybeUser; use crate::web::{ApiError, ObjectNotFound}; +#[tracing::instrument(err, skip_all)] pub async fn handle_note( Path(id): Path, Query(NoteByIdReq { diff --git a/src/api_v1/user.rs b/src/api_v1/user.rs index e48f89b..84b12d2 100644 --- a/src/api_v1/user.rs +++ b/src/api_v1/user.rs @@ -20,6 +20,7 @@ use std::collections::HashMap; use std::sync::Arc; use strum::IntoEnumIterator; +#[tracing::instrument(err, skip_all)] pub async fn handle_user_info_self( Query(req): Query>, State(service): State>, @@ -41,6 +42,7 @@ pub async fn handle_user_info_self( Ok(Json(user)) } +#[tracing::instrument(err, skip_all)] pub async fn handle_user_info( Path(id): Path, Query(req): Query>, @@ -69,6 +71,7 @@ pub async fn handle_user_info( Ok(Json(user)) } +#[tracing::instrument(err, skip_all)] pub async fn handle_user_info_by_acct( Path(tag_str): Path, Query(req): Query>, @@ -102,6 +105,7 @@ pub async fn handle_user_info_by_acct( Ok(Json(user)) } +#[tracing::instrument(err, skip_all)] pub async fn handle_user_by_id_many( Query(ManyUsersByIdReq { id }): Query>, State(service): State>, @@ -145,6 +149,7 @@ pub async fn handle_user_by_id_many( Ok(Json(users_ordered)) } +#[tracing::instrument(err, skip_all)] pub async fn handle_notifications( Query(NotificationsReq { ref exclude_types, @@ -179,6 +184,7 @@ pub async fn handle_notifications( Ok((pagination, Json(notifications))) } +#[tracing::instrument(err, skip_all)] pub async fn handle_following_self( Query(_): Query>, State(service): State>, @@ -194,6 +200,7 @@ pub async fn handle_following_self( Ok((pagination, Json(users))) } +#[tracing::instrument(err, skip_all)] pub async fn handle_followers_self( Query(_): Query>, State(service): State>, @@ -209,6 +216,7 @@ pub async fn handle_followers_self( Ok((pagination, Json(users))) } +#[tracing::instrument(err, skip_all)] pub async fn handle_following( Query(_): Query>, Path(id): Path, @@ -223,6 +231,7 @@ pub async fn handle_following( Ok((pagination, Json(users))) } +#[tracing::instrument(err, skip_all)] pub async fn handle_followers( Query(_): Query>, Path(id): Path, @@ -237,6 +246,7 @@ pub async fn handle_followers( Ok((pagination, Json(users))) } +#[tracing::instrument(err, skip_all)] pub async fn handle_follow_requests_self( Query(_): Query>, State(service): State>, diff --git a/src/model/processing/user.rs b/src/model/processing/user.rs index 1c8c4b2..a3b2fba 100644 --- a/src/model/processing/user.rs +++ b/src/model/processing/user.rs @@ -26,7 +26,7 @@ use magnetar_sdk::types::{Id, MmXml}; use magnetar_sdk::{mmm, Optional, Packed, Required}; use serde::{Deserialize, Serialize}; use tokio::{join, try_join}; -use tracing::warn; +use tracing::{instrument, warn}; use url::Url; pub trait UserShapedData<'a>: Send + Sync { @@ -566,24 +566,26 @@ impl UserModel { ctx: &PackingContext, id: &str, ) -> Result<(), ApiError> { - if !ctx.is_id_self(id) { - let profile = self.get_profile_by_id(ctx, id).await?; + if ctx.is_id_self(id) { + return Ok(()); + } - match (&ctx.self_user, &profile.ff_visibility) { - (_, UserProfileFfvisibilityEnum::Public) => {} - (Some(self_user), UserProfileFfvisibilityEnum::Followers) - if ctx - .is_relationship_between( - Either::Right(self_user), - Either::Left(id), - UserRelationship::Follow, - ) - .await? => {} - _ => { - Err(AccessForbidden( - "Follower information not visible".to_string(), - ))?; - } + let profile = self.get_profile_by_id(ctx, id).await?; + + match (&ctx.self_user, &profile.ff_visibility) { + (_, UserProfileFfvisibilityEnum::Public) => {} + (Some(self_user), UserProfileFfvisibilityEnum::Followers) + if ctx + .is_relationship_between( + Either::Right(self_user), + Either::Left(id), + UserRelationship::Follow, + ) + .await? => {} + _ => { + Err(AccessForbidden( + "Follower information not visible".to_string(), + ))?; } } diff --git a/src/web/mod.rs b/src/web/mod.rs index 9c58585..9e2be6e 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -28,7 +28,7 @@ impl IntoErrorCode for T { where &'a Self: Into<&'b str>, { - ErrorCode(self.into().to_string()) + ErrorCode(<&Self as Into<&'b str>>::into(self).to_string()) } }