2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 post::{LockPost, PostResponse},
8 check_community_deleted_or_removed,
9 get_local_user_view_from_jwt,
12 websocket::UserOperation,
14 use lemmy_db_schema::{
16 moderator::{ModLockPost, ModLockPostForm},
17 post::{Post, PostUpdateForm},
21 use lemmy_utils::{error::LemmyError, ConnectionId};
23 #[async_trait::async_trait(?Send)]
24 impl Perform for LockPost {
25 type Response = PostResponse;
27 #[tracing::instrument(skip(context, websocket_id))]
30 context: &Data<LemmyContext>,
31 websocket_id: Option<ConnectionId>,
32 ) -> Result<PostResponse, LemmyError> {
33 let data: &LockPost = self;
35 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
37 let post_id = data.post_id;
38 let orig_post = Post::read(context.pool(), post_id).await?;
41 local_user_view.person.id,
42 orig_post.community_id,
46 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
48 // Verify that only the mods can lock
51 local_user_view.person.id,
52 orig_post.community_id,
57 let post_id = data.post_id;
58 let locked = data.locked;
62 &PostUpdateForm::builder().locked(Some(locked)).build(),
67 let form = ModLockPostForm {
68 mod_person_id: local_user_view.person.id,
69 post_id: data.post_id,
72 ModLockPost::create(context.pool(), &form).await?;
75 .send_post_ws_message(
76 &UserOperation::LockPost,
79 Some(local_user_view.person.id),