Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add site.content_warning, local_site.default_post_listing_mode #4393

Merged
merged 24 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use lemmy_db_schema::{
},
ListingType,
ModlogActionType,
PostListingMode,
RegistrationMode,
SearchType,
SortType,
Expand Down Expand Up @@ -187,6 +188,8 @@ pub struct CreateSite {
pub blocked_instances: Option<Vec<String>>,
pub taglines: Option<Vec<String>>,
pub registration_mode: Option<RegistrationMode>,
pub content_warning: Option<String>,
pub default_post_listing_mode: Option<PostListingMode>,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -265,6 +268,11 @@ pub struct EditSite {
pub registration_mode: Option<RegistrationMode>,
/// Whether to email admins for new reports.
pub reports_email_admins: Option<bool>,
/// If present, nsfw content is visible by default. Should be displayed by frontends/clients
/// when the site is first opened by a user.
pub content_warning: Option<String>,
/// Default value for [LocalUser.post_listing_mode]
pub default_post_listing_mode: Option<PostListingMode>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
9 changes: 4 additions & 5 deletions crates/api_crud/src/community/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use lemmy_api_common::{
context::LemmyContext,
utils::{check_private_instance, is_admin},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views::structs::{LocalUserView, SiteView};
use lemmy_db_views_actor::community_view::CommunityQuery;
use lemmy_utils::error::LemmyError;

Expand All @@ -15,13 +14,13 @@ pub async fn list_communities(
context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>,
) -> Result<Json<ListCommunitiesResponse>, LemmyError> {
let local_site = LocalSite::read(&mut context.pool()).await?;
let local_site = SiteView::read_local(&mut context.pool()).await?;
let is_admin = local_user_view
.as_ref()
.map(|luv| is_admin(luv).is_ok())
.unwrap_or_default();

check_private_instance(&local_user_view, &local_site)?;
check_private_instance(&local_user_view, &local_site.local_site)?;

let sort = data.sort;
let listing_type = data.type_;
Expand All @@ -39,7 +38,7 @@ pub async fn list_communities(
is_mod_or_admin: is_admin,
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
dessalines marked this conversation as resolved.
Show resolved Hide resolved
.await?;

// Return the jwt
Expand Down
10 changes: 5 additions & 5 deletions crates/api_crud/src/post/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use lemmy_api_common::{
};
use lemmy_db_schema::{
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
source::{comment::Comment, local_site::LocalSite, post::Post},
source::{comment::Comment, post::Post},
traits::Crud,
};
use lemmy_db_views::{
post_view::PostQuery,
structs::{LocalUserView, PostView},
structs::{LocalUserView, PostView, SiteView},
};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
Expand All @@ -22,9 +22,9 @@ pub async fn get_post(
context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>,
) -> Result<Json<GetPostResponse>, LemmyError> {
let local_site = LocalSite::read(&mut context.pool()).await?;
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&local_user_view, &local_site)?;
check_private_instance(&local_user_view, &local_site.local_site)?;

let person_id = local_user_view.as_ref().map(|u| u.person.id);

Expand Down Expand Up @@ -93,7 +93,7 @@ pub async fn get_post(
url_search: Some(url.inner().as_str().into()),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;

// Don't return this post as one of the cross_posts
Expand Down
4 changes: 4 additions & 0 deletions crates/api_crud/src/site/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub async fn create_site(
inbox_url,
private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_key),
content_warning: diesel_option_overwrite(data.content_warning.clone()),
..Default::default()
};

Expand Down Expand Up @@ -101,6 +102,7 @@ pub async fn create_site(
federation_enabled: data.federation_enabled,
captcha_enabled: data.captcha_enabled,
captcha_difficulty: data.captcha_difficulty.clone(),
default_post_listing_mode: data.default_post_listing_mode,
..Default::default()
};

Expand Down Expand Up @@ -568,6 +570,8 @@ mod tests {
blocked_instances: None,
taglines: None,
registration_mode: site_registration_mode,
content_warning: None,
default_post_listing_mode: None,
}
}
}
4 changes: 4 additions & 0 deletions crates/api_crud/src/site/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub async fn update_site(
description: diesel_option_overwrite(data.description.clone()),
icon,
banner,
content_warning: diesel_option_overwrite(data.content_warning.clone()),
updated: Some(Some(naive_now())),
..Default::default()
};
Expand Down Expand Up @@ -101,6 +102,7 @@ pub async fn update_site(
captcha_enabled: data.captcha_enabled,
captcha_difficulty: data.captcha_difficulty.clone(),
reports_email_admins: data.reports_email_admins,
default_post_listing_mode: data.default_post_listing_mode,
..Default::default()
};

Expand Down Expand Up @@ -566,6 +568,8 @@ mod tests {
taglines: None,
registration_mode: site_registration_mode,
reports_email_admins: None,
content_warning: None,
default_post_listing_mode: None,
}
}
}
1 change: 1 addition & 0 deletions crates/api_crud/src/user/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub async fn register(
.show_nsfw(Some(data.show_nsfw))
.accepted_application(accepted_application)
.default_listing_type(Some(local_site.default_post_listing_type))
.post_listing_mode(Some(local_site.default_post_listing_mode))
// If its the initial site setup, they are an admin
.admin(Some(!local_site.site_setup))
.build();
Expand Down
12 changes: 6 additions & 6 deletions crates/apub/src/api/list_posts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use lemmy_api_common::{
post::{GetPosts, GetPostsResponse},
utils::check_private_instance,
};
use lemmy_db_schema::source::{community::Community, local_site::LocalSite};
use lemmy_db_schema::source::community::Community;
use lemmy_db_views::{
post_view::PostQuery,
structs::{LocalUserView, PaginationCursor},
structs::{LocalUserView, PaginationCursor, SiteView},
};
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};

Expand All @@ -23,9 +23,9 @@ pub async fn list_posts(
context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>,
) -> Result<Json<GetPostsResponse>, LemmyError> {
let local_site = LocalSite::read(&mut context.pool()).await?;
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&local_user_view, &local_site)?;
check_private_instance(&local_user_view, &local_site.local_site)?;

let sort = data.sort;

Expand All @@ -47,7 +47,7 @@ pub async fn list_posts(

let listing_type = Some(listing_type_with_default(
data.type_,
&local_site,
&local_site.local_site,
community_id,
)?);
// parse pagination token
Expand All @@ -70,7 +70,7 @@ pub async fn list_posts(
limit,
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await
.with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;

Expand Down
15 changes: 8 additions & 7 deletions crates/apub/src/api/read_person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use lemmy_api_common::{
person::{GetPersonDetails, GetPersonDetailsResponse},
utils::{check_private_instance, read_site_for_actor},
};
use lemmy_db_schema::{
source::{local_site::LocalSite, person::Person},
utils::post_to_comment_sort_type,
use lemmy_db_schema::{source::person::Person, utils::post_to_comment_sort_type};
use lemmy_db_views::{
comment_view::CommentQuery,
post_view::PostQuery,
structs::{LocalUserView, SiteView},
};
use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery, structs::LocalUserView};
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType};

Expand All @@ -25,9 +26,9 @@ pub async fn read_person(
Err(LemmyErrorType::NoIdGiven)?
}

let local_site = LocalSite::read(&mut context.pool()).await?;
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&local_user_view, &local_site)?;
check_private_instance(&local_user_view, &local_site.local_site)?;

let person_details_id = match data.person_id {
Some(id) => id,
Expand Down Expand Up @@ -70,7 +71,7 @@ pub async fn read_person(
creator_id,
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;

let comments = CommentQuery {
Expand Down
24 changes: 12 additions & 12 deletions crates/apub/src/api/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use lemmy_api_common::{
site::{Search, SearchResponse},
utils::{check_private_instance, is_admin},
};
use lemmy_db_schema::{
source::{community::Community, local_site::LocalSite},
utils::post_to_comment_sort_type,
SearchType,
use lemmy_db_schema::{source::community::Community, utils::post_to_comment_sort_type, SearchType};
use lemmy_db_views::{
comment_view::CommentQuery,
post_view::PostQuery,
structs::{LocalUserView, SiteView},
};
use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery, structs::LocalUserView};
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
use lemmy_utils::error::LemmyError;

Expand All @@ -21,9 +21,9 @@ pub async fn search(
context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>,
) -> Result<Json<SearchResponse>, LemmyError> {
let local_site = LocalSite::read(&mut context.pool()).await?;
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&local_user_view, &local_site)?;
check_private_instance(&local_user_view, &local_site.local_site)?;

let is_admin = local_user_view
.as_ref()
Expand Down Expand Up @@ -68,7 +68,7 @@ pub async fn search(
limit: (limit),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;
}
SearchType::Comments => {
Expand Down Expand Up @@ -97,7 +97,7 @@ pub async fn search(
limit: (limit),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;
}
SearchType::Users => {
Expand Down Expand Up @@ -128,7 +128,7 @@ pub async fn search(
limit: (limit),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;

let q = data.q.clone();
Expand Down Expand Up @@ -162,7 +162,7 @@ pub async fn search(
limit: (limit),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?
};

Expand Down Expand Up @@ -192,7 +192,7 @@ pub async fn search(
limit: (limit),
..Default::default()
}
.list(&mut context.pool())
.list(&local_site.site, &mut context.pool())
.await?;
}
};
Expand Down
2 changes: 2 additions & 0 deletions crates/apub/src/objects/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl Object for ApubSite {
outbox: Url::parse(&format!("{}/site_outbox", self.actor_id))?,
public_key: self.public_key(),
language,
content_warning: self.content_warning.clone(),
published: self.published,
updated: self.updated,
};
Expand Down Expand Up @@ -154,6 +155,7 @@ impl Object for ApubSite {
public_key: Some(apub.public_key.public_key_pem.clone()),
private_key: None,
instance_id: instance.id,
content_warning: apub.content_warning,
};
let languages =
LanguageTag::to_language_id_multiple(apub.language, &mut context.pool()).await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/apub/src/protocol/objects/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct Instance {
pub(crate) image: Option<ImageObject>,
#[serde(default)]
pub(crate) language: Vec<LanguageTag>,
/// nonstandard field
pub(crate) content_warning: Option<String>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to look for a standard compliant way to federate this.

Copy link
Member Author

@Nutomic Nutomic Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saldy I cant find anything as we are already using content and summary. Have to leave it like this.

pub(crate) published: DateTime<Utc>,
pub(crate) updated: Option<DateTime<Utc>>,
}
1 change: 1 addition & 0 deletions crates/db_perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ lemmy_db_schema = { workspace = true }
lemmy_db_views = { workspace = true, features = ["full"] }
lemmy_utils = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
Loading