Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint-plugin-prettier": "^5.5.0",
"jest": "^30.0.0",
"joi": "^18.0.0",
"lemmy-js-client": "1.0.0-rename-update-edit.2",
"lemmy-js-client": "1.0.0-rename-sidebar-again.1",
"lemmy-js-client-019": "npm:lemmy-js-client@0.19.9",
"prettier": "^3.5.3",
"ts-jest": "^29.4.0",
Expand Down
10 changes: 5 additions & 5 deletions api_tests/pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions api_tests/src/community.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,15 @@ test("Remote mods can edit communities", async () => {

let form2: EditCommunity = {
community_id: betaCommunity.community.id as number,
description: "Example sidebar",
sidebar: "Example sidebar",
};

await editCommunity(beta, form2);

const communityId = communityRes.community_view.community.id;
await waitUntil(
() => getCommunity(alpha, communityId),
c => c.community_view.community.description == "Example sidebar",
c => c.community_view.community.sidebar == "Example sidebar",
);
});

Expand Down
8 changes: 3 additions & 5 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,11 @@ export async function createCommunity(
name_: string = randomString(10),
visibility: CommunityVisibility = "public",
): Promise<CommunityResponse> {
let description = "a sample sidebar";
let sidebar = "a sample sidebar";
let form: CreateCommunity = {
name: name_,
title: name_,
description,
sidebar,
visibility,
};
return api.createCommunity(form);
Expand Down Expand Up @@ -1064,9 +1064,7 @@ export function assertCommunityFederation(
expect(communityOne?.community.ap_id).toBe(communityTwo?.community.ap_id);
expect(communityOne?.community.name).toBe(communityTwo?.community.name);
expect(communityOne?.community.title).toBe(communityTwo?.community.title);
expect(communityOne?.community.description).toBe(
communityTwo?.community.description,
);
expect(communityOne?.community.sidebar).toBe(communityTwo?.community.sidebar);
expect(communityOne?.community.icon).toBe(communityTwo?.community.icon);
expect(communityOne?.community.banner).toBe(communityTwo?.community.banner);
expect(communityOne?.community.published_at).toBe(
Expand Down
16 changes: 8 additions & 8 deletions crates/api/api/src/community/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub async fn create_community_tag(
check_community_mod_action(&local_user_view, &community, false, &mut context.pool()).await?;

check_api_elements_count(community_view.post_tags.0.len())?;
if let Some(desc) = &data.description {
summary_length_check(desc)?;
check_slurs(desc, &slur_regex(&context).await?)?;
if let Some(summary) = &data.summary {
summary_length_check(summary)?;
check_slurs(summary, &slur_regex(&context).await?)?;
}

let ap_id = Url::parse(&format!("{}/tag/{}", community.ap_id, &data.name))?;
Expand All @@ -51,7 +51,7 @@ pub async fn create_community_tag(
let tag_form = TagInsertForm {
name: data.name.clone(),
display_name: data.display_name.clone(),
description: data.description.clone(),
summary: data.summary.clone(),
community_id: data.community_id,
ap_id: ap_id.into(),
deleted: Some(false),
Expand All @@ -78,15 +78,15 @@ pub async fn edit_community_tag(
// Verify that only mods can update tags
check_community_mod_action(&local_user_view, &community, false, &mut context.pool()).await?;

if let Some(desc) = &data.description {
summary_length_check(desc)?;
check_slurs(desc, &slur_regex(&context).await?)?;
if let Some(summary) = &data.summary {
summary_length_check(summary)?;
check_slurs(summary, &slur_regex(&context).await?)?;
}

// Update the tag
let tag_form = TagUpdateForm {
display_name: diesel_string_update(data.display_name.as_deref()),
description: diesel_string_update(data.description.as_deref()),
summary: diesel_string_update(data.summary.as_deref()),
updated_at: Some(Some(Utc::now())),
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion crates/api/api/src/reports/community_report/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn create_community_report(
original_community_summary: community.summary,
original_community_icon: community.icon,
original_community_name: community.name,
original_community_description: community.description,
original_community_sidebar: community.sidebar,
original_community_title: community.title,
reason,
};
Expand Down
9 changes: 4 additions & 5 deletions crates/api/api_crud/src/community/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ pub async fn create_community(
let url_blocklist = get_url_blocklist(&context).await?;
check_slurs(&data.name, &slur_regex)?;
check_slurs(&data.title, &slur_regex)?;
let description =
process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context).await?;
let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context).await?;
let title = data.title.trim();
is_valid_display_name(title)?;

// Ensure that the sidebar has fewer than the max num characters...
if let Some(description) = &description {
is_valid_body_field(description, false)?;
if let Some(sidebar) = &sidebar {
is_valid_body_field(sidebar, false)?;
}

let summary = data.summary.clone();
Expand All @@ -92,7 +91,7 @@ pub async fn create_community(

let keypair = generate_actor_keypair()?;
let community_form = CommunityInsertForm {
description,
sidebar,
summary,
nsfw: data.nsfw,
ap_id: Some(community_ap_id.clone()),
Expand Down
10 changes: 5 additions & 5 deletions crates/api/api_crud/src/community/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ pub async fn edit_community(
is_valid_display_name(title)?;
}

let description = diesel_string_update(
process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context)
let sidebar = diesel_string_update(
process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context)
.await?
.as_deref(),
);

if let Some(Some(description)) = &description {
is_valid_body_field(description, false)?;
if let Some(Some(sidebar)) = &sidebar {
is_valid_body_field(sidebar, false)?;
}

let summary = diesel_string_update(data.summary.as_deref());
Expand All @@ -80,7 +80,7 @@ pub async fn edit_community(

let community_form = CommunityUpdateForm {
title: data.title.clone(),
description,
sidebar,
summary,
nsfw: data.nsfw,
posting_restricted_to_mods: data.posting_restricted_to_mods,
Expand Down
2 changes: 1 addition & 1 deletion crates/api/api_crud/src/multi_community/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn create_multi_community(

let form = MultiCommunityInsertForm {
title: data.title.clone(),
description: data.description.clone(),
summary: data.summary.clone(),
ap_id: Some(ap_id),
private_key: site_view.site.private_key,
inbox_url: Some(site_view.site.inbox_url),
Expand Down
2 changes: 1 addition & 1 deletion crates/api/api_crud/src/multi_community/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn edit_multi_community(

let form = MultiCommunityUpdateForm {
title: diesel_string_update(data.title.as_deref()),
description: diesel_string_update(data.description.as_deref()),
summary: diesel_string_update(data.summary.as_deref()),
deleted: data.deleted,
updated_at: Some(Utc::now()),
};
Expand Down
11 changes: 5 additions & 6 deletions crates/api/api_crud/src/site/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ pub async fn create_site(

let slur_regex = slur_regex(&context).await?;
let url_blocklist = get_url_blocklist(&context).await?;
let description =
process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context).await?;
let sidebar = process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context).await?;

let site_form = SiteUpdateForm {
name: Some(data.name.clone()),
description: diesel_string_update(description.as_deref()),
sidebar: diesel_string_update(sidebar.as_deref()),
summary: diesel_string_update(data.summary.as_deref()),
ap_id: Some(ap_id),
last_refreshed_at: Some(Utc::now()),
Expand Down Expand Up @@ -166,8 +165,8 @@ fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) ->
site_default_post_listing_type_check(&create_site.default_post_listing_type)?;

// Ensure that the sidebar has fewer than the max num characters...
if let Some(body) = &create_site.description {
is_valid_body_field(body, false)?;
if let Some(sidebar) = &create_site.sidebar {
is_valid_body_field(sidebar, false)?;
}

application_question_check(
Expand Down Expand Up @@ -330,7 +329,7 @@ mod tests {
},
&CreateSite {
name: String::from("site_name"),
description: Some(String::new()),
sidebar: Some(String::new()),
summary: Some(String::new()),
application_question: Some(String::new()),
private_instance: Some(false),
Expand Down
12 changes: 6 additions & 6 deletions crates/api/api_crud/src/site/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub async fn edit_site(

let slur_regex = slur_regex(&context).await?;
let url_blocklist = get_url_blocklist(&context).await?;
let description = diesel_string_update(
process_markdown_opt(&data.description, &slur_regex, &url_blocklist, &context)
let sidebar = diesel_string_update(
process_markdown_opt(&data.sidebar, &slur_regex, &url_blocklist, &context)
.await?
.as_deref(),
);
Expand All @@ -76,7 +76,7 @@ pub async fn edit_site(

let site_form = SiteUpdateForm {
name: data.name.clone(),
description,
sidebar,
summary: diesel_string_update(data.summary.as_deref()),
content_warning: diesel_string_update(data.content_warning.as_deref()),
updated_at: Some(Some(Utc::now())),
Expand Down Expand Up @@ -213,8 +213,8 @@ fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> Lemm
site_default_post_listing_type_check(&edit_site.default_post_listing_type)?;

// Ensure that the sidebar has fewer than the max num characters...
if let Some(body) = &edit_site.description {
is_valid_body_field(body, false)?;
if let Some(sidebar) = &edit_site.sidebar {
is_valid_body_field(sidebar, false)?;
}

application_question_check(
Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {
},
&EditSite {
name: Some(String::from("site_name")),
description: Some(String::new()),
sidebar: Some(String::new()),
summary: Some(String::new()),
application_question: Some(String::new()),
private_instance: Some(false),
Expand Down
2 changes: 1 addition & 1 deletion crates/api/routes_v3/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ pub(crate) fn convert_site(site: Site) -> SiteV3 {
let Site {
id,
name,
description: sidebar,
sidebar,
published_at,
updated_at,
icon,
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/activities/src/community/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Activity for Report {
original_community_banner: community.banner.clone(),
original_community_icon: community.icon.clone(),
original_community_summary: community.summary.clone(),
original_community_description: community.description.clone(),
original_community_sidebar: community.sidebar.clone(),
};
CommunityReport::report(&mut context.pool(), &report_form).await?;
}
Expand Down
24 changes: 12 additions & 12 deletions crates/apub/objects/src/objects/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use lemmy_utils::{
utils::{
markdown::markdown_to_html,
slurs::{check_slurs, check_slurs_opt},
validation::truncate_description,
validation::truncate_summary,
},
};
use std::{ops::Deref, sync::OnceLock};
Expand Down Expand Up @@ -123,10 +123,10 @@ impl Object for ApubCommunity {
id: self.id().clone().into(),
preferred_username: self.name.clone(),
name: Some(self.title.clone()),
content: self.summary.as_ref().map(|d| markdown_to_html(d)),
source: self.summary.clone().map(Source::new),
summary: self.description.clone(),
media_type: self.summary.as_ref().map(|_| MediaTypeHtml::Html),
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),
source: self.sidebar.clone().map(Source::new),
summary: self.summary.clone(),
media_type: self.sidebar.as_ref().map(|_| MediaTypeHtml::Html),
icon: self.icon.clone().map(ImageObject::new),
image: self.banner.clone().map(ImageObject::new),
sensitive: Some(self.nsfw),
Expand Down Expand Up @@ -166,6 +166,7 @@ impl Object for ApubCommunity {
check_slurs(&group.preferred_username, &slur_regex)?;
check_slurs_opt(&group.name, &slur_regex)?;
check_slurs_opt(&group.summary, &slur_regex)?;
check_slurs_opt(&group.content, &slur_regex)?;
Ok(())
}

Expand All @@ -179,10 +180,9 @@ impl Object for ApubCommunity {

let slur_regex = slur_regex(context).await?;
let url_blocklist = get_url_blocklist(context).await?;
let description = read_from_string_or_source_opt(&group.summary, &None, &group.source);
let description =
process_markdown_opt(&description, &slur_regex, &url_blocklist, context).await?;
let description = markdown_rewrite_remote_links_opt(description, context).await;
let sidebar = read_from_string_or_source_opt(&group.content, &None, &group.source);
let sidebar = process_markdown_opt(&sidebar, &slur_regex, &url_blocklist, context).await?;
let sidebar = markdown_rewrite_remote_links_opt(sidebar, context).await;
let icon = proxy_image_link_opt_apub(group.icon.clone().map(|i| i.url), context).await?;
let banner = proxy_image_link_opt_apub(group.image.clone().map(|i| i.url), context).await?;
let visibility = Some(community_visibility(&group));
Expand All @@ -203,9 +203,9 @@ impl Object for ApubCommunity {
last_refreshed_at: Some(Utc::now()),
icon,
banner,
description,
sidebar,
removed,
summary: group.content.clone().as_deref().map(truncate_description),
summary: group.summary.clone().as_deref().map(truncate_summary),
followers_url: group.followers.clone().clone().map(Into::into),
inbox_url: Some(
group
Expand Down Expand Up @@ -308,7 +308,7 @@ pub(crate) mod tests {

// Test the sidebar and description
assert_eq!(
community.description.as_ref().map(std::string::String::len),
community.sidebar.as_ref().map(std::string::String::len),
Some(63)
);
assert_eq!(
Expand Down
Loading