From: Dessalines Date: Fri, 23 Jun 2023 10:53:46 +0000 (-0400) Subject: Fixing removed posts showing. Fixes #2875 (#3279) X-Git-Url: http://these/git/%22https:/nerdica.net/%24%7B%60data:application/%7Bthis.captchaPngSrc%28%29%7D?a=commitdiff_plain;h=b6cd1bde8eae74d22c0c3c80ee7990b413d0ab27;p=lemmy.git Fixing removed posts showing. Fixes #2875 (#3279) * Fixing removed posts showing. Fixes #2875 * Fixing clippy. --- diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 79cc875c..14cf7fe1 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -147,10 +147,12 @@ impl PostView { .into_boxed(); // 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 .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 ( @@ -305,10 +307,12 @@ impl<'a> PostQuery<'a> { // Hide deleted and removed for non-admins or mods // 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 .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() { @@ -475,7 +479,7 @@ mod tests { local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, person::{Person, PersonInsertForm}, person_block::{PersonBlock, PersonBlockForm}, - post::{Post, PostInsertForm, PostLike, PostLikeForm}, + post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm}, }, traits::{Blockable, Crud, Likeable}, utils::{build_db_pool_for_tests, DbPool}, @@ -870,6 +874,50 @@ mod tests { 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) { let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap(); Community::delete(pool, data.inserted_community.id) diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index ee6066c2..c4f5920b 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -69,7 +69,7 @@ impl CommunityView { .into_boxed(); // 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 .filter(community::removed.eq(false)) .filter(community::deleted.eq(false)); @@ -170,7 +170,7 @@ impl<'a> CommunityQuery<'a> { }; // 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 .filter(community::removed.eq(false)) .filter(community::deleted.eq(false)) @@ -213,8 +213,6 @@ impl<'a> CommunityQuery<'a> { let res = query .limit(limit) .offset(offset) - .filter(community::removed.eq(false)) - .filter(community::deleted.eq(false)) .load::(conn) .await?;