mirror of https://github.com/LemmyNet/lemmy.git
* Fixing removed posts showing. Fixes #2875 * Fixing clippy.revert-3249-readd-captcha
parent
39572e1c3e
commit
dce79b83bf
|
@ -147,10 +147,12 @@ impl PostView {
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
if !is_mod_or_admin.unwrap_or(true) {
|
if !is_mod_or_admin.unwrap_or(false) {
|
||||||
query = query
|
query = query
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.filter(community::deleted.eq(false));
|
.filter(community::deleted.eq(false))
|
||||||
|
.filter(post::removed.eq(false))
|
||||||
|
.filter(post::deleted.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (
|
let (
|
||||||
|
@ -305,10 +307,12 @@ impl<'a> PostQuery<'a> {
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
// TODO This eventually needs to show posts where you are the creator
|
// TODO This eventually needs to show posts where you are the creator
|
||||||
if !self.is_mod_or_admin.unwrap_or(true) {
|
if !self.is_mod_or_admin.unwrap_or(false) {
|
||||||
query = query
|
query = query
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.filter(community::deleted.eq(false));
|
.filter(community::deleted.eq(false))
|
||||||
|
.filter(post::removed.eq(false))
|
||||||
|
.filter(post::deleted.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.community_id.is_none() {
|
if self.community_id.is_none() {
|
||||||
|
@ -475,7 +479,7 @@ mod tests {
|
||||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||||
person::{Person, PersonInsertForm},
|
person::{Person, PersonInsertForm},
|
||||||
person_block::{PersonBlock, PersonBlockForm},
|
person_block::{PersonBlock, PersonBlockForm},
|
||||||
post::{Post, PostInsertForm, PostLike, PostLikeForm},
|
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm},
|
||||||
},
|
},
|
||||||
traits::{Blockable, Crud, Likeable},
|
traits::{Blockable, Crud, Likeable},
|
||||||
utils::{build_db_pool_for_tests, DbPool},
|
utils::{build_db_pool_for_tests, DbPool},
|
||||||
|
@ -870,6 +874,50 @@ mod tests {
|
||||||
cleanup(data, pool).await;
|
cleanup(data, pool).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn post_listings_deleted() {
|
||||||
|
let pool = &build_db_pool_for_tests().await;
|
||||||
|
let data = init_data(pool).await;
|
||||||
|
|
||||||
|
// Delete the post
|
||||||
|
Post::update(
|
||||||
|
pool,
|
||||||
|
data.inserted_post.id,
|
||||||
|
&PostUpdateForm::builder().deleted(Some(true)).build(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Make sure you don't see the deleted post in the results
|
||||||
|
let post_listings_no_admin = PostQuery::builder()
|
||||||
|
.pool(pool)
|
||||||
|
.sort(Some(SortType::New))
|
||||||
|
.local_user(Some(&data.inserted_local_user))
|
||||||
|
.is_mod_or_admin(Some(false))
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(1, post_listings_no_admin.len());
|
||||||
|
|
||||||
|
// Make sure they see both
|
||||||
|
let post_listings_is_admin = PostQuery::builder()
|
||||||
|
.pool(pool)
|
||||||
|
.sort(Some(SortType::New))
|
||||||
|
.local_user(Some(&data.inserted_local_user))
|
||||||
|
.is_mod_or_admin(Some(true))
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(2, post_listings_is_admin.len());
|
||||||
|
|
||||||
|
cleanup(data, pool).await;
|
||||||
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, pool: &DbPool) {
|
async fn cleanup(data: Data, pool: &DbPool) {
|
||||||
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
|
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
|
||||||
Community::delete(pool, data.inserted_community.id)
|
Community::delete(pool, data.inserted_community.id)
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl CommunityView {
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
if !is_mod_or_admin.unwrap_or(true) {
|
if !is_mod_or_admin.unwrap_or(false) {
|
||||||
query = query
|
query = query
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.filter(community::deleted.eq(false));
|
.filter(community::deleted.eq(false));
|
||||||
|
@ -170,7 +170,7 @@ impl<'a> CommunityQuery<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
if !self.is_mod_or_admin.unwrap_or(true) {
|
if !self.is_mod_or_admin.unwrap_or(false) {
|
||||||
query = query
|
query = query
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.filter(community::deleted.eq(false))
|
.filter(community::deleted.eq(false))
|
||||||
|
@ -213,8 +213,6 @@ impl<'a> CommunityQuery<'a> {
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.filter(community::removed.eq(false))
|
|
||||||
.filter(community::deleted.eq(false))
|
|
||||||
.load::<CommunityViewTuple>(conn)
|
.load::<CommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue