1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 post::{PostResponse, RemovePost},
6 utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
7 websocket::UserOperationCrud,
11 moderator::{ModRemovePost, ModRemovePostForm},
12 post::{Post, PostUpdateForm},
16 use lemmy_utils::{error::LemmyError, ConnectionId};
18 #[async_trait::async_trait(?Send)]
19 impl PerformCrud for RemovePost {
20 type Response = PostResponse;
22 #[tracing::instrument(skip(context, websocket_id))]
25 context: &Data<LemmyContext>,
26 websocket_id: Option<ConnectionId>,
27 ) -> Result<PostResponse, LemmyError> {
28 let data: &RemovePost = self;
30 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
32 let post_id = data.post_id;
33 let orig_post = Post::read(context.pool(), post_id).await?;
36 local_user_view.person.id,
37 orig_post.community_id,
42 // Verify that only the mods can remove
45 local_user_view.person.id,
46 orig_post.community_id,
51 let post_id = data.post_id;
52 let removed = data.removed;
56 &PostUpdateForm::builder().removed(Some(removed)).build(),
61 let form = ModRemovePostForm {
62 mod_person_id: local_user_view.person.id,
63 post_id: data.post_id,
64 removed: Some(removed),
65 reason: data.reason.clone(),
67 ModRemovePost::create(context.pool(), &form).await?;
70 .send_post_ws_message(
71 &UserOperationCrud::RemovePost,
74 Some(local_user_view.person.id),