Adjust chat permisisons to allow deletion for channel admins

This commit is contained in:
Mikayla 2023-10-17 02:16:17 -07:00
parent b168bded1d
commit 162f625716
No known key found for this signature in database
2 changed files with 28 additions and 8 deletions

View file

@ -337,8 +337,22 @@ impl Database {
.filter(channel_message::Column::SenderId.eq(user_id))
.exec(&*tx)
.await?;
if result.rows_affected == 0 {
Err(anyhow!("no such message"))?;
if self
.check_user_is_channel_admin(channel_id, user_id, &*tx)
.await
.is_ok()
{
let result = channel_message::Entity::delete_by_id(message_id)
.exec(&*tx)
.await?;
if result.rows_affected == 0 {
Err(anyhow!("no such message"))?;
}
} else {
Err(anyhow!("operation could not be completed"))?;
}
}
Ok(participant_connection_ids)