Merge pull request 'Dont include community in comment to field (fixes #1446)' (#174) from no-community-in-comment-to into main

Reviewed-on: https://yerbamate.ml/LemmyNet/lemmy/pulls/174
This commit is contained in:
dessalines 2021-02-24 01:03:07 +00:00
commit 6499709221
5 changed files with 19 additions and 14 deletions

View file

@ -64,6 +64,14 @@
- src: '../docker/iframely.config.local.js'
dest: '{{lemmy_base_dir}}/iframely.config.local.js'
mode: '0600'
vars:
lemmy_docker_image: "dessalines/lemmy:dev"
lemmy_docker_ui_image: "dessalines/lemmy-ui:{{ lookup('file', 'VERSION') }}"
lemmy_port: "8536"
lemmy_ui_port: "1235"
pictshare_port: "8537"
iframely_port: "8538"
postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
- name: add config file (only during initial setup)
template:

View file

@ -120,7 +120,7 @@ pub(crate) async fn community_receive_message(
User_::read_from_apub_id(&conn, &actor_id.into())
})
.await??;
check_community_or_site_ban(&user, &to_community, context.pool()).await?;
check_community_or_site_ban(&user, to_community.id, context.pool()).await?;
let any_base = activity.clone().into_any_base()?;
let actor_url = actor.actor_id();
@ -261,14 +261,13 @@ async fn handle_undo_follow(
pub(crate) async fn check_community_or_site_ban(
user: &User_,
community: &Community,
community_id: i32,
pool: &DbPool,
) -> Result<(), LemmyError> {
if user.banned {
return Err(anyhow!("User is banned from site").into());
}
let user_id = user.id;
let community_id = community.id;
let is_banned = move |conn: &'_ _| CommunityUserBanView::get(conn, user_id, community_id).is_ok();
if blocking(pool, is_banned).await? {
return Err(anyhow!("User is banned from community").into());

View file

@ -24,7 +24,6 @@ use anyhow::{anyhow, Context};
use lemmy_db_queries::{Crud, DbPool};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::Community,
post::Post,
user::User_,
};
@ -50,9 +49,6 @@ impl ToApub for Comment {
let post_id = self.post_id;
let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
// Add a vector containing some important info to the "in_reply_to" field
// [post_ap_id, Option(parent_comment_ap_id)]
let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
@ -68,7 +64,7 @@ impl ToApub for Comment {
.set_many_contexts(lemmy_context()?)
.set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
.set_many_tos(vec![community.actor_id.into_inner(), public()])
.set_to(public())
.set_many_in_reply_tos(in_reply_to_vec)
.set_attributed_to(creator.actor_id.into_inner());
@ -104,13 +100,13 @@ impl FromApub for Comment {
expected_domain: Url,
request_counter: &mut i32,
) -> Result<Comment, LemmyError> {
check_object_for_community_or_site_ban(note, context, request_counter).await?;
let comment: Comment =
get_object_from_apub(note, context, expected_domain, request_counter).await?;
let post_id = comment.post_id;
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
check_object_for_community_or_site_ban(note, post.community_id, context, request_counter)
.await?;
if post.locked {
// This is not very efficient because a comment gets inserted just to be deleted right
// afterwards, but it seems to be the easiest way to implement it.

View file

@ -207,6 +207,7 @@ where
pub(in crate::objects) async fn check_object_for_community_or_site_ban<T, Kind>(
object: &T,
community_id: i32,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError>
@ -219,8 +220,7 @@ where
.as_single_xsd_any_uri()
.context(location_info!())?;
let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?;
let community = get_to_community(object, context, request_counter).await?;
check_community_or_site_ban(&user, &community, context.pool()).await
check_community_or_site_ban(&user, community_id, context.pool()).await
}
pub(in crate::objects) async fn get_to_community<T, Kind>(

View file

@ -118,8 +118,10 @@ impl FromApub for Post {
expected_domain: Url,
request_counter: &mut i32,
) -> Result<Post, LemmyError> {
check_object_for_community_or_site_ban(page, context, request_counter).await?;
get_object_from_apub(page, context, expected_domain, request_counter).await
let post: Post = get_object_from_apub(page, context, expected_domain, request_counter).await?;
check_object_for_community_or_site_ban(page, post.community_id, context, request_counter)
.await?;
Ok(post)
}
}