mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
feat: add admin channel deletion endpoint
This commit is contained in:
@@ -290,6 +290,7 @@ auto_derived! {
|
||||
Discover = 16,
|
||||
|
||||
ManageAccounts = 17,
|
||||
ManageChannels = 18,
|
||||
}
|
||||
|
||||
pub enum AdminAuditItemActions {
|
||||
@@ -324,6 +325,9 @@ auto_derived! {
|
||||
// Accounts
|
||||
DeleteAccount,
|
||||
DisableAccount,
|
||||
|
||||
// Channels
|
||||
DeleteChannel,
|
||||
}
|
||||
|
||||
// Joiner payloads
|
||||
@@ -373,6 +377,7 @@ impl AdminAuditItemActions {
|
||||
AdminAuditItemActions::ServerFetchMembers => false,
|
||||
AdminAuditItemActions::DeleteAccount => true,
|
||||
AdminAuditItemActions::DisableAccount => true,
|
||||
AdminAuditItemActions::DeleteChannel => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
use crate::routes::admin::util::{
|
||||
create_audit_action, flatten_authorized_user, user_has_permission,
|
||||
};
|
||||
use revolt_database::{util::reference::Reference, AdminAuthorization, Database};
|
||||
use revolt_models::v0;
|
||||
use revolt_result::{create_error, Result};
|
||||
use rocket::State;
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
#[openapi(tag = "Admin")]
|
||||
#[delete("/admin/channels/<channel_id>?<case>")]
|
||||
pub async fn admin_delete_channel(
|
||||
db: &State<Database>,
|
||||
auth: AdminAuthorization,
|
||||
channel_id: Reference<'_>,
|
||||
case: Option<&str>,
|
||||
) -> Result<EmptyResponse> {
|
||||
let user = flatten_authorized_user(&auth);
|
||||
if !user_has_permission(user, v0::AdminUserPermissionFlags::ManageAccounts) {
|
||||
return Err(create_error!(MissingPermission {
|
||||
permission: "ManageAccounts".to_string()
|
||||
}));
|
||||
}
|
||||
|
||||
let target = channel_id.as_channel(&db).await?;
|
||||
|
||||
target.delete(&db).await?;
|
||||
|
||||
create_audit_action(
|
||||
&db,
|
||||
&user.id,
|
||||
v0::AdminAuditItemActions::DeleteChannel,
|
||||
case,
|
||||
Some(channel_id.id),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mod channel_delete;
|
||||
mod channel_edit;
|
||||
mod channel_wipe;
|
||||
pub mod channel_delete;
|
||||
pub mod channel_edit;
|
||||
pub mod channel_wipe;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
mod actions;
|
||||
mod fetch;
|
||||
pub mod actions;
|
||||
pub mod fetch;
|
||||
|
||||
@@ -40,5 +40,6 @@ pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
servers::actions::server_remove_members::admin_server_remove_members,
|
||||
accounts::account_delete::admin_account_delete,
|
||||
accounts::account_disable::admin_account_disable,
|
||||
channels::actions::channel_delete::admin_delete_channel,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user