]> Untitled Git - lemmy.git/commitdiff
Fix data fetching from Peertube (fixes #2689) (#2703)
authorNutomic <me@nutomic.com>
Sun, 5 Feb 2023 05:38:08 +0000 (14:38 +0900)
committerGitHub <noreply@github.com>
Sun, 5 Feb 2023 05:38:08 +0000 (00:38 -0500)
- Other platforms can support additional language tags. Treat those
as None instead of throwing error
- deserialize_skip_error was implemented incorrectly and failed on
array values (https://github.com/LemmyNet/activitypub-federation-rust/commit/6d9682f4e6e5d47afaa05f8a35a230bf5e07a334)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Cargo.lock
Cargo.toml
crates/apub/src/api/resolve_object.rs
crates/apub/src/protocol/objects/group.rs
crates/apub/src/protocol/objects/mod.rs
crates/db_schema/src/impls/actor_language.rs
crates/db_schema/src/impls/language.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs

index 1c9cf6e8e9fc5f663cfd12ddec147bbee4344759..7cea9b571d4cb5f6855faa0a1590d42dc1aaea7d 100644 (file)
@@ -4,9 +4,9 @@ version = 3
 
 [[package]]
 name = "activitypub_federation"
-version = "0.3.4"
+version = "0.3.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f61d7a9a1207e70140b47869fd05222e30052ddc9ccfcc43098e48396c4e176"
+checksum = "59fbd2b7fb0aea9bdd738fc1441d34d3e7b585d60b42ed63deeac289c872f119"
 dependencies = [
  "actix-web",
  "anyhow",
index ac03b76e89919cbf5c9dbcb71a4684bb916d67c6..123991c7507b7383b6cca4c1fdd4905aac0644a3 100644 (file)
@@ -59,7 +59,7 @@ lemmy_routes = { version = "=0.17.1", path = "./crates/routes" }
 lemmy_db_views = { version = "=0.17.1", path = "./crates/db_views" }
 lemmy_db_views_actor = { version = "=0.17.1", path = "./crates/db_views_actor" }
 lemmy_db_views_moderator = { version = "=0.17.1", path = "./crates/db_views_moderator" }
-activitypub_federation = "0.3.4"
+activitypub_federation = "0.3.5"
 diesel = "2.0.2"
 diesel_migrations = "2.0.0"
 diesel-async = "0.1.1"
index dd39218bc14c8ebd4a441aa3c5c22ba626bb4c9e..c4fb2e9b8c0a236e006233747ee4d93e575a777c 100644 (file)
@@ -30,7 +30,9 @@ impl PerformApub for ResolveObject {
     let local_site = LocalSite::read(context.pool()).await?;
     check_private_instance(&local_user_view, &local_site)?;
 
-    let res = search_query_to_object_id(&self.q, local_user_view.is_none(), context)
+    // In release builds only allow for authenticated users to fetch remote objects
+    let local_only = local_user_view.is_none() && cfg!(not(debug_assertions));
+    let res = search_query_to_object_id(&self.q, local_only, context)
       .await
       .map_err(|e| e.with_message("couldnt_find_object"))?;
     convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
index 03f71a348b2d712029b8682fb642bc2a9fe51b98..5551b12888d5b35a05d4273a68912ba7a7801a86 100644 (file)
@@ -31,6 +31,7 @@ use lemmy_utils::{
 };
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
+use std::fmt::Debug;
 use url::Url;
 
 #[skip_serializing_none]
index 2dcf1eed74af86dbba7223849710acc3b70973ee..ad58d2677ac721b140504ddd9fa730eb4e1a6246 100644 (file)
@@ -68,7 +68,7 @@ impl LanguageTag {
     pool: &DbPool,
   ) -> Result<Option<LanguageId>, LemmyError> {
     let identifier = lang.map(|l| l.identifier);
-    let language = Language::read_id_from_code_opt(pool, identifier.as_deref()).await?;
+    let language = Language::read_id_from_code(pool, identifier.as_deref()).await?;
 
     Ok(language)
   }
@@ -81,10 +81,10 @@ impl LanguageTag {
 
     for l in langs {
       let id = l.identifier;
-      language_ids.push(Language::read_id_from_code(pool, &id).await?);
+      language_ids.push(Language::read_id_from_code(pool, Some(&id)).await?);
     }
 
-    Ok(language_ids)
+    Ok(language_ids.into_iter().flatten().collect())
   }
 }
 
index 7c311490b0cc12b0e3184d30fc73a6da25662436..c04982417512bf4260dee9285948d7703cc27aed 100644 (file)
@@ -370,15 +370,30 @@ mod tests {
 
   async fn test_langs1(pool: &DbPool) -> Vec<LanguageId> {
     vec![
-      Language::read_id_from_code(pool, "en").await.unwrap(),
-      Language::read_id_from_code(pool, "fr").await.unwrap(),
-      Language::read_id_from_code(pool, "ru").await.unwrap(),
+      Language::read_id_from_code(pool, Some("en"))
+        .await
+        .unwrap()
+        .unwrap(),
+      Language::read_id_from_code(pool, Some("fr"))
+        .await
+        .unwrap()
+        .unwrap(),
+      Language::read_id_from_code(pool, Some("ru"))
+        .await
+        .unwrap()
+        .unwrap(),
     ]
   }
   async fn test_langs2(pool: &DbPool) -> Vec<LanguageId> {
     vec![
-      Language::read_id_from_code(pool, "fi").await.unwrap(),
-      Language::read_id_from_code(pool, "se").await.unwrap(),
+      Language::read_id_from_code(pool, Some("fi"))
+        .await
+        .unwrap()
+        .unwrap(),
+      Language::read_id_from_code(pool, Some("se"))
+        .await
+        .unwrap()
+        .unwrap(),
     ]
   }
 
@@ -603,11 +618,20 @@ mod tests {
       .unwrap();
     assert_eq!(None, def1);
 
-    let ru = Language::read_id_from_code(pool, "ru").await.unwrap();
+    let ru = Language::read_id_from_code(pool, Some("ru"))
+      .await
+      .unwrap()
+      .unwrap();
     let test_langs3 = vec![
       ru,
-      Language::read_id_from_code(pool, "fi").await.unwrap(),
-      Language::read_id_from_code(pool, "se").await.unwrap(),
+      Language::read_id_from_code(pool, Some("fi"))
+        .await
+        .unwrap()
+        .unwrap(),
+      Language::read_id_from_code(pool, Some("se"))
+        .await
+        .unwrap()
+        .unwrap(),
     ];
     LocalUserLanguage::update(pool, test_langs3, local_user.id)
       .await
index 78898bcac01275aefb4a9e0ed7e6cb8d60305dcc..da9e0ca9d7e3d90cbb4fa9f8c1881d4eda19c9bd 100644 (file)
@@ -23,23 +23,21 @@ impl Language {
     language.filter(id.eq(id_)).first::<Self>(conn).await
   }
 
-  pub async fn read_id_from_code(pool: &DbPool, code_: &str) -> Result<LanguageId, Error> {
-    let conn = &mut get_conn(pool).await?;
-    Ok(
-      language
-        .filter(code.eq(code_))
-        .first::<Self>(conn)
-        .await?
-        .id,
-    )
-  }
-
-  pub async fn read_id_from_code_opt(
+  /// Attempts to find the given language code and return its ID. If not found, returns none.
+  pub async fn read_id_from_code(
     pool: &DbPool,
     code_: Option<&str>,
   ) -> Result<Option<LanguageId>, Error> {
     if let Some(code_) = code_ {
-      Ok(Some(Language::read_id_from_code(pool, code_).await?))
+      let conn = &mut get_conn(pool).await?;
+      Ok(
+        language
+          .filter(code.eq(code_))
+          .first::<Self>(conn)
+          .await
+          .map(|l| l.id)
+          .ok(),
+      )
     } else {
       Ok(None)
     }
index 66daf831c212e6a44dc7d178dfb29857c0491130..1819c04dbf6ababade68af3d9e15451943685141 100644 (file)
@@ -513,7 +513,10 @@ mod tests {
       .await
       .unwrap();
 
-    let finnish_id = Language::read_id_from_code(pool, "fi").await.unwrap();
+    let finnish_id = Language::read_id_from_code(pool, Some("fi"))
+      .await
+      .unwrap()
+      .unwrap();
     let comment_form_2 = CommentInsertForm::builder()
       .content("Comment 2".into())
       .creator_id(inserted_person.id)
@@ -536,7 +539,10 @@ mod tests {
         .await
         .unwrap();
 
-    let polish_id = Language::read_id_from_code(pool, "pl").await.unwrap();
+    let polish_id = Language::read_id_from_code(pool, Some("pl"))
+      .await
+      .unwrap()
+      .unwrap();
     let comment_form_4 = CommentInsertForm::builder()
       .content("Comment 4".into())
       .creator_id(inserted_person.id)
@@ -747,7 +753,10 @@ mod tests {
     assert_eq!(5, all_languages.len());
 
     // change user lang to finnish, should only show single finnish comment
-    let finnish_id = Language::read_id_from_code(pool, "fi").await.unwrap();
+    let finnish_id = Language::read_id_from_code(pool, Some("fi"))
+      .await
+      .unwrap()
+      .unwrap();
     LocalUserLanguage::update(pool, vec![finnish_id], data.inserted_local_user.id)
       .await
       .unwrap();
@@ -766,7 +775,10 @@ mod tests {
     assert_eq!(finnish_id, finnish_comment[0].comment.language_id);
 
     // now show all comments with undetermined language (which is the default value)
-    let undetermined_id = Language::read_id_from_code(pool, "und").await.unwrap();
+    let undetermined_id = Language::read_id_from_code(pool, Some("und"))
+      .await
+      .unwrap()
+      .unwrap();
     LocalUserLanguage::update(pool, vec![undetermined_id], data.inserted_local_user.id)
       .await
       .unwrap();
index 4a36b816fbe7dc55545f873f80b3c2d74321d913..0804815dfb3485270b9925d47cc213df16bd0815 100644 (file)
@@ -754,7 +754,10 @@ mod tests {
     let pool = &build_db_pool_for_tests().await;
     let data = init_data(pool).await;
 
-    let spanish_id = Language::read_id_from_code(pool, "es").await.unwrap();
+    let spanish_id = Language::read_id_from_code(pool, Some("es"))
+      .await
+      .unwrap()
+      .unwrap();
     let post_spanish = PostInsertForm::builder()
       .name("asffgdsc".to_string())
       .creator_id(data.inserted_person.id)
@@ -776,7 +779,10 @@ mod tests {
     // no language filters specified, all posts should be returned
     assert_eq!(3, post_listings_all.len());
 
-    let french_id = Language::read_id_from_code(pool, "fr").await.unwrap();
+    let french_id = Language::read_id_from_code(pool, Some("fr"))
+      .await
+      .unwrap()
+      .unwrap();
     LocalUserLanguage::update(pool, vec![french_id], data.inserted_local_user.id)
       .await
       .unwrap();
@@ -794,7 +800,10 @@ mod tests {
     assert_eq!(1, post_listing_french.len());
     assert_eq!(french_id, post_listing_french[0].post.language_id);
 
-    let undetermined_id = Language::read_id_from_code(pool, "und").await.unwrap();
+    let undetermined_id = Language::read_id_from_code(pool, Some("und"))
+      .await
+      .unwrap()
+      .unwrap();
     LocalUserLanguage::update(
       pool,
       vec![french_id, undetermined_id],