2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 request::purge_image_from_pictrs,
6 site::{PurgeCommunity, PurgeItemResponse},
7 utils::{is_admin, local_user_view_from_jwt, purge_image_posts_for_community},
12 moderator::{AdminPurgeCommunity, AdminPurgeCommunityForm},
16 use lemmy_utils::error::LemmyError;
18 #[async_trait::async_trait(?Send)]
19 impl Perform for PurgeCommunity {
20 type Response = PurgeItemResponse;
22 #[tracing::instrument(skip(context))]
23 async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
24 let data: &Self = self;
25 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
27 // Only let admin purge an item
28 is_admin(&local_user_view)?;
30 let community_id = data.community_id;
32 // Read the community to get its images
33 let community = Community::read(context.pool(), community_id).await?;
35 if let Some(banner) = community.banner {
36 purge_image_from_pictrs(context.client(), context.settings(), &banner)
41 if let Some(icon) = community.icon {
42 purge_image_from_pictrs(context.client(), context.settings(), &icon)
47 purge_image_posts_for_community(
55 Community::delete(context.pool(), community_id).await?;
58 let reason = data.reason.clone();
59 let form = AdminPurgeCommunityForm {
60 admin_person_id: local_user_view.person.id,
64 AdminPurgeCommunity::create(context.pool(), &form).await?;
66 Ok(PurgeItemResponse { success: true })