From: eiknat Date: Tue, 3 Nov 2020 03:06:20 +0000 (-0500) Subject: add more details to the report views X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/sneer-club-logo.svg?a=commitdiff_plain;h=438414a64b29bf271fccdb757ab9bc19acac4bc1;p=lemmy.git add more details to the report views --- diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index 2b0ee054..083cb841 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 ae19c5f8..35ed4aa9 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 0abb879c..b703c2ef 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 a5ac701c..83f43240 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 cf578c4c..d7f59d03 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 234b0e4d..61c32c0e 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 840d3d99..c0547d08 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;