2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 post::{LockPost, PostResponse},
8 check_community_deleted_or_removed,
10 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;
34 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
36 let post_id = data.post_id;
37 let orig_post = Post::read(context.pool(), post_id).await?;
40 local_user_view.person.id,
41 orig_post.community_id,
45 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
47 // Verify that only the mods can lock
50 local_user_view.person.id,
51 orig_post.community_id,
56 let post_id = data.post_id;
57 let locked = data.locked;
61 &PostUpdateForm::builder().locked(Some(locked)).build(),
66 let form = ModLockPostForm {
67 mod_person_id: local_user_view.person.id,
68 post_id: data.post_id,
71 ModLockPost::create(context.pool(), &form).await?;
74 .send_post_ws_message(
75 &UserOperation::LockPost,
78 Some(local_user_view.person.id),