feat(users): implement fetch self / user, open dm

This commit is contained in:
Paul Makles
2022-01-31 22:30:02 +00:00
parent c1cd4bfa66
commit 1d5800a3b8
8 changed files with 55 additions and 40 deletions

View File

@@ -1,8 +1,19 @@
use revolt_quark::{Ref, Result, models::User};
//! Fetch another user
//!
//! Will fail if the authenticated user does not
//! have permission to access the other user.
use rocket::serde::json::Value;
use revolt_quark::{Ref, Result, Error, models::User, perms, Database};
use rocket::{serde::json::Json, State};
#[get("/<target>")]
pub async fn req(user: User, target: Ref) -> Result<Value> {
todo!()
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<User>> {
let target = target.as_user(db).await?;
if perms(&user).user(&target).calc_user(db).await.get_access() {
Ok(Json(target))
} else {
Err(Error::NotFound)
}
}