summaryrefslogtreecommitdiffstats
path: root/server/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/db')
-rw-r--r--server/src/db/comment.rs9
-rw-r--r--server/src/db/comment_view.rs9
-rw-r--r--server/src/db/community.rs7
-rw-r--r--server/src/db/community_view.rs22
-rw-r--r--server/src/db/moderator.rs12
-rw-r--r--server/src/db/post.rs10
-rw-r--r--server/src/db/post_view.rs49
-rw-r--r--server/src/db/user.rs14
8 files changed, 94 insertions, 38 deletions
diff --git a/server/src/db/comment.rs b/server/src/db/comment.rs
index d125124c..ce0b5a63 100644
--- a/server/src/db/comment.rs
+++ b/server/src/db/comment.rs
@@ -170,7 +170,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -183,7 +184,8 @@ mod tests {
creator_id: inserted_user.id,
removed: None,
deleted: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -197,7 +199,8 @@ mod tests {
removed: None,
deleted: None,
locked: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
diff --git a/server/src/db/comment_view.rs b/server/src/db/comment_view.rs
index 53517db9..8a6545ba 100644
--- a/server/src/db/comment_view.rs
+++ b/server/src/db/comment_view.rs
@@ -261,7 +261,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -274,7 +275,8 @@ mod tests {
creator_id: inserted_user.id,
removed: None,
deleted: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -288,7 +290,8 @@ mod tests {
removed: None,
deleted: None,
locked: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
diff --git a/server/src/db/community.rs b/server/src/db/community.rs
index b32230b9..dd6ea94b 100644
--- a/server/src/db/community.rs
+++ b/server/src/db/community.rs
@@ -14,6 +14,7 @@ pub struct Community {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
@@ -27,6 +28,7 @@ pub struct CommunityForm {
pub removed: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
+ pub nsfw: bool,
}
impl Crud<CommunityForm> for Community {
@@ -229,7 +231,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -240,6 +243,7 @@ mod tests {
title: "nada".to_owned(),
description: None,
category_id: 1,
+ nsfw: false,
removed: None,
deleted: None,
updated: None,
@@ -254,6 +258,7 @@ mod tests {
title: "nada".to_owned(),
description: None,
category_id: 1,
+ nsfw: false,
removed: false,
deleted: false,
published: inserted_community.published,
diff --git a/server/src/db/community_view.rs b/server/src/db/community_view.rs
index 6249090d..88ab10af 100644
--- a/server/src/db/community_view.rs
+++ b/server/src/db/community_view.rs
@@ -12,6 +12,7 @@ table! {
published -> Timestamp,
updated -> Nullable<Timestamp>,
deleted -> Bool,
+ nsfw -> Bool,
creator_name -> Varchar,
category_name -> Varchar,
number_of_subscribers -> BigInt,
@@ -84,6 +85,7 @@ pub struct CommunityView {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
pub creator_name: String,
pub category_name: String,
pub number_of_subscribers: i64,
@@ -112,13 +114,15 @@ impl CommunityView {
query.first::<Self>(conn)
}
- pub fn list(conn: &PgConnection,
- sort: &SortType,
- from_user_id: Option<i32>,
- search_term: Option<String>,
- page: Option<i64>,
- limit: Option<i64>,
- ) -> Result<Vec<Self>, Error> {
+ pub fn list(
+ conn: &PgConnection,
+ sort: &SortType,
+ from_user_id: Option<i32>,
+ show_nsfw: bool,
+ search_term: Option<String>,
+ page: Option<i64>,
+ limit: Option<i64>,
+ ) -> Result<Vec<Self>, Error> {
use super::community_view::community_view::dsl::*;
let mut query = community_view.into_boxed();
@@ -143,6 +147,10 @@ impl CommunityView {
_ => ()
};
+ if !show_nsfw {
+ query = query.filter(nsfw.eq(false));
+ };
+
query
.limit(limit)
.offset(offset)
diff --git a/server/src/db/moderator.rs b/server/src/db/moderator.rs
index 56cf2f47..fec46aa1 100644
--- a/server/src/db/moderator.rs
+++ b/server/src/db/moderator.rs
@@ -412,7 +412,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_mod = User_::create(&conn, &new_mod).unwrap();
@@ -425,7 +426,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -438,7 +440,8 @@ mod tests {
creator_id: inserted_user.id,
removed: None,
deleted: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -452,7 +455,8 @@ mod tests {
removed: None,
deleted: None,
locked: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
diff --git a/server/src/db/post.rs b/server/src/db/post.rs
index d8fd27b0..12ea1081 100644
--- a/server/src/db/post.rs
+++ b/server/src/db/post.rs
@@ -15,6 +15,7 @@ pub struct Post {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone)]
@@ -29,6 +30,7 @@ pub struct PostForm {
pub locked: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
+ pub nsfw: bool,
}
impl Crud<PostForm> for Post {
@@ -183,7 +185,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -196,7 +199,8 @@ mod tests {
creator_id: inserted_user.id,
removed: None,
deleted: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -210,6 +214,7 @@ mod tests {
removed: None,
deleted: None,
locked: None,
+ nsfw: false,
updated: None
};
@@ -225,6 +230,7 @@ mod tests {
published: inserted_post.published,
removed: false,
locked: false,
+ nsfw: false,
deleted: false,
updated: None
};
diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs
index bec00b98..c7e6eea3 100644
--- a/server/src/db/post_view.rs
+++ b/server/src/db/post_view.rs
@@ -19,10 +19,12 @@ table! {
published -> Timestamp,
updated -> Nullable<Timestamp>,
deleted -> Bool,
+ nsfw -> Bool,
creator_name -> Varchar,
community_name -> Varchar,
community_removed -> Bool,
community_deleted -> Bool,
+ community_nsfw -> Bool,
number_of_comments -> BigInt,
score -> BigInt,
upvotes -> BigInt,
@@ -51,10 +53,12 @@ pub struct PostView {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
pub creator_name: String,
pub community_name: String,
pub community_removed: bool,
pub community_deleted: bool,
+ pub community_nsfw: bool,
pub number_of_comments: i64,
pub score: i64,
pub upvotes: i64,
@@ -68,18 +72,20 @@ pub struct PostView {
}
impl PostView {
- pub fn list(conn: &PgConnection,
- type_: PostListingType,
- sort: &SortType,
- for_community_id: Option<i32>,
- for_creator_id: Option<i32>,
- search_term: Option<String>,
- my_user_id: Option<i32>,
- saved_only: bool,
- unread_only: bool,
- page: Option<i64>,
- limit: Option<i64>,
- ) -> Result<Vec<Self>, Error> {
+ pub fn list(
+ conn: &PgConnection,
+ type_: PostListingType,
+ sort: &SortType,
+ for_community_id: Option<i32>,
+ for_creator_id: Option<i32>,
+ search_term: Option<String>,
+ my_user_id: Option<i32>,
+ show_nsfw: bool,
+ saved_only: bool,
+ unread_only: bool,
+ page: Option<i64>,
+ limit: Option<i64>,
+ ) -> Result<Vec<Self>, Error> {
use super::post_view::post_view::dsl::*;
let (limit, offset) = limit_and_offset(page, limit);
@@ -121,6 +127,12 @@ impl PostView {
query = query.filter(user_id.is_null());
}
+ if !show_nsfw {
+ query = query
+ .filter(nsfw.eq(false))
+ .filter(community_nsfw.eq(false));
+ };
+
query = match sort {
SortType::Hot => query.order_by(hot_rank.desc())
.then_order_by(published.desc()),
@@ -196,6 +208,7 @@ mod tests {
updated: None,
admin: false,
banned: false,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -208,7 +221,8 @@ mod tests {
category_id: 1,
removed: None,
deleted: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -222,7 +236,8 @@ mod tests {
removed: None,
deleted: None,
locked: None,
- updated: None
+ updated: None,
+ nsfw: false,
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
@@ -266,6 +281,7 @@ mod tests {
community_name: community_name.to_owned(),
community_removed: false,
community_deleted: false,
+ community_nsfw: false,
number_of_comments: 0,
score: 1,
upvotes: 1,
@@ -276,6 +292,7 @@ mod tests {
subscribed: None,
read: None,
saved: None,
+ nsfw: false,
};
let expected_post_listing_with_user = PostView {
@@ -294,6 +311,7 @@ mod tests {
community_name: community_name.to_owned(),
community_removed: false,
community_deleted: false,
+ community_nsfw: false,
number_of_comments: 0,
score: 1,
upvotes: 1,
@@ -304,6 +322,7 @@ mod tests {
subscribed: None,
read: None,
saved: None,
+ nsfw: false,
};
@@ -313,6 +332,7 @@ mod tests {
None,
None,
Some(inserted_user.id),
+ false,
false,
false,
None,
@@ -324,6 +344,7 @@ mod tests {
None,
None,
None,
+ false,
false,
false,
None,
diff --git a/server/src/db/user.rs b/server/src/db/user.rs
index aed5e890..b794524c 100644
--- a/server/src/db/user.rs
+++ b/server/src/db/user.rs
@@ -18,7 +18,8 @@ pub struct User_ {
pub admin: bool,
pub banned: bool,
pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone)]
@@ -31,7 +32,8 @@ pub struct UserForm {
pub admin: bool,
pub banned: bool,
pub email: Option<String>,
- pub updated: Option<chrono::NaiveDateTime>
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
}
impl Crud<UserForm> for User_ {
@@ -77,6 +79,7 @@ pub struct Claims {
pub id: i32,
pub username: String,
pub iss: String,
+ pub show_nsfw: bool,
}
impl Claims {
@@ -96,6 +99,7 @@ impl User_ {
id: self.id,
username: self.name.to_owned(),
iss: self.fedi_name.to_owned(),
+ show_nsfw: self.show_nsfw,
};
encode(&Header::default(), &my_claims, Settings::get().jwt_secret.as_ref()).unwrap()
}
@@ -133,7 +137,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -149,7 +154,8 @@ mod tests {
admin: false,
banned: false,
published: inserted_user.published,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let read_user = User_::read(&conn, inserted_user.id).unwrap();