2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 build_response::build_post_response,
6 post::{LockPost, PostResponse},
9 check_community_deleted_or_removed,
11 local_user_view_from_jwt,
14 use lemmy_db_schema::{
16 moderator::{ModLockPost, ModLockPostForm},
17 post::{Post, PostUpdateForm},
21 use lemmy_utils::error::LemmyError;
23 #[async_trait::async_trait(?Send)]
24 impl Perform for LockPost {
25 type Response = PostResponse;
27 #[tracing::instrument(skip(context))]
28 async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
29 let data: &LockPost = self;
30 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
32 let post_id = data.post_id;
33 let orig_post = Post::read(&mut context.pool(), post_id).await?;
36 local_user_view.person.id,
37 orig_post.community_id,
41 check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
43 // Verify that only the mods can lock
46 local_user_view.person.id,
47 orig_post.community_id,
52 let post_id = data.post_id;
53 let locked = data.locked;
57 &PostUpdateForm::builder().locked(Some(locked)).build(),
62 let form = ModLockPostForm {
63 mod_person_id: local_user_view.person.id,
64 post_id: data.post_id,
67 ModLockPost::create(&mut context.pool(), &form).await?;
71 orig_post.community_id,
72 local_user_view.person.id,