1 use actix_web::web::{Data, Json};
2 use lemmy_api_common::{
3 comment::{CommentReportResponse, ResolveCommentReport},
5 utils::{is_mod_or_admin, local_user_view_from_jwt},
7 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
8 use lemmy_db_views::structs::CommentReportView;
9 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
11 /// Resolves or unresolves a comment report and notifies the moderators of the community
12 #[tracing::instrument(skip(context))]
13 pub async fn resolve_comment_report(
14 data: Json<ResolveCommentReport>,
15 context: Data<LemmyContext>,
16 ) -> Result<Json<CommentReportResponse>, LemmyError> {
17 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
19 let report_id = data.report_id;
20 let person_id = local_user_view.person.id;
21 let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
23 let person_id = local_user_view.person.id;
24 is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
27 CommentReport::resolve(&mut context.pool(), report_id, person_id)
29 .with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
31 CommentReport::unresolve(&mut context.pool(), report_id, person_id)
33 .with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
36 let report_id = data.report_id;
37 let comment_report_view =
38 CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
40 Ok(Json(CommentReportResponse {