Checking for valid channel.kind on /channels/create

This commit is contained in:
shockrah 2020-12-12 13:51:43 -08:00
parent 8e2b52d1c9
commit 201297f4c1

View File

@ -49,6 +49,11 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
match req_params { match req_params {
(Some(name), Some(desc), Some(kind)) => { (Some(name), Some(desc), Some(kind)) => {
use db::channels::{TEXT_CHANNEL, VOICE_CHANNEL};
if kind < VOICE_CHANNEL as i64 || kind > TEXT_CHANNEL as i64 {
*response.status_mut() = StatusCode::BAD_REQUEST; // restriciting to 1|2 for valid channel kinds
}
else {
// Send the data up to the db, then return the new channel back to the user(?) // Send the data up to the db, then return the new channel back to the user(?)
match db::channels::Channel::add(pool, name, desc, kind.try_into().unwrap()).await { match db::channels::Channel::add(pool, name, desc, kind.try_into().unwrap()).await {
db::Response::Row(row) => { db::Response::Row(row) => {
@ -65,6 +70,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
} }
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR _ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
} }
}
}, },
// basically one of the parameter gets failed so we bail on all of this // basically one of the parameter gets failed so we bail on all of this
_ => *response.status_mut() = StatusCode::BAD_REQUEST _ => *response.status_mut() = StatusCode::BAD_REQUEST