Better tracing of API endpoints
This commit is contained in:
parent
cbf6c7fe43
commit
236502ad05
|
@ -11,6 +11,7 @@ use crate::service::MagnetarService;
|
||||||
use crate::web::auth::MaybeUser;
|
use crate::web::auth::MaybeUser;
|
||||||
use crate::web::{ApiError, ObjectNotFound};
|
use crate::web::{ApiError, ObjectNotFound};
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_note(
|
pub async fn handle_note(
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
Query(NoteByIdReq {
|
Query(NoteByIdReq {
|
||||||
|
|
|
@ -20,6 +20,7 @@ use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_user_info_self(
|
pub async fn handle_user_info_self(
|
||||||
Query(req): Query<Req<GetUserSelf>>,
|
Query(req): Query<Req<GetUserSelf>>,
|
||||||
State(service): State<Arc<MagnetarService>>,
|
State(service): State<Arc<MagnetarService>>,
|
||||||
|
@ -41,6 +42,7 @@ pub async fn handle_user_info_self(
|
||||||
Ok(Json(user))
|
Ok(Json(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_user_info(
|
pub async fn handle_user_info(
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
Query(req): Query<Req<GetUserById>>,
|
Query(req): Query<Req<GetUserById>>,
|
||||||
|
@ -69,6 +71,7 @@ pub async fn handle_user_info(
|
||||||
Ok(Json(user))
|
Ok(Json(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_user_info_by_acct(
|
pub async fn handle_user_info_by_acct(
|
||||||
Path(tag_str): Path<String>,
|
Path(tag_str): Path<String>,
|
||||||
Query(req): Query<Req<GetUserByAcct>>,
|
Query(req): Query<Req<GetUserByAcct>>,
|
||||||
|
@ -102,6 +105,7 @@ pub async fn handle_user_info_by_acct(
|
||||||
Ok(Json(user))
|
Ok(Json(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_user_by_id_many(
|
pub async fn handle_user_by_id_many(
|
||||||
Query(ManyUsersByIdReq { id }): Query<Req<GetManyUsersById>>,
|
Query(ManyUsersByIdReq { id }): Query<Req<GetManyUsersById>>,
|
||||||
State(service): State<Arc<MagnetarService>>,
|
State(service): State<Arc<MagnetarService>>,
|
||||||
|
@ -145,6 +149,7 @@ pub async fn handle_user_by_id_many(
|
||||||
Ok(Json(users_ordered))
|
Ok(Json(users_ordered))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_notifications(
|
pub async fn handle_notifications(
|
||||||
Query(NotificationsReq {
|
Query(NotificationsReq {
|
||||||
ref exclude_types,
|
ref exclude_types,
|
||||||
|
@ -179,6 +184,7 @@ pub async fn handle_notifications(
|
||||||
Ok((pagination, Json(notifications)))
|
Ok((pagination, Json(notifications)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_following_self(
|
pub async fn handle_following_self(
|
||||||
Query(_): Query<Req<GetFollowingSelf>>,
|
Query(_): Query<Req<GetFollowingSelf>>,
|
||||||
State(service): State<Arc<MagnetarService>>,
|
State(service): State<Arc<MagnetarService>>,
|
||||||
|
@ -194,6 +200,7 @@ pub async fn handle_following_self(
|
||||||
Ok((pagination, Json(users)))
|
Ok((pagination, Json(users)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_followers_self(
|
pub async fn handle_followers_self(
|
||||||
Query(_): Query<Req<GetFollowersSelf>>,
|
Query(_): Query<Req<GetFollowersSelf>>,
|
||||||
State(service): State<Arc<MagnetarService>>,
|
State(service): State<Arc<MagnetarService>>,
|
||||||
|
@ -209,6 +216,7 @@ pub async fn handle_followers_self(
|
||||||
Ok((pagination, Json(users)))
|
Ok((pagination, Json(users)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_following(
|
pub async fn handle_following(
|
||||||
Query(_): Query<Req<GetFollowingById>>,
|
Query(_): Query<Req<GetFollowingById>>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
|
@ -223,6 +231,7 @@ pub async fn handle_following(
|
||||||
Ok((pagination, Json(users)))
|
Ok((pagination, Json(users)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_followers(
|
pub async fn handle_followers(
|
||||||
Query(_): Query<Req<GetFollowersById>>,
|
Query(_): Query<Req<GetFollowersById>>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
|
@ -237,6 +246,7 @@ pub async fn handle_followers(
|
||||||
Ok((pagination, Json(users)))
|
Ok((pagination, Json(users)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(err, skip_all)]
|
||||||
pub async fn handle_follow_requests_self(
|
pub async fn handle_follow_requests_self(
|
||||||
Query(_): Query<Req<GetFollowRequestsSelf>>,
|
Query(_): Query<Req<GetFollowRequestsSelf>>,
|
||||||
State(service): State<Arc<MagnetarService>>,
|
State(service): State<Arc<MagnetarService>>,
|
||||||
|
|
|
@ -26,7 +26,7 @@ use magnetar_sdk::types::{Id, MmXml};
|
||||||
use magnetar_sdk::{mmm, Optional, Packed, Required};
|
use magnetar_sdk::{mmm, Optional, Packed, Required};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::{join, try_join};
|
use tokio::{join, try_join};
|
||||||
use tracing::warn;
|
use tracing::{instrument, warn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub trait UserShapedData<'a>: Send + Sync {
|
pub trait UserShapedData<'a>: Send + Sync {
|
||||||
|
@ -566,24 +566,26 @@ impl UserModel {
|
||||||
ctx: &PackingContext,
|
ctx: &PackingContext,
|
||||||
id: &str,
|
id: &str,
|
||||||
) -> Result<(), ApiError> {
|
) -> Result<(), ApiError> {
|
||||||
if !ctx.is_id_self(id) {
|
if ctx.is_id_self(id) {
|
||||||
let profile = self.get_profile_by_id(ctx, id).await?;
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
match (&ctx.self_user, &profile.ff_visibility) {
|
let profile = self.get_profile_by_id(ctx, id).await?;
|
||||||
(_, UserProfileFfvisibilityEnum::Public) => {}
|
|
||||||
(Some(self_user), UserProfileFfvisibilityEnum::Followers)
|
match (&ctx.self_user, &profile.ff_visibility) {
|
||||||
if ctx
|
(_, UserProfileFfvisibilityEnum::Public) => {}
|
||||||
.is_relationship_between(
|
(Some(self_user), UserProfileFfvisibilityEnum::Followers)
|
||||||
Either::Right(self_user),
|
if ctx
|
||||||
Either::Left(id),
|
.is_relationship_between(
|
||||||
UserRelationship::Follow,
|
Either::Right(self_user),
|
||||||
)
|
Either::Left(id),
|
||||||
.await? => {}
|
UserRelationship::Follow,
|
||||||
_ => {
|
)
|
||||||
Err(AccessForbidden(
|
.await? => {}
|
||||||
"Follower information not visible".to_string(),
|
_ => {
|
||||||
))?;
|
Err(AccessForbidden(
|
||||||
}
|
"Follower information not visible".to_string(),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl<T: ?Sized> IntoErrorCode for T {
|
||||||
where
|
where
|
||||||
&'a Self: Into<&'b str>,
|
&'a Self: Into<&'b str>,
|
||||||
{
|
{
|
||||||
ErrorCode(self.into().to_string())
|
ErrorCode(<&Self as Into<&'b str>>::into(self).to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue