1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 build_response::build_post_response,
6 post::{PostResponse, RemovePost},
7 utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
11 moderator::{ModRemovePost, ModRemovePostForm},
12 post::{Post, PostUpdateForm},
16 use lemmy_utils::error::LemmyError;
18 #[async_trait::async_trait(?Send)]
19 impl PerformCrud for RemovePost {
20 type Response = PostResponse;
22 #[tracing::instrument(skip(context))]
23 async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
24 let data: &RemovePost = self;
25 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
27 let post_id = data.post_id;
28 let orig_post = Post::read(context.pool(), post_id).await?;
31 local_user_view.person.id,
32 orig_post.community_id,
37 // Verify that only the mods can remove
40 local_user_view.person.id,
41 orig_post.community_id,
46 let post_id = data.post_id;
47 let removed = data.removed;
51 &PostUpdateForm::builder().removed(Some(removed)).build(),
56 let form = ModRemovePostForm {
57 mod_person_id: local_user_view.person.id,
58 post_id: data.post_id,
59 removed: Some(removed),
60 reason: data.reason.clone(),
62 ModRemovePost::create(context.pool(), &form).await?;
66 orig_post.community_id,
67 local_user_view.person.id,