Adding extra fields to PostReport and CommentReport views. (#4520)

- Fixes #4200
This commit is contained in:
Dessalines 2024-03-13 12:11:24 -04:00 committed by GitHub
parent 15f02f00a9
commit 255e695633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 162 additions and 1 deletions

View file

@ -18,10 +18,14 @@ use lemmy_db_schema::{
comment_aggregates, comment_aggregates,
comment_like, comment_like,
comment_report, comment_report,
comment_saved,
community, community,
community_follower,
community_moderator, community_moderator,
community_person_ban, community_person_ban,
local_user,
person, person,
person_block,
post, post,
}, },
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
@ -64,6 +68,45 @@ fn queries<'a>() -> Queries<
), ),
), ),
) )
.left_join(
aliases::community_moderator1.on(
community::id
.eq(aliases::community_moderator1.field(community_moderator::community_id))
.and(
aliases::community_moderator1
.field(community_moderator::person_id)
.eq(comment::creator_id),
),
),
)
.left_join(
local_user::table.on(
comment::creator_id
.eq(local_user::person_id)
.and(local_user::admin.eq(true)),
),
)
.left_join(
person_block::table.on(
comment::creator_id
.eq(person_block::target_id)
.and(person_block::person_id.eq(my_person_id)),
),
)
.left_join(
community_follower::table.on(
post::community_id
.eq(community_follower::community_id)
.and(community_follower::person_id.eq(my_person_id)),
),
)
.left_join(
comment_saved::table.on(
comment::id
.eq(comment_saved::comment_id)
.and(comment_saved::person_id.eq(my_person_id)),
),
)
.select(( .select((
comment_report::all_columns, comment_report::all_columns,
comment::all_columns, comment::all_columns,
@ -73,6 +116,14 @@ fn queries<'a>() -> Queries<
aliases::person1.fields(person::all_columns), aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns, comment_aggregates::all_columns,
community_person_ban::community_id.nullable().is_not_null(), community_person_ban::community_id.nullable().is_not_null(),
aliases::community_moderator1
.field(community_moderator::community_id)
.nullable()
.is_not_null(),
local_user::admin.nullable().is_not_null(),
person_block::target_id.nullable().is_not_null(),
community_follower::pending.nullable(),
comment_saved::published.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(), aliases::person2.fields(person::all_columns).nullable(),
)) ))
@ -230,6 +281,7 @@ mod tests {
traits::{Crud, Joinable, Reportable}, traits::{Crud, Joinable, Reportable},
utils::{build_db_pool_for_tests, RANK_DEFAULT}, utils::{build_db_pool_for_tests, RANK_DEFAULT},
CommunityVisibility, CommunityVisibility,
SubscribedType,
}; };
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use serial_test::serial; use serial_test::serial;
@ -352,6 +404,11 @@ mod tests {
comment_report: inserted_jessica_report.clone(), comment_report: inserted_jessica_report.clone(),
comment: inserted_comment.clone(), comment: inserted_comment.clone(),
post: inserted_post, post: inserted_post,
creator_is_moderator: true,
creator_is_admin: false,
creator_blocked: false,
subscribed: SubscribedType::NotSubscribed,
saved: false,
community: Community { community: Community {
id: inserted_community.id, id: inserted_community.id,
name: inserted_community.name, name: inserted_community.name,

View file

@ -14,15 +14,31 @@ use lemmy_db_schema::{
newtypes::{CommunityId, PersonId, PostId, PostReportId}, newtypes::{CommunityId, PersonId, PostId, PostReportId},
schema::{ schema::{
community, community,
community_follower,
community_moderator, community_moderator,
community_person_ban, community_person_ban,
local_user,
person, person,
person_block,
person_post_aggregates,
post, post,
post_aggregates, post_aggregates,
post_hide,
post_like, post_like,
post_read,
post_report, post_report,
post_saved,
},
utils::{
functions::coalesce,
get_conn,
limit_and_offset,
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
}, },
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
@ -42,6 +58,67 @@ fn queries<'a>() -> Queries<
.and(community_person_ban::person_id.eq(post::creator_id)), .and(community_person_ban::person_id.eq(post::creator_id)),
), ),
) )
.left_join(
aliases::community_moderator1.on(
aliases::community_moderator1
.field(community_moderator::community_id)
.eq(post::community_id)
.and(
aliases::community_moderator1
.field(community_moderator::person_id)
.eq(my_person_id),
),
),
)
.left_join(
local_user::table.on(
post::creator_id
.eq(local_user::person_id)
.and(local_user::admin.eq(true)),
),
)
.left_join(
post_saved::table.on(
post::id
.eq(post_saved::post_id)
.and(post_saved::person_id.eq(my_person_id)),
),
)
.left_join(
post_read::table.on(
post::id
.eq(post_read::post_id)
.and(post_read::person_id.eq(my_person_id)),
),
)
.left_join(
post_hide::table.on(
post::id
.eq(post_hide::post_id)
.and(post_hide::person_id.eq(my_person_id)),
),
)
.left_join(
person_block::table.on(
post::creator_id
.eq(person_block::target_id)
.and(person_block::person_id.eq(my_person_id)),
),
)
.left_join(
person_post_aggregates::table.on(
post::id
.eq(person_post_aggregates::post_id)
.and(person_post_aggregates::person_id.eq(my_person_id)),
),
)
.left_join(
community_follower::table.on(
post::community_id
.eq(community_follower::community_id)
.and(community_follower::person_id.eq(my_person_id)),
),
)
.left_join( .left_join(
post_like::table.on( post_like::table.on(
post::id post::id
@ -61,7 +138,21 @@ fn queries<'a>() -> Queries<
person::all_columns, person::all_columns,
aliases::person1.fields(person::all_columns), aliases::person1.fields(person::all_columns),
community_person_ban::community_id.nullable().is_not_null(), community_person_ban::community_id.nullable().is_not_null(),
aliases::community_moderator1
.field(community_moderator::community_id)
.nullable()
.is_not_null(),
local_user::admin.nullable().is_not_null(),
community_follower::pending.nullable(),
post_saved::post_id.nullable().is_not_null(),
post_read::post_id.nullable().is_not_null(),
post_hide::post_id.nullable().is_not_null(),
person_block::target_id.nullable().is_not_null(),
post_like::score.nullable(), post_like::score.nullable(),
coalesce(
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
post_aggregates::comments,
),
post_aggregates::all_columns, post_aggregates::all_columns,
aliases::person2.fields(person::all_columns.nullable()), aliases::person2.fields(person::all_columns.nullable()),
)) ))

View file

@ -42,6 +42,11 @@ pub struct CommentReportView {
pub comment_creator: Person, pub comment_creator: Person,
pub counts: CommentAggregates, pub counts: CommentAggregates,
pub creator_banned_from_community: bool, pub creator_banned_from_community: bool,
pub creator_is_moderator: bool,
pub creator_is_admin: bool,
pub creator_blocked: bool,
pub subscribed: SubscribedType,
pub saved: bool,
pub my_vote: Option<i16>, pub my_vote: Option<i16>,
pub resolver: Option<Person>, pub resolver: Option<Person>,
} }
@ -92,7 +97,15 @@ pub struct PostReportView {
pub creator: Person, pub creator: Person,
pub post_creator: Person, pub post_creator: Person,
pub creator_banned_from_community: bool, pub creator_banned_from_community: bool,
pub creator_is_moderator: bool,
pub creator_is_admin: bool,
pub subscribed: SubscribedType,
pub saved: bool,
pub read: bool,
pub hidden: bool,
pub creator_blocked: bool,
pub my_vote: Option<i16>, pub my_vote: Option<i16>,
pub unread_comments: i64,
pub counts: PostAggregates, pub counts: PostAggregates,
pub resolver: Option<Person>, pub resolver: Option<Person>,
} }