mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 13:36:59 +00:00
31 lines
888 B
Rust
31 lines
888 B
Rust
use revolt_database::{
|
|
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
|
Database, User,
|
|
};
|
|
use revolt_models::v0;
|
|
|
|
use revolt_permissions::{calculate_user_permissions, UserPermission};
|
|
use revolt_result::Result;
|
|
use rocket::State;
|
|
use crate::util::json::Json;
|
|
|
|
/// # Fetch User
|
|
///
|
|
/// Retrieve a user's information.
|
|
#[openapi(tag = "User Information")]
|
|
#[get("/<target>")]
|
|
pub async fn fetch(db: &State<Database>, user: User, target: Reference<'_>) -> Result<Json<v0::User>> {
|
|
if user.id == target.id {
|
|
return Ok(Json(user.into_self(false).await));
|
|
}
|
|
|
|
let target = target.as_user(db).await?;
|
|
|
|
let mut query = DatabasePermissionQuery::new(db, &user).user(&target);
|
|
calculate_user_permissions(&mut query)
|
|
.await
|
|
.throw_if_lacking_user_permission(UserPermission::Access)?;
|
|
|
|
Ok(Json(target.into(db, &user).await))
|
|
}
|