mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
Merge pull request 'Only search locally for Community::read_from_name and similar (ref #698)' (#110) from read-only-local into main
Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/110
This commit is contained in:
commit
75ace1192a
5 changed files with 18 additions and 12 deletions
|
@ -35,6 +35,7 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, web, web::Path, HttpResponse};
|
use actix_web::{body::Body, web, web::Path, HttpResponse};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use diesel::result::Error::NotFound;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
|
@ -68,6 +69,9 @@ pub async fn get_apub_comment(
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let id = info.comment_id.parse::<i32>()?;
|
let id = info.comment_id.parse::<i32>()?;
|
||||||
let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
|
let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
|
||||||
|
if !comment.local {
|
||||||
|
return Err(NotFound.into());
|
||||||
|
}
|
||||||
|
|
||||||
if !comment.deleted {
|
if !comment.deleted {
|
||||||
Ok(create_apub_response(
|
Ok(create_apub_response(
|
||||||
|
|
|
@ -11,7 +11,7 @@ use activitystreams::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||||
user::User_,
|
user::User_,
|
||||||
|
@ -48,15 +48,6 @@ pub async fn community_inbox(
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
if !community.local {
|
|
||||||
return Err(
|
|
||||||
anyhow!(
|
|
||||||
"Received activity is addressed to remote community {}",
|
|
||||||
&community.actor_id
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
debug!(
|
debug!(
|
||||||
"Community {} received activity {:?}",
|
"Community {} received activity {:?}",
|
||||||
&community.name, &activity
|
&community.name, &activity
|
||||||
|
|
|
@ -31,6 +31,7 @@ use activitystreams::{
|
||||||
use activitystreams_ext::Ext1;
|
use activitystreams_ext::Ext1;
|
||||||
use actix_web::{body::Body, web, HttpResponse};
|
use actix_web::{body::Body, web, HttpResponse};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
community::Community,
|
community::Community,
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
|
@ -61,6 +62,9 @@ pub async fn get_apub_post(
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let id = info.post_id.parse::<i32>()?;
|
let id = info.post_id.parse::<i32>()?;
|
||||||
let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
|
let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
|
||||||
|
if !post.local {
|
||||||
|
return Err(NotFound.into());
|
||||||
|
}
|
||||||
|
|
||||||
if !post.deleted {
|
if !post.deleted {
|
||||||
Ok(create_apub_response(&post.to_apub(context.pool()).await?))
|
Ok(create_apub_response(&post.to_apub(context.pool()).await?))
|
||||||
|
|
|
@ -87,6 +87,7 @@ impl Community {
|
||||||
pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
|
pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
|
||||||
use crate::schema::community::dsl::*;
|
use crate::schema::community::dsl::*;
|
||||||
community
|
community
|
||||||
|
.filter(local)
|
||||||
.filter(name.eq(community_name))
|
.filter(name.eq(community_name))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,11 +144,17 @@ impl User_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
|
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> {
|
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 {
|
pub fn get_profile_url(&self, hostname: &str) -> String {
|
||||||
|
|
Loading…
Reference in a new issue