forked from jmug/stoatchat
fix: permit empty remove array in edit requests
This commit is contained in:
@@ -43,7 +43,7 @@ pub async fn edit(
|
||||
&& data.flags.is_none()
|
||||
&& data.analytics.is_none()
|
||||
&& data.discoverable.is_none()
|
||||
&& data.remove.is_none()
|
||||
&& data.remove.is_empty()
|
||||
{
|
||||
return Ok(Json(server.into()));
|
||||
} else if data.name.is_some()
|
||||
@@ -52,7 +52,7 @@ pub async fn edit(
|
||||
|| data.banner.is_some()
|
||||
|| data.system_messages.is_some()
|
||||
|| data.analytics.is_some()
|
||||
|| data.remove.is_some()
|
||||
|| !data.remove.is_empty()
|
||||
{
|
||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::ManageServer)?;
|
||||
}
|
||||
@@ -96,17 +96,15 @@ pub async fn edit(
|
||||
};
|
||||
|
||||
// 1. Remove fields from object
|
||||
if let Some(fields) = &remove {
|
||||
if fields.contains(&v0::FieldsServer::Banner) {
|
||||
if let Some(banner) = &server.banner {
|
||||
db.mark_attachment_as_deleted(&banner.id).await?;
|
||||
}
|
||||
if remove.contains(&v0::FieldsServer::Banner) {
|
||||
if let Some(banner) = &server.banner {
|
||||
db.mark_attachment_as_deleted(&banner.id).await?;
|
||||
}
|
||||
}
|
||||
|
||||
if fields.contains(&v0::FieldsServer::Icon) {
|
||||
if let Some(icon) = &server.icon {
|
||||
db.mark_attachment_as_deleted(&icon.id).await?;
|
||||
}
|
||||
if remove.contains(&v0::FieldsServer::Icon) {
|
||||
if let Some(icon) = &server.icon {
|
||||
db.mark_attachment_as_deleted(&icon.id).await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,13 +147,7 @@ pub async fn edit(
|
||||
}
|
||||
|
||||
server
|
||||
.update(
|
||||
db,
|
||||
partial,
|
||||
remove
|
||||
.map(|v| v.into_iter().map(Into::into).collect())
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.update(db, partial, remove.into_iter().map(Into::into).collect())
|
||||
.await?;
|
||||
|
||||
Ok(Json(server.into()))
|
||||
|
||||
Reference in New Issue
Block a user