]> Untitled Git - lemmy.git/blobdiff - crates/db_views/src/post_view.rs
Adding temporary bans. Fixes #1423 (#1999)
[lemmy.git] / crates / db_views / src / post_view.rs
index dc55e6ece4f6170145ea8b590c03e5e35f84ef3f..14138374a146f837f623eb5ed11214c4df54c086 100644 (file)
@@ -1,16 +1,10 @@
-use diesel::{pg::Pg, result::Error, *};
-use lemmy_db_queries::{
+use diesel::{dsl::*, pg::Pg, result::Error, *};
+use lemmy_db_schema::{
   aggregates::post_aggregates::PostAggregates,
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-  ViewToVec,
-};
-use lemmy_db_schema::{
+  newtypes::{CommunityId, DbUrl, PersonId, PostId},
   schema::{
     community,
     community_block,
@@ -30,15 +24,14 @@ use lemmy_db_schema::{
     person_block::PersonBlock,
     post::{Post, PostRead, PostSaved},
   },
-  CommunityId,
-  DbUrl,
-  PersonId,
-  PostId,
+  traits::{MaybeOptional, ToSafe, ViewToVec},
+  ListingType,
+  SortType,
 };
-use log::debug;
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
+use tracing::debug;
 
-#[derive(Debug, PartialEq, Serialize, Clone)]
+#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
 pub struct PostView {
   pub post: Post,
   pub creator: PersonSafe,
@@ -93,7 +86,12 @@ impl PostView {
         community_person_ban::table.on(
           post::community_id
             .eq(community_person_ban::community_id)
-            .and(community_person_ban::person_id.eq(post::creator_id)),
+            .and(community_person_ban::person_id.eq(post::creator_id))
+            .and(
+              community_person_ban::expires
+                .is_null()
+                .or(community_person_ban::expires.gt(now)),
+            ),
         ),
       )
       .inner_join(post_aggregates::table)
@@ -291,7 +289,12 @@ impl<'a> PostQueryBuilder<'a> {
         community_person_ban::table.on(
           post::community_id
             .eq(community_person_ban::community_id)
-            .and(community_person_ban::person_id.eq(post::creator_id)),
+            .and(community_person_ban::person_id.eq(post::creator_id))
+            .and(
+              community_person_ban::expires
+                .is_null()
+                .or(community_person_ban::expires.gt(now)),
+            ),
         ),
       )
       .inner_join(post_aggregates::table)
@@ -487,22 +490,20 @@ impl ViewToVec for PostView {
 #[cfg(test)]
 mod tests {
   use crate::post_view::{PostQueryBuilder, PostView};
-  use lemmy_db_queries::{
+  use lemmy_db_schema::{
     aggregates::post_aggregates::PostAggregates,
     establish_unpooled_connection,
-    Blockable,
-    Crud,
-    Likeable,
+    source::{
+      community::*,
+      community_block::{CommunityBlock, CommunityBlockForm},
+      person::*,
+      person_block::{PersonBlock, PersonBlockForm},
+      post::*,
+    },
+    traits::{Blockable, Crud, Likeable},
     ListingType,
     SortType,
   };
-  use lemmy_db_schema::source::{
-    community::*,
-    community_block::{CommunityBlock, CommunityBlockForm},
-    person::*,
-    person_block::{PersonBlock, PersonBlockForm},
-    post::*,
-  };
   use serial_test::serial;
 
   #[test]
@@ -662,6 +663,7 @@ mod tests {
         inbox_url: inserted_person.inbox_url.to_owned(),
         shared_inbox_url: None,
         matrix_user_id: None,
+        ban_expires: None,
       },
       creator_banned_from_community: false,
       community: CommunitySafe {