feat: Allow restricting server creation to specific users (#685)

Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com>
This commit is contained in:
Tom
2026-03-23 12:25:33 -07:00
committed by GitHub
parent cf2cedcee1
commit edfa97db10
7 changed files with 56 additions and 19 deletions

View File

@@ -37,6 +37,7 @@ impl IntoResponse for Error {
ErrorType::AlreadyPinned => StatusCode::BAD_REQUEST,
ErrorType::NotPinned => StatusCode::BAD_REQUEST,
ErrorType::CantCreateServers => StatusCode::FORBIDDEN,
ErrorType::UnknownServer => StatusCode::NOT_FOUND,
ErrorType::InvalidRole => StatusCode::NOT_FOUND,
ErrorType::Banned => StatusCode::FORBIDDEN,

View File

@@ -1,5 +1,5 @@
use std::panic::Location;
use std::fmt::Display;
use std::panic::Location;
#[cfg(feature = "serde")]
#[macro_use]
@@ -104,6 +104,7 @@ pub enum ErrorType {
NotPinned,
// ? Server related errors
CantCreateServers,
UnknownServer,
InvalidRole,
Banned,
@@ -232,17 +233,16 @@ impl<T, E: std::fmt::Debug + std::error::Error> ToRevoltError<T> for Result<T, E
fn to_internal_error(self) -> Result<T, Error> {
let loc = Location::caller();
self
.map_err(|e| {
log::error!("{e:?}");
#[cfg(feature = "sentry")]
sentry::capture_error(&e);
self.map_err(|e| {
log::error!("{e:?}");
#[cfg(feature = "sentry")]
sentry::capture_error(&e);
Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column())
}
})
Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column()),
}
})
}
}
@@ -251,11 +251,9 @@ impl<T> ToRevoltError<T> for Option<T> {
fn to_internal_error(self) -> Result<T, Error> {
let loc = Location::caller();
self.ok_or_else(|| {
Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column())
}
self.ok_or_else(|| Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column()),
})
}
}

View File

@@ -44,6 +44,7 @@ impl<'r> Responder<'r, 'static> for Error {
ErrorType::NotPinned => Status::BadRequest,
ErrorType::InvalidFlagValue => Status::BadRequest,
ErrorType::CantCreateServers => Status::Forbidden,
ErrorType::UnknownServer => Status::NotFound,
ErrorType::InvalidRole => Status::NotFound,
ErrorType::Banned => Status::Forbidden,