2023-08-02 16:52:41 +00:00
|
|
|
use activitypub_federation::config::Data;
|
|
|
|
use actix_web::web::Json;
|
2022-04-28 20:32:32 +00:00
|
|
|
use lemmy_api_common::{
|
2023-06-06 16:27:22 +00:00
|
|
|
build_response::build_community_response,
|
2022-04-28 20:32:32 +00:00
|
|
|
community::{CommunityResponse, HideCommunity},
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2023-08-02 16:52:41 +00:00
|
|
|
send_activity::{ActivityChannel, SendActivityData},
|
2023-07-26 18:01:15 +00:00
|
|
|
utils::{is_admin, local_user_view_from_jwt, sanitize_html_opt},
|
2022-04-28 20:32:32 +00:00
|
|
|
};
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2022-10-27 09:24:07 +00:00
|
|
|
community::{Community, CommunityUpdateForm},
|
2022-04-28 20:32:32 +00:00
|
|
|
moderator::{ModHideCommunity, ModHideCommunityForm},
|
|
|
|
},
|
|
|
|
traits::Crud,
|
|
|
|
};
|
2023-07-10 14:50:07 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
|
2022-04-28 20:32:32 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn hide_community(
|
|
|
|
data: Json<HideCommunity>,
|
|
|
|
context: Data<LemmyContext>,
|
|
|
|
) -> Result<Json<CommunityResponse>, LemmyError> {
|
|
|
|
// Verify its a admin (only admin can hide or unhide it)
|
|
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
|
|
|
is_admin(&local_user_view)?;
|
|
|
|
|
2023-08-08 09:41:41 +00:00
|
|
|
let community_form = CommunityUpdateForm {
|
|
|
|
hidden: Some(data.hidden),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2023-08-02 16:52:41 +00:00
|
|
|
|
|
|
|
let mod_hide_community_form = ModHideCommunityForm {
|
|
|
|
community_id: data.community_id,
|
|
|
|
mod_person_id: local_user_view.person.id,
|
|
|
|
reason: sanitize_html_opt(&data.reason),
|
|
|
|
hidden: Some(data.hidden),
|
|
|
|
};
|
|
|
|
|
|
|
|
let community_id = data.community_id;
|
|
|
|
let community = Community::update(&mut context.pool(), community_id, &community_form)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunityHiddenStatus)?;
|
|
|
|
|
|
|
|
ModHideCommunity::create(&mut context.pool(), &mod_hide_community_form).await?;
|
|
|
|
|
|
|
|
ActivityChannel::submit_activity(
|
|
|
|
SendActivityData::UpdateCommunity(local_user_view.person.clone(), community),
|
|
|
|
&context,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
build_community_response(&context, local_user_view, community_id).await
|
2022-04-28 20:32:32 +00:00
|
|
|
}
|