From 9e604b4038ddea3b488565044a5da8c54a0783a2 Mon Sep 17 00:00:00 2001 From: eiknat Date: Tue, 3 Nov 2020 21:15:11 -0500 Subject: [PATCH] update/fix migration, add some doc also run cargo fmt/clippy --- lemmy_api/src/comment.rs | 50 ++++++++------ lemmy_api/src/community.rs | 3 +- lemmy_api/src/lib.rs | 14 ++-- lemmy_api/src/post.rs | 53 ++++++++------- lemmy_api/src/user.rs | 17 +++-- lemmy_db/src/comment_report.rs | 51 ++++++++++---- lemmy_db/src/community.rs | 11 +-- lemmy_db/src/lib.rs | 12 ++-- lemmy_db/src/post_report.rs | 67 +++++++++++++------ lemmy_db/src/schema.rs | 8 +-- lemmy_structs/src/comment.rs | 5 +- lemmy_structs/src/user.rs | 4 +- lemmy_websocket/src/chat_server.rs | 4 +- lemmy_websocket/src/handlers.rs | 4 +- .../up.sql | 13 ++-- src/routes/api.rs | 22 +++--- 16 files changed, 207 insertions(+), 131 deletions(-) diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index 083cb841..b1107d0d 100644 --- a/lemmy_api/src/comment.rs +++ b/lemmy_api/src/comment.rs @@ -1,11 +1,11 @@ use crate::{ check_community_ban, + collect_moderated_communities, get_post, get_user_from_jwt, get_user_from_jwt_opt, is_mod_or_admin, Perform, - collect_moderated_communities, }; use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; @@ -20,9 +20,9 @@ use lemmy_db::{ Crud, Likeable, ListingType, + Reportable, Saveable, SortType, - Reportable, }; use lemmy_structs::{blocking, comment::*, send_local_notifs}; use lemmy_utils::{ @@ -32,9 +32,12 @@ use lemmy_utils::{ ConnectionId, LemmyError, }; -use lemmy_websocket::{messages::{SendComment, SendUserRoomMessage}, LemmyContext, UserOperation}; +use lemmy_websocket::{ + messages::{SendComment, SendModRoomMessage, SendUserRoomMessage}, + LemmyContext, + UserOperation, +}; use std::str::FromStr; -use lemmy_websocket::messages::SendModRoomMessage; #[async_trait::async_trait(?Send)] impl Perform for CreateComment { @@ -687,6 +690,7 @@ impl Perform for GetComments { } } +/// Creates a comment report and notifies the moderators of the community #[async_trait::async_trait(?Send)] impl Perform for CreateCommentReport { type Response = CreateCommentReportResponse; @@ -707,27 +711,30 @@ impl Perform for CreateCommentReport { if reason.len() > 1000 { return Err(APIError::err("report_too_long").into()); } - + let user_id = user.id; let comment_id = data.comment_id; let comment = blocking(context.pool(), move |conn| { CommentView::read(&conn, comment_id, None) - }).await??; + }) + .await??; check_community_ban(user_id, comment.community_id, context.pool()).await?; let report_form = CommentReportForm { creator_id: user_id, comment_id, - comment_text: comment.content, + original_comment_text: comment.content, reason: data.reason.to_owned(), }; let report = match blocking(context.pool(), move |conn| { CommentReport::report(conn, &report_form) - }).await? { + }) + .await? + { Ok(report) => report, - Err(_e) => return Err(APIError::err("couldnt_create_report").into()) + Err(_e) => return Err(APIError::err("couldnt_create_report").into()), }; let res = CreateCommentReportResponse { success: true }; @@ -750,6 +757,7 @@ impl Perform for CreateCommentReport { } } +/// Resolves or unresolves a comment report and notifies the moderators of the community #[async_trait::async_trait(?Send)] impl Perform for ResolveCommentReport { type Response = ResolveCommentReportResponse; @@ -765,7 +773,8 @@ impl Perform for ResolveCommentReport { let report_id = data.report_id; let report = blocking(context.pool(), move |conn| { CommentReportView::read(&conn, report_id) - }).await??; + }) + .await??; let user_id = user.id; is_mod_or_admin(context.pool(), user_id, report.community_id).await?; @@ -779,8 +788,8 @@ impl Perform for ResolveCommentReport { } }; - if blocking(context.pool(),resolve_fun).await?.is_err() { - return Err(APIError::err("couldnt_resolve_report").into()) + if blocking(context.pool(), resolve_fun).await?.is_err() { + return Err(APIError::err("couldnt_resolve_report").into()); }; let report_id = data.report_id; @@ -800,6 +809,8 @@ impl Perform for ResolveCommentReport { } } +/// Lists comment reports for a community if an id is supplied +/// or returns all comment reports for communities a user moderates #[async_trait::async_trait(?Send)] impl Perform for ListCommentReports { type Response = ListCommentReportsResponse; @@ -814,18 +825,19 @@ impl Perform for ListCommentReports { let user_id = user.id; let community_id = data.community; - let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?; + let community_ids = + collect_moderated_communities(user_id, community_id, context.pool()).await?; let page = data.page; let limit = data.limit; let comments = blocking(context.pool(), move |conn| { CommentReportQueryBuilder::create(conn) - .community_ids(community_ids) - .page(page) - .limit(limit) - .list() + .community_ids(community_ids) + .page(page) + .limit(limit) + .list() }) - .await??; + .await??; let res = ListCommentReportsResponse { comments }; @@ -838,4 +850,4 @@ impl Perform for ListCommentReports { Ok(res) } -} \ No newline at end of file +} diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 35ed4aa9..861433a8 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -36,12 +36,11 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::{ - messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage}, + messages::{GetCommunityUsersOnline, JoinCommunityRoom, JoinModRoom, SendCommunityRoomMessage}, LemmyContext, UserOperation, }; use std::str::FromStr; -use lemmy_websocket::messages::JoinModRoom; #[async_trait::async_trait(?Send)] impl Perform for GetCommunity { diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 96f2b061..7c5c5e20 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -100,6 +100,13 @@ pub(in crate) async fn check_community_ban( } } +/// Returns a list of communities that the user moderates +/// or if a community_id is supplied validates the user is a moderator +/// of that community and returns the community id in a vec +/// +/// * `user_id` - the user id of the moderator +/// * `community_id` - optional community id to check for moderator privileges +/// * `pool` - the diesel db pool pub(in crate) async fn collect_moderated_communities( user_id: i32, community_id: Option, @@ -112,7 +119,8 @@ pub(in crate) async fn collect_moderated_communities( } else { let ids = blocking(pool, move |conn: &'_ _| { CommunityModerator::get_user_moderated_communities(conn, user_id) - }).await??; + }) + .await??; Ok(ids) } } @@ -195,9 +203,7 @@ pub async fn match_websocket_operation( UserOperation::CommunityJoin => { do_websocket_operation::(context, id, op, data).await } - UserOperation::ModJoin => { - do_websocket_operation::(context, id, op, data).await - } + UserOperation::ModJoin => do_websocket_operation::(context, id, op, data).await, UserOperation::SaveUserSettings => { do_websocket_operation::(context, id, op, data).await } diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index b703c2ef..707c8335 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -1,11 +1,11 @@ use crate::{ check_community_ban, check_optional_url, + collect_moderated_communities, get_user_from_jwt, get_user_from_jwt_opt, is_mod_or_admin, Perform, - collect_moderated_communities, }; use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; @@ -21,9 +21,9 @@ use lemmy_db::{ Crud, Likeable, ListingType, + Reportable, Saveable, SortType, - Reportable, }; use lemmy_structs::{blocking, post::*}; use lemmy_utils::{ @@ -35,13 +35,7 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::{ - messages::{ - GetPostUsersOnline, - JoinPostRoom, - SendModRoomMessage, - SendPost, - SendUserRoomMessage - }, + messages::{GetPostUsersOnline, JoinPostRoom, SendModRoomMessage, SendPost, SendUserRoomMessage}, LemmyContext, UserOperation, }; @@ -751,6 +745,7 @@ impl Perform for PostJoin { } } +/// Creates a post report and notifies the moderators of the community #[async_trait::async_trait(?Send)] impl Perform for CreatePostReport { type Response = CreatePostReportResponse; @@ -771,29 +766,32 @@ impl Perform for CreatePostReport { if reason.len() > 1000 { return Err(APIError::err("report_too_long").into()); } - + let user_id = user.id; let post_id = data.post_id; let post = blocking(context.pool(), move |conn| { PostView::read(&conn, post_id, None) - }).await??; + }) + .await??; check_community_ban(user_id, post.community_id, context.pool()).await?; let report_form = PostReportForm { creator_id: user_id, post_id, - post_name: post.name, - post_url: post.url, - post_body: post.body, + original_post_name: post.name, + original_post_url: post.url, + original_post_body: post.body, reason: data.reason.to_owned(), }; let report = match blocking(context.pool(), move |conn| { PostReport::report(conn, &report_form) - }).await? { + }) + .await? + { Ok(report) => report, - Err(_e) => return Err(APIError::err("couldnt_create_report").into()) + Err(_e) => return Err(APIError::err("couldnt_create_report").into()), }; let res = CreatePostReportResponse { success: true }; @@ -816,6 +814,7 @@ impl Perform for CreatePostReport { } } +/// Resolves or unresolves a post report and notifies the moderators of the community #[async_trait::async_trait(?Send)] impl Perform for ResolvePostReport { type Response = ResolvePostReportResponse; @@ -831,7 +830,8 @@ impl Perform for ResolvePostReport { let report_id = data.report_id; let report = blocking(context.pool(), move |conn| { PostReportView::read(&conn, report_id) - }).await??; + }) + .await??; let user_id = user.id; is_mod_or_admin(context.pool(), user_id, report.community_id).await?; @@ -850,8 +850,8 @@ impl Perform for ResolvePostReport { resolved: true, }; - if blocking(context.pool(),resolve_fun).await?.is_err() { - return Err(APIError::err("couldnt_resolve_report").into()) + if blocking(context.pool(), resolve_fun).await?.is_err() { + return Err(APIError::err("couldnt_resolve_report").into()); }; context.chat_server().do_send(SendModRoomMessage { @@ -865,6 +865,8 @@ impl Perform for ResolvePostReport { } } +/// Lists post reports for a community if an id is supplied +/// or returns all post reports for communities a user moderates #[async_trait::async_trait(?Send)] impl Perform for ListPostReports { type Response = ListPostReportsResponse; @@ -879,18 +881,19 @@ impl Perform for ListPostReports { let user_id = user.id; let community_id = data.community; - let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?; + let community_ids = + collect_moderated_communities(user_id, community_id, context.pool()).await?; let page = data.page; let limit = data.limit; let posts = blocking(context.pool(), move |conn| { PostReportQueryBuilder::create(conn) - .community_ids(community_ids) - .page(page) - .limit(limit) - .list() + .community_ids(community_ids) + .page(page) + .limit(limit) + .list() }) - .await??; + .await??; let res = ListPostReportsResponse { posts }; diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 5efc6331..3b0b6d3f 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -2,11 +2,11 @@ use crate::{ captcha_espeak_wav_base64, check_optional_url, claims::Claims, + collect_moderated_communities, get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform, - collect_moderated_communities }; use actix_web::web::Data; use anyhow::Context; @@ -1312,7 +1312,8 @@ impl Perform for GetReportCount { let user_id = user.id; let community_id = data.community; - let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?; + let community_ids = + collect_moderated_communities(user_id, community_id, context.pool()).await?; let res = { if community_ids.is_empty() { @@ -1323,12 +1324,16 @@ impl Perform for GetReportCount { } } else { let ids = community_ids.clone(); - let comment_reports = blocking(context.pool(), move |conn| - CommentReportView::get_report_count(conn, &ids)).await??; + let comment_reports = blocking(context.pool(), move |conn| { + CommentReportView::get_report_count(conn, &ids) + }) + .await??; let ids = community_ids.clone(); - let post_reports = blocking(context.pool(), move |conn| - PostReportView::get_report_count(conn, &ids)).await??; + let post_reports = blocking(context.pool(), move |conn| { + PostReportView::get_report_count(conn, &ids) + }) + .await??; GetReportCountResponse { community: data.community, diff --git a/lemmy_db/src/comment_report.rs b/lemmy_db/src/comment_report.rs index 83f43240..b1037f11 100644 --- a/lemmy_db/src/comment_report.rs +++ b/lemmy_db/src/comment_report.rs @@ -1,14 +1,21 @@ use diesel::{dsl::*, pg::Pg, result::Error, *}; use serde::{Deserialize, Serialize}; -use crate::{limit_and_offset, MaybeOptional, schema::comment_report, comment::Comment, Reportable, naive_now}; +use crate::{ + comment::Comment, + limit_and_offset, + naive_now, + schema::comment_report, + MaybeOptional, + Reportable, +}; table! { comment_report_view (id) { id -> Int4, creator_id -> Int4, comment_id -> Int4, - comment_text -> Text, + original_comment_text -> Text, reason -> Text, resolved -> Bool, resolver_id -> Nullable, @@ -43,7 +50,7 @@ pub struct CommentReport { pub id: i32, pub creator_id: i32, pub comment_id: i32, - pub comment_text: String, + pub original_comment_text: String, pub reason: String, pub resolved: bool, pub resolver_id: Option, @@ -56,11 +63,15 @@ pub struct CommentReport { pub struct CommentReportForm { pub creator_id: i32, pub comment_id: i32, - pub comment_text: String, + pub original_comment_text: String, pub reason: String, } impl Reportable for CommentReport { + /// creates a comment report and returns it + /// + /// * `conn` - the postgres connection + /// * `comment_report_form` - the filled CommentReportForm to insert fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result { use crate::schema::comment_report::dsl::*; insert_into(comment_report) @@ -68,6 +79,11 @@ impl Reportable for CommentReport { .get_result::(conn) } + /// resolve a comment report + /// + /// * `conn` - the postgres connection + /// * `report_id` - the id of the report to resolve + /// * `by_resolver_id` - the id of the user resolving the report fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::comment_report::dsl::*; update(comment_report.find(report_id)) @@ -79,6 +95,11 @@ impl Reportable for CommentReport { .execute(conn) } + /// unresolve a comment report + /// + /// * `conn` - the postgres connection + /// * `report_id` - the id of the report to unresolve + /// * `by_resolver_id` - the id of the user unresolving the report fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::comment_report::dsl::*; update(comment_report.find(report_id)) @@ -91,15 +112,13 @@ impl Reportable for CommentReport { } } -#[derive( -Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone, -)] +#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone)] #[table_name = "comment_report_view"] pub struct CommentReportView { pub id: i32, pub creator_id: i32, pub comment_id: i32, - pub comment_text: String, + pub original_comment_text: String, pub reason: String, pub resolved: bool, pub resolver_id: Option, @@ -136,19 +155,23 @@ pub struct CommentReportQueryBuilder<'a> { } impl CommentReportView { + /// returns the CommentReportView for the provided report_id + /// + /// * `report_id` - the report id to obtain pub fn read(conn: &PgConnection, report_id: i32) -> Result { use super::comment_report::comment_report_view::dsl::*; - comment_report_view - .find(report_id) - .first::(conn) + comment_report_view.find(report_id).first::(conn) } - pub fn get_report_count(conn: &PgConnection, community_ids: &Vec) -> Result { + /// returns the current unresolved comment report count for the supplied community ids + /// + /// * `community_ids` - a Vec of community_ids to get a count for + pub fn get_report_count(conn: &PgConnection, community_ids: &Vec) -> Result { use super::comment_report::comment_report_view::dsl::*; comment_report_view .filter(resolved.eq(false).and(community_id.eq_any(community_ids))) - .select(sql::("COUNT(*)")) - .first::(conn) + .select(count(id)) + .first::(conn) } } diff --git a/lemmy_db/src/community.rs b/lemmy_db/src/community.rs index a888015e..b0474398 100644 --- a/lemmy_db/src/community.rs +++ b/lemmy_db/src/community.rs @@ -225,12 +225,15 @@ impl CommunityModerator { diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn) } - pub fn get_user_moderated_communities(conn: &PgConnection, for_user_id: i32) -> Result, Error> { + pub fn get_user_moderated_communities( + conn: &PgConnection, + for_user_id: i32, + ) -> Result, Error> { use crate::schema::community_moderator::dsl::*; community_moderator - .filter(user_id.eq(for_user_id)) - .select(community_id) - .load::(conn) + .filter(user_id.eq(for_user_id)) + .select(community_id) + .load::(conn) } } diff --git a/lemmy_db/src/lib.rs b/lemmy_db/src/lib.rs index d7f59d03..655ba68b 100644 --- a/lemmy_db/src/lib.rs +++ b/lemmy_db/src/lib.rs @@ -113,14 +113,14 @@ pub trait Readable { pub trait Reportable { fn report(conn: &PgConnection, form: &T) -> Result - where - Self: Sized; + where + Self: Sized; fn resolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result - where - Self: Sized; + where + Self: Sized; fn unresolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result - where - Self: Sized; + where + Self: Sized; } pub trait MaybeOptional { diff --git a/lemmy_db/src/post_report.rs b/lemmy_db/src/post_report.rs index 61c32c0e..3422f54a 100644 --- a/lemmy_db/src/post_report.rs +++ b/lemmy_db/src/post_report.rs @@ -1,16 +1,23 @@ use diesel::{dsl::*, pg::Pg, result::Error, *}; use serde::{Deserialize, Serialize}; -use crate::{limit_and_offset, MaybeOptional, schema::post_report, post::Post, Reportable, naive_now}; +use crate::{ + limit_and_offset, + naive_now, + post::Post, + schema::post_report, + MaybeOptional, + Reportable, +}; table! { post_report_view (id) { id -> Int4, creator_id -> Int4, post_id -> Int4, - post_name -> Varchar, - post_url -> Nullable, - post_body -> Nullable, + original_post_name -> Varchar, + original_post_url -> Nullable, + original_post_body -> Nullable, reason -> Text, resolved -> Bool, resolver_id -> Nullable, @@ -46,9 +53,9 @@ pub struct PostReport { pub id: i32, pub creator_id: i32, pub post_id: i32, - pub post_name: String, - pub post_url: Option, - pub post_body: Option, + pub original_post_name: String, + pub original_post_url: Option, + pub original_post_body: Option, pub reason: String, pub resolved: bool, pub resolver_id: Option, @@ -61,13 +68,17 @@ pub struct PostReport { pub struct PostReportForm { pub creator_id: i32, pub post_id: i32, - pub post_name: String, - pub post_url: Option, - pub post_body: Option, + pub original_post_name: String, + pub original_post_url: Option, + pub original_post_body: Option, pub reason: String, } impl Reportable for PostReport { + /// creates a post report and returns it + /// + /// * `conn` - the postgres connection + /// * `post_report_form` - the filled CommentReportForm to insert fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result { use crate::schema::post_report::dsl::*; insert_into(post_report) @@ -75,6 +86,11 @@ impl Reportable for PostReport { .get_result::(conn) } + /// resolve a post report + /// + /// * `conn` - the postgres connection + /// * `report_id` - the id of the report to resolve + /// * `by_resolver_id` - the id of the user resolving the report fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::post_report::dsl::*; update(post_report.find(report_id)) @@ -86,6 +102,11 @@ impl Reportable for PostReport { .execute(conn) } + /// resolve a post report + /// + /// * `conn` - the postgres connection + /// * `report_id` - the id of the report to unresolve + /// * `by_resolver_id` - the id of the user unresolving the report fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::post_report::dsl::*; update(post_report.find(report_id)) @@ -98,17 +119,15 @@ impl Reportable for PostReport { } } -#[derive( -Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone, -)] +#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone)] #[table_name = "post_report_view"] pub struct PostReportView { pub id: i32, pub creator_id: i32, pub post_id: i32, - pub post_name: String, - pub post_url: Option, - pub post_body: Option, + pub original_post_name: String, + pub original_post_url: Option, + pub original_post_body: Option, pub reason: String, pub resolved: bool, pub resolver_id: Option, @@ -137,19 +156,23 @@ pub struct PostReportView { } impl PostReportView { + /// returns the PostReportView for the provided report_id + /// + /// * `report_id` - the report id to obtain pub fn read(conn: &PgConnection, report_id: i32) -> Result { use super::post_report::post_report_view::dsl::*; - post_report_view - .find(report_id) - .first::(conn) + post_report_view.find(report_id).first::(conn) } - pub fn get_report_count(conn: &PgConnection, community_ids: &Vec) -> Result { + /// returns the current unresolved post report count for the supplied community ids + /// + /// * `community_ids` - a Vec of community_ids to get a count for + pub fn get_report_count(conn: &PgConnection, community_ids: &Vec) -> Result { use super::post_report::post_report_view::dsl::*; post_report_view .filter(resolved.eq(false).and(community_id.eq_any(community_ids))) - .select(sql::("COUNT(*)")) - .first::(conn) + .select(count(id)) + .first::(conn) } } diff --git a/lemmy_db/src/schema.rs b/lemmy_db/src/schema.rs index b23deff3..400c87d4 100644 --- a/lemmy_db/src/schema.rs +++ b/lemmy_db/src/schema.rs @@ -86,7 +86,7 @@ table! { id -> Int4, creator_id -> Int4, comment_id -> Int4, - comment_text -> Text, + original_comment_text -> Text, reason -> Text, resolved -> Bool, resolver_id -> Nullable, @@ -389,9 +389,9 @@ table! { id -> Int4, creator_id -> Int4, post_id -> Int4, - post_name -> Varchar, - post_url -> Nullable, - post_body -> Nullable, + original_post_name -> Varchar, + original_post_url -> Nullable, + original_post_body -> Nullable, reason -> Text, resolved -> Bool, resolver_id -> Nullable, diff --git a/lemmy_structs/src/comment.rs b/lemmy_structs/src/comment.rs index 5ca7a532..ed292cae 100644 --- a/lemmy_structs/src/comment.rs +++ b/lemmy_structs/src/comment.rs @@ -1,7 +1,4 @@ -use lemmy_db::{ - comment_view::CommentView, - comment_report::CommentReportView, -}; +use lemmy_db::{comment_report::CommentReportView, comment_view::CommentView}; use serde::{Deserialize, Serialize}; #[derive(Deserialize)] diff --git a/lemmy_structs/src/user.rs b/lemmy_structs/src/user.rs index 03a84ce4..bf4a3628 100644 --- a/lemmy_structs/src/user.rs +++ b/lemmy_structs/src/user.rs @@ -247,6 +247,6 @@ pub struct GetReportCount { #[derive(Serialize, Deserialize, Clone, Debug)] pub struct GetReportCountResponse { pub community: Option, - pub comment_reports: i32, - pub post_reports: i32, + pub comment_reports: i64, + pub post_reports: i64, } diff --git a/lemmy_websocket/src/chat_server.rs b/lemmy_websocket/src/chat_server.rs index 0a524e3d..0be54c33 100644 --- a/lemmy_websocket/src/chat_server.rs +++ b/lemmy_websocket/src/chat_server.rs @@ -260,8 +260,8 @@ impl ChatServer { community_id: CommunityId, websocket_id: Option, ) -> Result<(), LemmyError> - where - Response: Serialize, + where + Response: Serialize, { let res_str = &serialize_websocket_message(op, response)?; if let Some(sessions) = self.mod_rooms.get(&community_id) { diff --git a/lemmy_websocket/src/handlers.rs b/lemmy_websocket/src/handlers.rs index 0b5703ab..d95dfd57 100644 --- a/lemmy_websocket/src/handlers.rs +++ b/lemmy_websocket/src/handlers.rs @@ -121,8 +121,8 @@ where } impl Handler> for ChatServer - where - Response: Serialize, +where + Response: Serialize, { type Result = (); diff --git a/migrations/2020-10-13-212240_create_report_tables/up.sql b/migrations/2020-10-13-212240_create_report_tables/up.sql index c0547d08..e9dce1ad 100644 --- a/migrations/2020-10-13-212240_create_report_tables/up.sql +++ b/migrations/2020-10-13-212240_create_report_tables/up.sql @@ -2,7 +2,7 @@ create table comment_report ( id serial primary key, creator_id int references user_ on update cascade on delete cascade not null, -- user reporting comment comment_id int references comment on update cascade on delete cascade not null, -- comment being reported - comment_text text not null, + original_comment_text text not null, reason text not null, resolved bool not null default false, resolver_id int references user_ on update cascade on delete cascade, -- user resolving report @@ -15,9 +15,9 @@ create table post_report ( id serial primary key, creator_id int references user_ on update cascade on delete cascade not null, -- user reporting post post_id int references post on update cascade on delete cascade not null, -- post being reported - post_name varchar(100) not null, - post_url text, - post_body text, + original_post_name varchar(100) not null, + original_post_url text, + original_post_body text, reason text not null, resolved bool not null default false, resolver_id int references user_ on update cascade on delete cascade, -- user resolving report @@ -54,7 +54,7 @@ from comment_report cr left join comment c on c.id = cr.comment_id left join post p on p.id = c.post_id left join user_ u on u.id = c.creator_id -left join user_ f on f.id = cr.creator_id; +left join user_ f on f.id = cr.creator_id left join user_ r on r.id = cr.resolver_id; create or replace view post_report_view as @@ -63,7 +63,6 @@ p.name as current_post_name, p.url as current_post_url, p.body as current_post_body, p.community_id, -f.name as creator_name, -- report creator details f.actor_id as creator_actor_id, f.name as creator_name, @@ -86,5 +85,5 @@ r.local as resolver_local from post_report pr left join post p on p.id = pr.post_id left join user_ u on u.id = p.creator_id -left join user_ f on f.id = pr.creator_id; +left join user_ f on f.id = pr.creator_id left join user_ r on r.id = pr.resolver_id; diff --git a/src/routes/api.rs b/src/routes/api.rs index 7b95b4ee..167797d7 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -82,8 +82,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("/save", web::put().to(route_post::)) .route("/join", web::post().to(route_post::)) .route("/report", web::post().to(route_post::)) - .route("/report/resolve", web::put().to(route_post::)) - .route("/report/list", web::get().to(route_get::)) + .route( + "/report/resolve", + web::put().to(route_post::), + ) + .route("/report/list", web::get().to(route_get::)), ) // Comment .service( @@ -101,8 +104,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("/save", web::put().to(route_post::)) .route("/list", web::get().to(route_get::)) .route("/report", web::post().to(route_post::)) - .route("/report/resolve", web::put().to(route_post::)) - .route("/report/list", web::get().to(route_get::)) + .route( + "/report/resolve", + web::put().to(route_post::), + ) + .route( + "/report/list", + web::get().to(route_get::), + ), ) // Private Message .service( @@ -171,10 +180,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { "/save_user_settings", web::put().to(route_post::), ) - .route( - "/report_count", - web::get().to(route_get::) - ), + .route("/report_count", web::get().to(route_get::)), ) // Admin Actions .service( -- 2.44.1