2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 community::{CommunityResponse, HideCommunity},
6 utils::{get_local_user_view_from_jwt, is_admin},
7 websocket::UserOperationCrud,
11 community::{Community, CommunityUpdateForm},
12 moderator::{ModHideCommunity, ModHideCommunityForm},
16 use lemmy_utils::{error::LemmyError, ConnectionId};
18 #[async_trait::async_trait(?Send)]
19 impl Perform for HideCommunity {
20 type Response = CommunityResponse;
22 #[tracing::instrument(skip(context, websocket_id))]
25 context: &Data<LemmyContext>,
26 websocket_id: Option<ConnectionId>,
27 ) -> Result<CommunityResponse, LemmyError> {
28 let data: &HideCommunity = self;
30 // Verify its a admin (only admin can hide or unhide it)
32 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
33 is_admin(&local_user_view)?;
35 let community_form = CommunityUpdateForm::builder()
36 .hidden(Some(data.hidden))
39 let mod_hide_community_form = ModHideCommunityForm {
40 community_id: data.community_id,
41 mod_person_id: local_user_view.person.id,
42 reason: data.reason.clone(),
43 hidden: Some(data.hidden),
46 let community_id = data.community_id;
47 Community::update(context.pool(), community_id, &community_form)
49 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
51 ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
54 .send_community_ws_message(
55 &UserOperationCrud::EditCommunity,