+Parsing channel_id param correctly
+ Checking for proper permissions in user moar if let bindings!!!1
This commit is contained in:
parent
42e783ccf1
commit
20aca8a069
@ -84,25 +84,50 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: HashMap<&str, &str>) {
|
||||||
// make sure we have the right parameters provided
|
/*
|
||||||
if let Some(name) = params.get("channel_id") {
|
* Deletes a channel from the database, only after making sure the user has
|
||||||
if let Some(id) = name.as_u64() {
|
* the required permissions to do so
|
||||||
// TODO: something more intelligent with the logging im ngl
|
* @channel_id : u64 - required
|
||||||
match Channel::delete(pool, id).await {
|
*/
|
||||||
db::Response::Success => {},
|
use crate::perms;
|
||||||
db::Response::Other(data) => {
|
use db::member::Member;
|
||||||
eprintln!("\t{}", data);
|
use db::Response::*;
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
|
||||||
}
|
let uid = crate::http::extract_uid(¶ms);
|
||||||
_ => {
|
let permissions = match Member::get(pool, uid).await {
|
||||||
eprintln!("\tBro like restart the server");
|
Row(user) => user.permissions,
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
_ => 0
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
// make sure unpriveleged users don't delete channels somehow
|
||||||
|
if perms::has_perm(permissions, perms::DELETE_CHANNEL) == false{
|
||||||
|
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect the channel_id param before we attempt deletion
|
||||||
|
let channel_id = if let Some(chan) = params.get("channel_id") {
|
||||||
|
let c = chan;
|
||||||
|
match c.to_string().parse::<u64>() {
|
||||||
|
Ok(val) => Some(val),
|
||||||
|
_ => None
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(id) = channel_id {
|
||||||
|
match Channel::delete(pool, id).await {
|
||||||
|
Success => {/* nothing to do on sucess */},
|
||||||
|
Other(data) => {
|
||||||
|
eprintln!("\t{}", data);
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
_ => { // ngmi
|
||||||
|
eprintln!("\tBro like restart the server this branch should never execute");
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user