Compare commits

..

3 Commits

Author SHA1 Message Date
Paul Makles
e0b918771d chore: ensure restrict_reactions is used in conjunction with reactions list 2023-01-20 18:06:44 +00:00
Paul Makles
7a6bd70dcd feat: add route to fetch user flags
chore: bump rauth to change disabled account behaviour
2023-01-20 17:47:26 +00:00
Paul Makles
c0ef3d295a fix: fallback if vergen cannot generate data 2023-01-20 17:14:25 +00:00
10 changed files with 72 additions and 19 deletions

8
Cargo.lock generated
View File

@@ -2580,8 +2580,8 @@ dependencies = [
[[package]]
name = "rauth"
version = "1.0.3"
source = "git+https://github.com/insertish/rauth?tag=1.0.3#a62eae5076d94730d06e76d438cbca0d70161856"
version = "1.0.4"
source = "git+https://github.com/insertish/rauth?tag=1.0.4#2d3bc59623672e3ff57c49a90c4d3cd20780dbba"
dependencies = [
"async-std",
"async-trait",
@@ -3080,8 +3080,8 @@ dependencies = [
[[package]]
name = "rocket_rauth"
version = "1.0.3"
source = "git+https://github.com/insertish/rauth?tag=1.0.3#a62eae5076d94730d06e76d438cbca0d70161856"
version = "1.0.4"
source = "git+https://github.com/insertish/rauth?tag=1.0.4#2d3bc59623672e3ff57c49a90c4d3cd20780dbba"
dependencies = [
"iso8601-timestamp",
"rauth",

View File

@@ -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"

View File

@@ -12,5 +12,5 @@ fn main() {
}
}
vergen(Config::default()).unwrap();
vergen(Config::default()).ok();
}

View File

@@ -65,16 +65,20 @@ pub async fn message_send(
data.validate()
.map_err(|error| Error::FailedValidation { error })?;
// Validate Message is within reasonable length limits
Message::validate_sum(&data.content, &data.embeds)?;
// Ensure the request is unique
idempotency.consume_nonce(data.nonce).await?;
// Ensure we have permissions to send a message
let channel = target.as_channel(db).await?;
let mut permissions = perms(&user).channel(&channel);
permissions
.throw_permission_and_view_channel(db, Permission::SendMessage)
.await?;
// Check the message is not empty
if (data.content.as_ref().map_or(true, |v| v.is_empty()))
&& (data.attachments.as_ref().map_or(true, |v| v.is_empty()))
&& (data.embeds.as_ref().map_or(true, |v| v.is_empty()))
@@ -82,6 +86,22 @@ pub async fn message_send(
return Err(Error::EmptyMessage);
}
// Ensure restrict_reactions is not specified without reactions list
if let Some(interactions) = &data.interactions {
if interactions.restrict_reactions {
let disallowed = if let Some(list) = &interactions.reactions {
list.len() == 0
} else {
true
};
if disallowed {
return Err(Error::InvalidProperty);
}
}
}
// Start constructing the message
let message_id = Ulid::new().to_string();
let mut message = Message {
id: message_id.clone(),

View File

@@ -119,11 +119,12 @@ pub async fn root() -> Result<Json<RevoltConfig>> {
app: APP_URL.to_string(),
vapid: VAPID_PUBLIC_KEY.to_string(),
build: BuildInformation {
commit_sha: env!("VERGEN_GIT_SHA").to_string(),
commit_timestamp: env!("VERGEN_GIT_COMMIT_TIMESTAMP").to_string(),
semver: env!("VERGEN_GIT_SEMVER").to_string(),
origin_url: env!("GIT_ORIGIN_URL", "<missing>").to_string(),
timestamp: env!("VERGEN_BUILD_TIMESTAMP").to_string(),
commit_sha: env!("VERGEN_GIT_SHA", "<failed to generate>").to_string(),
commit_timestamp: env!("VERGEN_GIT_COMMIT_TIMESTAMP", "<failed to generate>")
.to_string(),
semver: env!("VERGEN_GIT_SEMVER", "<failed to generate>").to_string(),
origin_url: env!("GIT_ORIGIN_URL", "<failed to generate>").to_string(),
timestamp: env!("VERGEN_BUILD_TIMESTAMP", "<failed to generate>").to_string(),
},
}))
}

View File

@@ -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("/<target>/flags")]
pub async fn fetch_user_flags(db: &State<Database>, target: Ref) -> Result<Json<FlagResponse>> {
let flags = if let Ok(target) = target.as_user(db).await {
target.flags.unwrap_or_default()
} else {
0
};
Ok(Json(FlagResponse { flags }))
}

View File

@@ -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<Route>, 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,

View File

@@ -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"

View File

@@ -98,6 +98,8 @@ pub struct Interactions {
#[serde(skip_serializing_if = "Option::is_none", default)]
pub reactions: Option<IndexSet<String>>,
/// Whether reactions should be restricted to the given list
///
/// Can only be set to true if reactions list is of at least length 1
#[serde(skip_serializing_if = "if_false", default)]
pub restrict_reactions: bool,
}

View File

@@ -20,10 +20,10 @@ pub enum Error {
/// This error was not labeled :(
LabelMe,
// ? Onboarding related errors.
// ? Onboarding related errors
AlreadyOnboarded,
// ? User related errors.
// ? User related errors
UsernameTaken,
InvalidUsername,
UnknownUser,
@@ -33,7 +33,7 @@ pub enum Error {
BlockedByOther,
NotFriends,
// ? Channel related errors.
// ? Channel related errors
UnknownChannel,
UnknownAttachment,
UnknownMessage,
@@ -50,7 +50,7 @@ pub enum Error {
AlreadyInGroup,
NotInGroup,
// ? Server related errors.
// ? Server related errors
UnknownServer,
InvalidRole,
Banned,
@@ -59,12 +59,12 @@ pub enum Error {
},
TooManyEmoji,
// ? Bot related errors.
// ? Bot related errors
ReachedMaximumBots,
IsBot,
BotIsPrivate,
// ? Permission errors.
// ? Permission errors
MissingPermission {
permission: Permission,
},
@@ -75,7 +75,7 @@ pub enum Error {
CannotGiveMissingPermissions,
NotOwner,
// ? General errors.
// ? General errors
DatabaseError {
operation: &'static str,
with: &'static str,
@@ -83,6 +83,7 @@ pub enum Error {
InternalError,
InvalidOperation,
InvalidCredentials,
InvalidProperty,
InvalidSession,
DuplicateNonce,
VosoUnavailable,
@@ -175,6 +176,7 @@ impl<'r> Responder<'r, 'static> for Error {
Error::InternalError => Status::InternalServerError,
Error::InvalidOperation => Status::BadRequest,
Error::InvalidCredentials => Status::Unauthorized,
Error::InvalidProperty => Status::BadRequest,
Error::InvalidSession => Status::Unauthorized,
Error::DuplicateNonce => Status::Conflict,
Error::VosoUnavailable => Status::BadRequest,