Merge remote-tracking branch 'origin/main' into fix_html_doctype_check

fix_html_doctype_check
Dessalines 3 months ago
commit 37ea4b778a

@ -60,7 +60,7 @@ steps:
# store cargo data in repo folder so that it gets cached between steps
CARGO_HOME: .cargo_home
commands:
# need make existing toolchain available
- rustup component add rustfmt
- cargo +nightly fmt -- --check
cargo_machete:

@ -967,8 +967,6 @@ mod tests {
#![allow(clippy::indexing_slicing)]
use super::*;
use crate::utils::{honeypot_check, limit_expire_time, password_length_check};
use chrono::{Days, Utc};
use pretty_assertions::assert_eq;
use serial_test::serial;

@ -6,11 +6,14 @@ use activitypub_federation::{
config::Data,
kinds::collection::OrderedCollectionType,
protocol::verification::verify_domains_match,
traits::{ActivityHandler, Collection, Object},
traits::{Collection, Object},
};
use futures::future::{join_all, try_join_all};
use lemmy_api_common::{context::LemmyContext, utils::generate_featured_url};
use lemmy_db_schema::{source::post::Post, utils::FETCH_LIMIT_MAX};
use lemmy_db_schema::{
source::{community::Community, post::Post},
utils::FETCH_LIMIT_MAX,
};
use lemmy_utils::error::LemmyError;
use url::Url;
@ -55,35 +58,36 @@ impl Collection for ApubCommunityFeatured {
async fn from_json(
apub: Self::Kind,
_owner: &Self::Owner,
data: &Data<Self::DataType>,
owner: &Self::Owner,
context: &Data<Self::DataType>,
) -> Result<Self, Self::Error>
where
Self: Sized,
{
let mut posts = apub.ordered_items;
if posts.len() as i64 > FETCH_LIMIT_MAX {
posts = posts
let mut pages = apub.ordered_items;
if pages.len() as i64 > FETCH_LIMIT_MAX {
pages = pages
.get(0..(FETCH_LIMIT_MAX as usize))
.unwrap_or_default()
.to_vec();
}
// We intentionally ignore errors here. This is because the outbox might contain posts from old
// Lemmy versions, or from other software which we cant parse. In that case, we simply skip the
// item and only parse the ones that work.
// process items in parallel, to avoid long delay from fetch_site_metadata() and other processing
join_all(posts.into_iter().map(|post| {
let stickied_posts: Vec<Post> = join_all(pages.into_iter().map(|page| {
async {
// use separate request counter for each item, otherwise there will be problems with
// parallel processing
let verify = post.verify(data).await;
if verify.is_ok() {
post.receive(data).await.ok();
}
ApubPost::verify(&page, &apub.id, context).await?;
ApubPost::from_json(page, context).await
}
}))
.await;
.await
// ignore any failed or unparseable items
.into_iter()
.filter_map(|p| p.ok().map(|p| p.0))
.collect();
Community::set_featured_posts(owner.id, stickied_posts, &mut context.pool()).await?;
// This return value is unused, so just set an empty vec
Ok(ApubCommunityFeatured(()))

@ -123,10 +123,7 @@ pub(crate) mod tests {
use crate::protocol::objects::{group::Group, tombstone::Tombstone};
use actix_web::body::to_bytes;
use lemmy_db_schema::{
source::{
community::{Community, CommunityInsertForm},
instance::Instance,
},
source::{community::CommunityInsertForm, instance::Instance},
traits::Crud,
CommunityVisibility,
};

@ -166,7 +166,7 @@ impl Object for ApubCommunity {
moderators_url: group.attributed_to.clone().map(Into::into),
posting_restricted_to_mods: group.posting_restricted_to_mods,
instance_id,
featured_url: group.featured.map(Into::into),
featured_url: group.featured.clone().map(Into::into),
..Default::default()
};
let languages =
@ -184,6 +184,9 @@ impl Object for ApubCommunity {
spawn_try_task(async move {
group.outbox.dereference(&community_, &context_).await?;
group.followers.dereference(&community_, &context_).await?;
if let Some(featured) = group.featured {
featured.dereference(&community_, &context_).await?;
}
if let Some(moderators) = group.attributed_to {
moderators.dereference(&community_, &context_).await?;
}
@ -254,7 +257,7 @@ pub(crate) mod tests {
protocol::tests::file_to_json_object,
};
use activitypub_federation::fetch::collection_id::CollectionId;
use lemmy_db_schema::{source::site::Site, traits::Crud};
use lemmy_db_schema::source::site::Site;
use lemmy_utils::error::LemmyResult;
use pretty_assertions::assert_eq;
use serial_test::serial;

@ -218,7 +218,6 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
pub(crate) mod tests {
use super::*;
use crate::protocol::tests::file_to_json_object;
use lemmy_db_schema::traits::Crud;
use lemmy_utils::error::LemmyResult;
use pretty_assertions::assert_eq;
use serial_test::serial;

@ -225,7 +225,7 @@ pub(crate) mod tests {
protocol::{objects::instance::Instance, tests::file_to_json_object},
};
use activitypub_federation::fetch::object_id::ObjectId;
use lemmy_db_schema::{source::site::Site, traits::Crud};
use lemmy_db_schema::source::site::Site;
use lemmy_utils::error::LemmyResult;
use pretty_assertions::assert_eq;
use serial_test::serial;

@ -34,7 +34,6 @@ use lemmy_api_common::{
},
};
use lemmy_db_schema::{
self,
source::{
community::Community,
local_site::LocalSite,
@ -297,7 +296,6 @@ mod tests {
community::{tests::parse_lemmy_community, ApubCommunity},
instance::ApubSite,
person::{tests::parse_lemmy_person, ApubPerson},
post::ApubPost,
},
protocol::tests::file_to_json_object,
};

@ -8,7 +8,6 @@ use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::{LemmyError, LemmyErrorType};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use strum_macros::Display;
use url::Url;

@ -306,9 +306,9 @@ impl CommunityLanguage {
// tracing::warn!("unique error: {_info:#?}");
// _info.constraint_name() should be = "community_language_community_id_language_id_key"
return Ok(());
} else {
insert_res?;
}
insert_res?;
Ok(())
}) as _
})
@ -391,27 +391,13 @@ mod tests {
use super::*;
use crate::{
impls::actor_language::{
convert_read_languages,
convert_update_languages,
default_post_language,
get_conn,
CommunityLanguage,
DbPool,
Language,
LanguageId,
LocalUserLanguage,
QueryDsl,
RunQueryDsl,
SiteLanguage,
},
source::{
community::{Community, CommunityInsertForm},
instance::Instance,
local_site::{LocalSite, LocalSiteInsertForm},
local_user::{LocalUser, LocalUserInsertForm},
person::{Person, PersonInsertForm},
site::{Site, SiteInsertForm},
site::SiteInsertForm,
},
traits::Crud,
utils::build_db_pool_for_tests,

@ -14,6 +14,7 @@ use crate::{
CommunityPersonBanForm,
CommunityUpdateForm,
},
post::Post,
},
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
utils::{functions::lower, get_conn, DbPool},
@ -27,6 +28,7 @@ use diesel::{
result::Error,
select,
sql_types,
update,
ExpressionMethods,
NullableExpressionMethods,
QueryDsl,
@ -137,6 +139,42 @@ impl Community {
}
Err(diesel::NotFound)
}
pub async fn set_featured_posts(
community_id: CommunityId,
posts: Vec<Post>,
pool: &mut DbPool<'_>,
) -> Result<(), Error> {
use crate::schema::post;
let conn = &mut get_conn(pool).await?;
for p in &posts {
debug_assert!(p.community_id == community_id);
}
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
update(
// first remove all existing featured posts
post::table,
)
.filter(post::dsl::community_id.eq(community_id))
.set(post::dsl::featured_community.eq(false))
.execute(conn)
.await?;
// then mark the given posts as featured
let post_ids: Vec<_> = posts.iter().map(|p| p.id).collect();
update(post::table)
.filter(post::dsl::id.eq_any(post_ids))
.set(post::dsl::featured_community.eq(true))
.execute(conn)
.await?;
Ok(())
}) as _
})
.await
}
}
impl CommunityModerator {

@ -248,9 +248,8 @@ pub fn limit_and_offset(
Some(page) => {
if page < 1 {
return Err(QueryBuilderError("Page is < 1".into()));
} else {
page
}
page
}
None => 1,
};
@ -260,9 +259,8 @@ pub fn limit_and_offset(
return Err(QueryBuilderError(
format!("Fetch limit is > {FETCH_LIMIT_MAX}").into(),
));
} else {
limit
}
limit
}
None => FETCH_LIMIT_DEFAULT,
};
@ -542,8 +540,7 @@ mod tests {
#![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)]
use super::{fuzzy_search, *};
use crate::utils::is_email_regex;
use super::*;
use pretty_assertions::assert_eq;
#[test]

@ -2,7 +2,7 @@ use cfg_if::cfg_if;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use strum_macros::{Display, EnumIter};
#[cfg(feature = "full")]
#[cfg(feature = "ts-rs")]
use ts_rs::TS;
#[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)]

Loading…
Cancel
Save