2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 request::purge_image_from_pictrs,
5 site::{PurgeCommunity, PurgeItemResponse},
6 utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
12 moderator::{AdminPurgeCommunity, AdminPurgeCommunityForm},
16 use lemmy_utils::{error::LemmyError, ConnectionId};
18 #[async_trait::async_trait(?Send)]
19 impl Perform for PurgeCommunity {
20 type Response = PurgeItemResponse;
22 #[tracing::instrument(skip(context, _websocket_id))]
25 context: &Data<LemmyContext>,
26 _websocket_id: Option<ConnectionId>,
27 ) -> Result<Self::Response, LemmyError> {
28 let data: &Self = self;
30 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
32 // Only let admins purge an item
33 is_admin(&local_user_view)?;
35 let community_id = data.community_id;
37 // Read the community to get its images
38 let community = Community::read(context.pool(), community_id).await?;
40 if let Some(banner) = community.banner {
41 purge_image_from_pictrs(context.client(), context.settings(), &banner)
46 if let Some(icon) = community.icon {
47 purge_image_from_pictrs(context.client(), context.settings(), &icon)
52 purge_image_posts_for_community(
60 Community::delete(context.pool(), community_id).await?;
63 let reason = data.reason.clone();
64 let form = AdminPurgeCommunityForm {
65 admin_person_id: local_user_view.person.id,
69 AdminPurgeCommunity::create(context.pool(), &form).await?;
71 Ok(PurgeItemResponse { success: true })