2023-03-20 21:32:31 +00:00
|
|
|
use crate::PerformCrud;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
|
|
|
custom_emoji::{DeleteCustomEmoji, DeleteCustomEmojiResponse},
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::{is_admin, local_user_view_from_jwt},
|
2023-03-20 21:32:31 +00:00
|
|
|
};
|
|
|
|
use lemmy_db_schema::source::custom_emoji::CustomEmoji;
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2023-03-20 21:32:31 +00:00
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl PerformCrud for DeleteCustomEmoji {
|
|
|
|
type Response = DeleteCustomEmojiResponse;
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
#[tracing::instrument(skip(self, context))]
|
2023-03-20 21:32:31 +00:00
|
|
|
async fn perform(
|
|
|
|
&self,
|
|
|
|
context: &Data<LemmyContext>,
|
|
|
|
) -> Result<DeleteCustomEmojiResponse, LemmyError> {
|
|
|
|
let data: &DeleteCustomEmoji = self;
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
2023-03-20 21:32:31 +00:00
|
|
|
|
|
|
|
// Make sure user is an admin
|
|
|
|
is_admin(&local_user_view)?;
|
|
|
|
CustomEmoji::delete(context.pool(), data.id).await?;
|
|
|
|
Ok(DeleteCustomEmojiResponse {
|
|
|
|
id: data.id,
|
|
|
|
success: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|