From 438414a64b29bf271fccdb757ab9bc19acac4bc1 Mon Sep 17 00:00:00 2001 From: eiknat Date: Mon, 2 Nov 2020 22:06:20 -0500 Subject: [PATCH] add more details to the report views --- lemmy_api/src/comment.rs | 2 +- lemmy_api/src/community.rs | 1 - lemmy_api/src/post.rs | 2 +- lemmy_db/src/comment_report.rs | 33 ++++++++++++++-- lemmy_db/src/lib.rs | 4 +- lemmy_db/src/post_report.rs | 33 ++++++++++++++-- .../up.sql | 39 ++++++++++++++++++- 7 files changed, 101 insertions(+), 13 deletions(-) diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index 2b0ee0544..083cb8410 100644 --- a/lemmy_api/src/comment.rs +++ b/lemmy_api/src/comment.rs @@ -775,7 +775,7 @@ impl Perform for ResolveCommentReport { if resolved { CommentReport::resolve(conn, report_id.clone(), user_id) } else { - CommentReport::unresolve(conn, report_id.clone()) + CommentReport::unresolve(conn, report_id.clone(), user_id) } }; diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index ae19c5f8f..35ed4aa9c 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -885,7 +885,6 @@ impl Perform for CommunityJoin { } } -// is this the right place for this? #[async_trait::async_trait(?Send)] impl Perform for ModJoin { type Response = ModJoinResponse; diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index 0abb879cf..b703c2ef8 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -841,7 +841,7 @@ impl Perform for ResolvePostReport { if resolved { PostReport::resolve(conn, report_id.clone(), user_id) } else { - PostReport::unresolve(conn, report_id.clone()) + PostReport::unresolve(conn, report_id.clone(), user_id) } }; diff --git a/lemmy_db/src/comment_report.rs b/lemmy_db/src/comment_report.rs index a5ac701c1..83f432407 100644 --- a/lemmy_db/src/comment_report.rs +++ b/lemmy_db/src/comment_report.rs @@ -17,9 +17,22 @@ table! { post_id -> Int4, current_comment_text -> Text, community_id -> Int4, + creator_actor_id -> Text, creator_name -> Varchar, + creator_preferred_username -> Nullable, + creator_avatar -> Nullable, + creator_local -> Bool, comment_creator_id -> Int4, + comment_creator_actor_id -> Text, comment_creator_name -> Varchar, + comment_creator_preferred_username -> Nullable, + comment_creator_avatar -> Nullable, + comment_creator_local -> Bool, + resolver_actor_id -> Nullable, + resolver_name -> Nullable, + resolver_preferred_username -> Nullable, + resolver_avatar -> Nullable, + resolver_local -> Nullable, } } @@ -55,22 +68,23 @@ impl Reportable for CommentReport { .get_result::(conn) } - fn resolve(conn: &PgConnection, report_id: i32, by_user_id: i32) -> Result { + fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::comment_report::dsl::*; update(comment_report.find(report_id)) .set(( resolved.eq(true), - resolver_id.eq(by_user_id), + resolver_id.eq(by_resolver_id), updated.eq(naive_now()), )) .execute(conn) } - fn unresolve(conn: &PgConnection, report_id: i32) -> Result { + fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::comment_report::dsl::*; update(comment_report.find(report_id)) .set(( resolved.eq(false), + resolver_id.eq(by_resolver_id), updated.eq(naive_now()), )) .execute(conn) @@ -94,9 +108,22 @@ pub struct CommentReportView { pub post_id: i32, pub current_comment_text: String, pub community_id: i32, + pub creator_actor_id: String, pub creator_name: String, + pub creator_preferred_username: Option, + pub creator_avatar: Option, + pub creator_local: bool, pub comment_creator_id: i32, + pub comment_creator_actor_id: String, pub comment_creator_name: String, + pub comment_creator_preferred_username: Option, + pub comment_creator_avatar: Option, + pub comment_creator_local: bool, + pub resolver_actor_id: Option, + pub resolver_name: Option, + pub resolver_preferred_username: Option, + pub resolver_avatar: Option, + pub resolver_local: Option, } pub struct CommentReportQueryBuilder<'a> { diff --git a/lemmy_db/src/lib.rs b/lemmy_db/src/lib.rs index cf578c4cb..d7f59d03f 100644 --- a/lemmy_db/src/lib.rs +++ b/lemmy_db/src/lib.rs @@ -115,10 +115,10 @@ pub trait Reportable { fn report(conn: &PgConnection, form: &T) -> Result where Self: Sized; - fn resolve(conn: &PgConnection, report_id: i32, user_id: i32) -> Result + fn resolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result where Self: Sized; - fn unresolve(conn: &PgConnection, report_id: i32) -> Result + fn unresolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result where Self: Sized; } diff --git a/lemmy_db/src/post_report.rs b/lemmy_db/src/post_report.rs index 234b0e4db..61c32c0e2 100644 --- a/lemmy_db/src/post_report.rs +++ b/lemmy_db/src/post_report.rs @@ -20,9 +20,22 @@ table! { current_post_url -> Nullable, current_post_body -> Nullable, community_id -> Int4, + creator_actor_id -> Text, creator_name -> Varchar, + creator_preferred_username -> Nullable, + creator_avatar -> Nullable, + creator_local -> Bool, post_creator_id -> Int4, + post_creator_actor_id -> Text, post_creator_name -> Varchar, + post_creator_preferred_username -> Nullable, + post_creator_avatar -> Nullable, + post_creator_local -> Bool, + resolver_actor_id -> Nullable, + resolver_name -> Nullable, + resolver_preferred_username -> Nullable, + resolver_avatar -> Nullable, + resolver_local -> Nullable, } } @@ -62,22 +75,23 @@ impl Reportable for PostReport { .get_result::(conn) } - fn resolve(conn: &PgConnection, report_id: i32, by_user_id: i32) -> Result { + fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::post_report::dsl::*; update(post_report.find(report_id)) .set(( resolved.eq(true), - resolver_id.eq(by_user_id), + resolver_id.eq(by_resolver_id), updated.eq(naive_now()), )) .execute(conn) } - fn unresolve(conn: &PgConnection, report_id: i32) -> Result { + fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result { use crate::schema::post_report::dsl::*; update(post_report.find(report_id)) .set(( resolved.eq(false), + resolver_id.eq(by_resolver_id), updated.eq(naive_now()), )) .execute(conn) @@ -104,9 +118,22 @@ pub struct PostReportView { pub current_post_url: Option, pub current_post_body: Option, pub community_id: i32, + pub creator_actor_id: String, pub creator_name: String, + pub creator_preferred_username: Option, + pub creator_avatar: Option, + pub creator_local: bool, pub post_creator_id: i32, + pub post_creator_actor_id: String, pub post_creator_name: String, + pub post_creator_preferred_username: Option, + pub post_creator_avatar: Option, + pub post_creator_local: bool, + pub resolver_actor_id: Option, + pub resolver_name: Option, + pub resolver_preferred_username: Option, + pub resolver_avatar: Option, + pub resolver_local: Option, } impl PostReportView { 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 840d3d99a..c0547d084 100644 --- a/migrations/2020-10-13-212240_create_report_tables/up.sql +++ b/migrations/2020-10-13-212240_create_report_tables/up.sql @@ -31,14 +31,31 @@ select cr.*, c.post_id, c.content as current_comment_text, p.community_id, +-- report creator details +f.actor_id as creator_actor_id, f.name as creator_name, +f.preferred_username as creator_preferred_username, +f.avatar as creator_avatar, +f.local as creator_local, +-- comment creator details u.id as comment_creator_id, -u.name as comment_creator_name +u.actor_id as comment_creator_actor_id, +u.name as comment_creator_name, +u.preferred_username as comment_creator_preferred_username, +u.avatar as comment_creator_avatar, +u.local as comment_creator_local, +-- resolver details +r.actor_id as resolver_actor_id, +r.name as resolver_name, +r.preferred_username as resolver_preferred_username, +r.avatar as resolver_avatar, +r.local as resolver_local 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_ r on r.id = cr.resolver_id; create or replace view post_report_view as select pr.*, @@ -47,9 +64,27 @@ 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, +f.preferred_username as creator_preferred_username, +f.avatar as creator_avatar, +f.local as creator_local, +-- post creator details u.id as post_creator_id, -u.name as post_creator_name +u.actor_id as post_creator_actor_id, +u.name as post_creator_name, +u.preferred_username as post_creator_preferred_username, +u.avatar as post_creator_avatar, +u.local as post_creator_local, +-- resolver details +r.actor_id as resolver_actor_id, +r.name as resolver_name, +r.preferred_username as resolver_preferred_username, +r.avatar as resolver_avatar, +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_ r on r.id = pr.resolver_id;