forked from jmug/stoatchat
fix: short-circuit fetch user route if self
This commit is contained in:
@@ -8,6 +8,10 @@ use rocket::{serde::json::Json, State};
|
|||||||
#[openapi(tag = "User Information")]
|
#[openapi(tag = "User Information")]
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<User>> {
|
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 target = target.as_user(db).await?;
|
||||||
|
|
||||||
let permissions = perms(&user).user(&target).calc_user(db).await;
|
let permissions = perms(&user).user(&target).calc_user(db).await;
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ pub struct MutualResponse {
|
|||||||
#[openapi(tag = "Relationships")]
|
#[openapi(tag = "Relationships")]
|
||||||
#[get("/<target>/mutual")]
|
#[get("/<target>/mutual")]
|
||||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<MutualResponse>> {
|
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 {
|
if target.id == user.id {
|
||||||
return Err(Error::InvalidOperation);
|
return Err(Error::InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let target = target.as_user(db).await?;
|
||||||
|
|
||||||
if perms(&user)
|
if perms(&user)
|
||||||
.user(&target)
|
.user(&target)
|
||||||
.calc_user(db)
|
.calc_user(db)
|
||||||
|
|||||||
Reference in New Issue
Block a user