fix: squash audit log branch changes

Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
Zomatree
2026-04-20 03:47:49 +01:00
parent 057f2bb8b3
commit ada0bc0f8e
57 changed files with 1923 additions and 153 deletions

View File

@@ -1,7 +1,8 @@
use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference},
voice::{delete_voice_channel, UserVoiceChannel, VoiceClient},
Channel, Database, File, PartialChannel, SystemMessage, User, AMQP,
AuditLogEntryAction, Channel, Database, FieldsChannel, File, PartialChannel, SystemMessage,
User, AMQP,
};
use revolt_models::v0;
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
@@ -9,6 +10,8 @@ use revolt_result::{create_error, Result};
use rocket::{serde::json::Json, State};
use validator::Validate;
use crate::util::audit_log_reason::AuditLogReason;
/// # Edit Channel
///
/// Edit a channel object by its id.
@@ -19,6 +22,7 @@ pub async fn edit(
voice_client: &State<VoiceClient>,
amqp: &State<AMQP>,
user: User,
reason: AuditLogReason,
target: Reference<'_>,
data: Json<v0::DataEditChannel>,
) -> Result<Json<v0::Channel>> {
@@ -91,6 +95,8 @@ pub async fn edit(
.ok();
}
let before_channel = channel.clone();
match &mut channel {
Channel::Group {
id,
@@ -258,17 +264,33 @@ pub async fn edit(
_ => return Err(create_error!(InvalidOperation)),
};
channel
.update(
db,
partial,
data.remove.into_iter().map(|f| f.into()).collect(),
)
.await?;
let remove = data
.remove
.into_iter()
.map(|f| f.into())
.collect::<Vec<FieldsChannel>>();
let before = if before_channel.server().is_some() {
Some(before_channel.generate_diff(&partial, &remove))
} else {
None
};
channel.update(db, partial.clone(), remove).await?;
if channel.voice().is_none() {
delete_voice_channel(voice_client, &UserVoiceChannel::from_channel(&channel)).await?;
}
if let Some(before) = before {
AuditLogEntryAction::ChannelEdit {
channel: channel.id().to_string(),
before,
after: partial,
}
.insert(db, channel.server().unwrap().to_string(), reason, user.id, None)
.await;
};
Ok(Json(channel.into()))
}