]> Untitled Git - lemmy.git/commitdiff
Fixing removed posts showing. Fixes #2875 (#3279)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 23 Jun 2023 10:53:46 +0000 (06:53 -0400)
committerGitHub <noreply@github.com>
Fri, 23 Jun 2023 10:53:46 +0000 (12:53 +0200)
* Fixing removed posts showing. Fixes #2875

* Fixing clippy.

crates/db_views/src/post_view.rs
crates/db_views_actor/src/community_view.rs

index 79cc875cc940fc9f750d7a09ba1d0fd14e74d29d..14cf7fe1976e3832b2515d60839de9708997d339 100644 (file)
@@ -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)
index ee6066c22d95a836b82c7d84ef5cffdaa0c971db..c4f5920b78122dd7b71941e984470315fb9f3461 100644 (file)
@@ -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::<CommunityViewTuple>(conn)
       .await?;