mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 22:01:19 +00:00
Merge branch 'main' into delete_local_image_on_delete_account
This commit is contained in:
commit
871b3d6267
2 changed files with 79 additions and 6 deletions
|
@ -211,5 +211,6 @@ pub struct CustomEmojiView {
|
||||||
/// A vote view for checking a post or comments votes.
|
/// A vote view for checking a post or comments votes.
|
||||||
pub struct VoteView {
|
pub struct VoteView {
|
||||||
pub creator: Person,
|
pub creator: Person,
|
||||||
|
pub creator_banned_from_community: bool,
|
||||||
pub score: i16,
|
pub score: i16,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
use crate::structs::VoteView;
|
use crate::structs::VoteView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{
|
||||||
|
result::Error,
|
||||||
|
BoolExpressionMethods,
|
||||||
|
ExpressionMethods,
|
||||||
|
JoinOnDsl,
|
||||||
|
NullableExpressionMethods,
|
||||||
|
QueryDsl,
|
||||||
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, PostId},
|
newtypes::{CommentId, PostId},
|
||||||
schema::{comment_like, person, post_like},
|
schema::{comment_like, community_person_ban, person, post, post_like},
|
||||||
utils::{get_conn, limit_and_offset, DbPool},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,8 +26,21 @@ impl VoteView {
|
||||||
|
|
||||||
post_like::table
|
post_like::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
.inner_join(post::table)
|
||||||
|
// Join to community_person_ban to get creator_banned_from_community
|
||||||
|
.left_join(
|
||||||
|
community_person_ban::table.on(
|
||||||
|
post::community_id
|
||||||
|
.eq(community_person_ban::community_id)
|
||||||
|
.and(community_person_ban::person_id.eq(post_like::person_id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
.filter(post_like::post_id.eq(post_id))
|
.filter(post_like::post_id.eq(post_id))
|
||||||
.select((person::all_columns, post_like::score))
|
.select((
|
||||||
|
person::all_columns,
|
||||||
|
community_person_ban::community_id.nullable().is_not_null(),
|
||||||
|
post_like::score,
|
||||||
|
))
|
||||||
.order_by(post_like::score)
|
.order_by(post_like::score)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
|
@ -39,8 +59,21 @@ impl VoteView {
|
||||||
|
|
||||||
comment_like::table
|
comment_like::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
.inner_join(post::table)
|
||||||
|
// Join to community_person_ban to get creator_banned_from_community
|
||||||
|
.left_join(
|
||||||
|
community_person_ban::table.on(
|
||||||
|
post::community_id
|
||||||
|
.eq(community_person_ban::community_id)
|
||||||
|
.and(community_person_ban::person_id.eq(comment_like::person_id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
.filter(comment_like::comment_id.eq(comment_id))
|
.filter(comment_like::comment_id.eq(comment_id))
|
||||||
.select((person::all_columns, comment_like::score))
|
.select((
|
||||||
|
person::all_columns,
|
||||||
|
community_person_ban::community_id.nullable().is_not_null(),
|
||||||
|
comment_like::score,
|
||||||
|
))
|
||||||
.order_by(comment_like::score)
|
.order_by(comment_like::score)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
|
@ -58,12 +91,12 @@ mod tests {
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentInsertForm, CommentLike, CommentLikeForm},
|
||||||
community::{Community, CommunityInsertForm},
|
community::{Community, CommunityInsertForm, CommunityPersonBan, CommunityPersonBanForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
person::{Person, PersonInsertForm},
|
person::{Person, PersonInsertForm},
|
||||||
post::{Post, PostInsertForm, PostLike, PostLikeForm},
|
post::{Post, PostInsertForm, PostLike, PostLikeForm},
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable},
|
traits::{Bannable, Crud, Likeable},
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
@ -139,10 +172,12 @@ mod tests {
|
||||||
let expected_post_vote_views = [
|
let expected_post_vote_views = [
|
||||||
VoteView {
|
VoteView {
|
||||||
creator: inserted_sara.clone(),
|
creator: inserted_sara.clone(),
|
||||||
|
creator_banned_from_community: false,
|
||||||
score: -1,
|
score: -1,
|
||||||
},
|
},
|
||||||
VoteView {
|
VoteView {
|
||||||
creator: inserted_timmy.clone(),
|
creator: inserted_timmy.clone(),
|
||||||
|
creator_banned_from_community: false,
|
||||||
score: 1,
|
score: 1,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -177,10 +212,12 @@ mod tests {
|
||||||
let expected_comment_vote_views = [
|
let expected_comment_vote_views = [
|
||||||
VoteView {
|
VoteView {
|
||||||
creator: inserted_timmy.clone(),
|
creator: inserted_timmy.clone(),
|
||||||
|
creator_banned_from_community: false,
|
||||||
score: -1,
|
score: -1,
|
||||||
},
|
},
|
||||||
VoteView {
|
VoteView {
|
||||||
creator: inserted_sara.clone(),
|
creator: inserted_sara.clone(),
|
||||||
|
creator_banned_from_community: false,
|
||||||
score: 1,
|
score: 1,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -190,6 +227,41 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(read_comment_vote_views, expected_comment_vote_views);
|
assert_eq!(read_comment_vote_views, expected_comment_vote_views);
|
||||||
|
|
||||||
|
// Ban timmy from that community
|
||||||
|
let ban_timmy_form = CommunityPersonBanForm {
|
||||||
|
community_id: inserted_community.id,
|
||||||
|
person_id: inserted_timmy.id,
|
||||||
|
expires: None,
|
||||||
|
};
|
||||||
|
CommunityPersonBan::ban(pool, &ban_timmy_form)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Make sure creator_banned_from_community is true
|
||||||
|
let read_comment_vote_views_after_ban =
|
||||||
|
VoteView::list_for_comment(pool, inserted_comment.id, None, None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
read_comment_vote_views_after_ban
|
||||||
|
.first()
|
||||||
|
.unwrap()
|
||||||
|
.creator_banned_from_community
|
||||||
|
);
|
||||||
|
|
||||||
|
let read_post_vote_views_after_ban =
|
||||||
|
VoteView::list_for_post(pool, inserted_post.id, None, None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
read_post_vote_views_after_ban
|
||||||
|
.get(1)
|
||||||
|
.unwrap()
|
||||||
|
.creator_banned_from_community
|
||||||
|
);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue