fix: short-circuit fetch user route if self

This commit is contained in:
Paul Makles
2022-04-29 13:10:52 +01:00
parent 278d795d50
commit 0651a501f6
2 changed files with 6 additions and 2 deletions

View File

@@ -8,6 +8,10 @@ use rocket::{serde::json::Json, State};
#[openapi(tag = "User Information")]
#[get("/<target>")]
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<User>> {
if target.id == user.id {
return Ok(Json(user));
}
let target = target.as_user(db).await?;
let permissions = perms(&user).user(&target).calc_user(db).await;

View File

@@ -20,12 +20,12 @@ pub struct MutualResponse {
#[openapi(tag = "Relationships")]
#[get("/<target>/mutual")]
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<MutualResponse>> {
let target = target.as_user(db).await?;
if target.id == user.id {
return Err(Error::InvalidOperation);
}
let target = target.as_user(db).await?;
if perms(&user)
.user(&target)
.calc_user(db)