1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 build_response::build_community_response,
5 community::{CommunityResponse, RemoveCommunity},
7 utils::{is_admin, local_user_view_from_jwt},
11 community::{Community, CommunityUpdateForm},
12 moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
17 error::{LemmyError, LemmyErrorExt, LemmyErrorType},
18 utils::time::naive_from_unix,
21 #[async_trait::async_trait(?Send)]
22 impl PerformCrud for RemoveCommunity {
23 type Response = CommunityResponse;
25 #[tracing::instrument(skip(context))]
26 async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
27 let data: &RemoveCommunity = self;
28 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
30 // Verify its an admin (only an admin can remove a community)
31 is_admin(&local_user_view)?;
34 let community_id = data.community_id;
35 let removed = data.removed;
39 &CommunityUpdateForm::builder()
40 .removed(Some(removed))
44 .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
47 let expires = data.expires.map(naive_from_unix);
48 let form = ModRemoveCommunityForm {
49 mod_person_id: local_user_view.person.id,
50 community_id: data.community_id,
51 removed: Some(removed),
52 reason: data.reason.clone(),
55 ModRemoveCommunity::create(&mut context.pool(), &form).await?;
57 build_community_response(context, local_user_view, community_id).await