Fetch profile route, push badges and status.

This commit is contained in:
Paul
2021-04-02 21:55:02 +01:00
parent 3797878d20
commit 78c42fd412
8 changed files with 56 additions and 6 deletions

View File

@@ -0,0 +1,24 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use mongodb::bson::doc;
use rocket_contrib::json::JsonValue;
#[get("/<target>/profile")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let target = target.fetch_user().await?;
let perm = permissions::PermissionCalculator::new(&user)
.with_user(&target)
.for_user_given()
.await?;
if !perm.get_view_profile() {
Err(Error::MissingPermission)?
}
if target.profile.is_some() {
Ok(json!({ "profile": target.profile }))
} else {
Ok(json!({}))
}
}