fix: Add limits to channels and roles

This commit is contained in:
Zomatree
2023-04-10 17:39:21 +01:00
parent b7b70346b4
commit 144f0d39c6
6 changed files with 47 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ use revolt_quark::{
},
perms,
web::idempotency::IdempotencyKey,
Db, Error, Permission, Ref, Result,
Db, Error, Permission, Ref, Result, variables::delta::{MAX_ATTACHMENT_COUNT, MAX_REPLY_COUNT},
};
use regex::Regex;
@@ -139,8 +139,8 @@ pub async fn message_send(
// 4. Verify replies are valid.
let mut replies = HashSet::new();
if let Some(entries) = data.replies {
if entries.len() > 5 {
return Err(Error::TooManyReplies);
if entries.len() > *MAX_REPLY_COUNT {
return Err(Error::TooManyReplies { max: *MAX_REPLY_COUNT });
}
for Reply { id, mention } in entries {
@@ -191,8 +191,8 @@ pub async fn message_send(
}
// ! FIXME: move this to app config
if ids.len() > 5 {
return Err(Error::TooManyAttachments);
if ids.len() > *MAX_ATTACHMENT_COUNT {
return Err(Error::TooManyAttachments { max: *MAX_ATTACHMENT_COUNT} );
}
for attachment_id in ids {

View File

@@ -1,5 +1,6 @@
use revolt_quark::models::emoji::EmojiParent;
use revolt_quark::models::{Emoji, File, User};
use revolt_quark::variables::delta::MAX_EMOJI_COUNT;
use revolt_quark::{perms, Db, Error, Permission, Result};
use serde::Deserialize;
use validator::Validate;
@@ -55,8 +56,8 @@ pub async fn create_emoji(
// Check that there are no more than 100 emoji
// ! FIXME: hardcoded upper limit
let emojis = db.fetch_emoji_by_parent_id(&server.id).await?;
if emojis.len() > 99 {
return Err(Error::TooManyEmoji);
if emojis.len() > *MAX_EMOJI_COUNT {
return Err(Error::TooManyEmoji { max: *MAX_EMOJI_COUNT });
}
}
EmojiParent::Detached => return Err(Error::InvalidOperation),

View File

@@ -2,7 +2,7 @@ use std::collections::HashMap;
use revolt_quark::{
models::{server::PartialServer, Channel, User},
perms, Db, Error, Permission, Ref, Result,
perms, Db, Error, Permission, Ref, Result, variables::delta::MAX_CHANNEL_COUNT,
};
use rocket::serde::json::Json;
@@ -58,6 +58,10 @@ pub async fn req(
.throw_permission(db, Permission::ManageChannel)
.await?;
if server.channels.len() > *MAX_CHANNEL_COUNT {
return Err(Error::TooManyChannels { max: *MAX_CHANNEL_COUNT })
};
let id = Ulid::new().to_string();
let mut channels = server.channels.clone();
channels.push(id.clone());

View File

@@ -1,6 +1,6 @@
use revolt_quark::{
models::{server::Role, User},
perms, Db, Error, Permission, Ref, Result,
perms, Db, Error, Permission, Ref, Result, variables::delta::MAX_ROLE_COUNT,
};
use rocket::serde::json::Json;
@@ -50,6 +50,10 @@ pub async fn req(
.throw_permission(db, Permission::ManageRole)
.await?;
if server.roles.len() > *MAX_ROLE_COUNT {
return Err(Error::TooManyRoles { max: *MAX_ROLE_COUNT })
};
let member_rank = permissions.get_member_rank();
let rank = if let Some(given_rank) = data.rank {
if given_rank <= member_rank.unwrap_or(i64::MIN) {