From 7a6bd70dcd8bfee1d361e545f072bc093bc6a9b2 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 20 Jan 2023 17:47:26 +0000 Subject: [PATCH] feat: add route to fetch user flags chore: bump rauth to change disabled account behaviour --- crates/delta/Cargo.toml | 2 +- .../src/routes/users/fetch_user_flags.rs | 26 +++++++++++++++++++ crates/delta/src/routes/users/mod.rs | 2 ++ crates/quark/Cargo.toml | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 crates/delta/src/routes/users/fetch_user_flags.rs diff --git a/crates/delta/Cargo.toml b/crates/delta/Cargo.toml index 527bae57..f3d3ffa3 100644 --- a/crates/delta/Cargo.toml +++ b/crates/delta/Cargo.toml @@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s # web rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] } rocket_empty = { version = "0.1.1", features = ["schema"] } -rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.3" } +rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.4" } # spec generation schemars = "0.8.8" diff --git a/crates/delta/src/routes/users/fetch_user_flags.rs b/crates/delta/src/routes/users/fetch_user_flags.rs new file mode 100644 index 00000000..4025b649 --- /dev/null +++ b/crates/delta/src/routes/users/fetch_user_flags.rs @@ -0,0 +1,26 @@ +use revolt_quark::{Database, Ref, Result}; + +use rocket::{serde::json::Json, State}; +use serde::Serialize; + +/// # Flag Response +#[derive(Serialize, JsonSchema)] +pub struct FlagResponse { + /// Flags + flags: i32, +} + +/// # Fetch User Flags +/// +/// Retrieve a user's flags. +#[openapi(tag = "User Information")] +#[get("//flags")] +pub async fn fetch_user_flags(db: &State, target: Ref) -> Result> { + let flags = if let Ok(target) = target.as_user(db).await { + target.flags.unwrap_or_default() + } else { + 0 + }; + + Ok(Json(FlagResponse { flags })) +} diff --git a/crates/delta/src/routes/users/mod.rs b/crates/delta/src/routes/users/mod.rs index 2908148d..28e8ee0b 100644 --- a/crates/delta/src/routes/users/mod.rs +++ b/crates/delta/src/routes/users/mod.rs @@ -9,6 +9,7 @@ mod fetch_dms; mod fetch_profile; mod fetch_self; mod fetch_user; +mod fetch_user_flags; mod find_mutual; mod get_default_avatar; mod open_dm; @@ -21,6 +22,7 @@ pub fn routes() -> (Vec, OpenApi) { // User Information fetch_self::req, fetch_user::req, + fetch_user_flags::fetch_user_flags, edit_user::req, change_username::req, get_default_avatar::req, diff --git a/crates/quark/Cargo.toml b/crates/quark/Cargo.toml index f06a4d9f..e29eeff0 100644 --- a/crates/quark/Cargo.toml +++ b/crates/quark/Cargo.toml @@ -84,7 +84,7 @@ rocket_empty = { version = "0.1.1", optional = true, features = [ "schema" ] } rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "c17e8145baa4790319fdb6a473e465b960f55e7c" } # rAuth -rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.3", features = [ "async-std-runtime" ] } +rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.4", features = [ "async-std-runtime" ] } # Sentry sentry = "0.25.0"