Enhancement: Routes with no body should return 204 No Content.
This commit is contained in:
@@ -6,7 +6,7 @@ use validator::Contains;
|
||||
use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
@@ -14,7 +14,7 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[put("/<target>/permissions/<role>", data = "<data>", rank = 2)]
|
||||
pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Result<EmptyResponse> {
|
||||
let target = target.fetch_channel().await?;
|
||||
|
||||
match target {
|
||||
@@ -25,7 +25,7 @@ pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Res
|
||||
.with_server(&target)
|
||||
.for_server()
|
||||
.await?;
|
||||
|
||||
|
||||
if !perm.get_manage_roles() {
|
||||
return Err(Error::MissingPermission);
|
||||
}
|
||||
@@ -33,9 +33,9 @@ pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Res
|
||||
if !target.roles.has_element(&role) {
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
|
||||
let permissions: u32 = ChannelPermission::View as u32 | data.permissions;
|
||||
|
||||
|
||||
get_collection("channels")
|
||||
.update_one(
|
||||
doc! { "_id": &id },
|
||||
@@ -51,7 +51,7 @@ pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Res
|
||||
operation: "update_one",
|
||||
with: "channel"
|
||||
})?;
|
||||
|
||||
|
||||
role_permissions.insert(role, permissions as i32);
|
||||
ClientboundNotification::ChannelUpdate {
|
||||
id: id.clone(),
|
||||
@@ -62,7 +62,7 @@ pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Res
|
||||
}
|
||||
.publish(id);
|
||||
|
||||
Ok(())
|
||||
Ok(EmptyResponse {})
|
||||
}
|
||||
_ => Err(Error::InvalidOperation)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user