use actix_web::web::Data;
use lemmy_api_common::{
blocking,
+ check_image_has_local_domain,
community::{CommunityResponse, EditCommunity},
get_local_user_view_from_jwt,
};
traits::Crud,
};
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
-use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
+use lemmy_utils::{utils::check_slurs_opt, ConnectionId, LemmyError};
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)]
impl PerformCrud for EditCommunity {
type Response = CommunityResponse;
+ #[tracing::instrument(skip(context, websocket_id))]
async fn perform(
&self,
context: &Data<LemmyContext>,
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+ let icon = diesel_option_overwrite_to_url(&data.icon)?;
+ let banner = diesel_option_overwrite_to_url(&data.banner)?;
+
check_slurs_opt(&data.title, &context.settings().slur_regex())?;
check_slurs_opt(&data.description, &context.settings().slur_regex())?;
+ check_image_has_local_domain(icon.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
// Verify its a mod (only mods can edit it)
let community_id = data.community_id;
})
.await??;
if !mods.contains(&local_user_view.person.id) {
- return Err(ApiError::err_plain("not_a_moderator").into());
+ return Err(LemmyError::from_message("not_a_moderator"));
}
let community_id = data.community_id;
})
.await??;
- let icon = diesel_option_overwrite_to_url(&data.icon)?;
- let banner = diesel_option_overwrite_to_url(&data.banner)?;
-
let community_form = CommunityForm {
name: read_community.name,
title: data.title.to_owned().unwrap_or(read_community.title),
Community::update(conn, community_id, &community_form)
})
.await?
- .map_err(|e| ApiError::err("couldnt_update_community", e))?;
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
UpdateCommunity::send(
- &updated_community.into(),
+ updated_community.into(),
&local_user_view.person.into(),
context,
)