]> Untitled Git - lemmy.git/commitdiff
Only search locally for Community::read_from_name and similar (ref #698)
authorFelix Ableitner <me@nutomic.com>
Fri, 2 Oct 2020 12:16:40 +0000 (14:16 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 2 Oct 2020 12:18:20 +0000 (14:18 +0200)
lemmy_apub/src/comment.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/post.rs
lemmy_db/src/community.rs
lemmy_db/src/user.rs

index 4e5c173f892c8b3d4df55e1f9ba25c5f4881a574..459d0796cda86244a595650c9b197cf6222c83d1 100644 (file)
@@ -35,6 +35,7 @@ use activitystreams::{
 };
 use actix_web::{body::Body, web, web::Path, HttpResponse};
 use anyhow::Context;
+use diesel::result::Error::NotFound;
 use itertools::Itertools;
 use lemmy_db::{
   comment::{Comment, CommentForm},
@@ -68,6 +69,9 @@ pub async fn get_apub_comment(
 ) -> Result<HttpResponse<Body>, LemmyError> {
   let id = info.comment_id.parse::<i32>()?;
   let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
+  if !comment.local {
+    return Err(NotFound.into());
+  }
 
   if !comment.deleted {
     Ok(create_apub_response(
index ee75fa005fa758cf75e3ed1e7f1a56dad2373054..6f5f1854ee066397dab03f87517e80e93d2901d3 100644 (file)
@@ -11,7 +11,7 @@ use activitystreams::{
   prelude::*,
 };
 use actix_web::{web, HttpRequest, HttpResponse};
-use anyhow::{anyhow, Context};
+use anyhow::Context;
 use lemmy_db::{
   community::{Community, CommunityFollower, CommunityFollowerForm},
   user::User_,
@@ -48,15 +48,6 @@ pub async fn community_inbox(
   })
   .await??;
 
-  if !community.local {
-    return Err(
-      anyhow!(
-        "Received activity is addressed to remote community {}",
-        &community.actor_id
-      )
-      .into(),
-    );
-  }
   debug!(
     "Community {} received activity {:?}",
     &community.name, &activity
index 8f5ffbcb8f4310fd481b256ee4e5a36b68232552..efdfcfd6cbed990e92ffbe787b65c174cb521400 100644 (file)
@@ -31,6 +31,7 @@ use activitystreams::{
 use activitystreams_ext::Ext1;
 use actix_web::{body::Body, web, HttpResponse};
 use anyhow::Context;
+use diesel::result::Error::NotFound;
 use lemmy_db::{
   community::Community,
   post::{Post, PostForm},
@@ -61,6 +62,9 @@ pub async fn get_apub_post(
 ) -> Result<HttpResponse<Body>, LemmyError> {
   let id = info.post_id.parse::<i32>()?;
   let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
+  if !post.local {
+    return Err(NotFound.into());
+  }
 
   if !post.deleted {
     Ok(create_apub_response(&post.to_apub(context.pool()).await?))
index 24cf7e32fd0129fdf6cabd1224cbd5dc2b8923c9..b4fa424a7f311a2929e0e55a294a9970a69fbe4a 100644 (file)
@@ -87,6 +87,7 @@ impl Community {
   pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
     use crate::schema::community::dsl::*;
     community
+      .filter(local)
       .filter(name.eq(community_name))
       .first::<Self>(conn)
   }
index 60fdebbbaafdb11ae1d1765f5f93e17bafff1021..42be672af3d9b43ca285fefa8b9cf4d1048fe4df 100644 (file)
@@ -143,11 +143,17 @@ impl User_ {
   }
 
   pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
-    user_.filter(name.ilike(username)).first::<User_>(conn)
+    user_
+      .filter(local)
+      .filter(name.ilike(username))
+      .first::<User_>(conn)
   }
 
   pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
-    user_.filter(email.eq(from_email)).first::<User_>(conn)
+    user_
+      .filter(local)
+      .filter(email.eq(from_email))
+      .first::<User_>(conn)
   }
 
   pub fn get_profile_url(&self, hostname: &str) -> String {