Skip to content

Federate community reports #5496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d67cb19
add calls to submit_activity and use SiteOrCommunity
dullbananas Mar 11, 2025
60203ac
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Mar 14, 2025
97f9ba0
add send_activity imports
dullbananas Mar 14, 2025
eb46faa
use separate CreateReportToSite and SendResolveReportToSite variants
dullbananas Mar 15, 2025
1699e17
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Mar 15, 2025
8df24fb
fix api compile errors
dullbananas Mar 15, 2025
580151c
allow apub Report struct to represent community report
dullbananas Mar 16, 2025
97ba710
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Mar 16, 2025
7b4604c
change argument types of Report::new, Report::send, and report_inboxes
dullbananas Mar 17, 2025
9446e8a
impl Object for ReportableObjects
dullbananas Mar 17, 2025
b7ad063
impl Actor for SiteOrCommunity
dullbananas Mar 17, 2025
2980197
change return types of ReportObject::dereference and ReportObject::ob…
dullbananas Mar 17, 2025
8561dd0
Add verify_person_in_site_or_community
dullbananas Mar 17, 2025
f2fa0ed
replace Report::community with Report::recipient to return either sit…
dullbananas Mar 17, 2025
8e18194
fix Report::receive
dullbananas Mar 17, 2025
43a671d
fix ResolveReport::send
dullbananas Mar 18, 2025
bba0869
fix ResolveReport
dullbananas Mar 18, 2025
a851ffd
fix match_outgoing_activities
dullbananas Mar 18, 2025
6c8c22f
replace recipient with receiver
dullbananas Mar 18, 2025
137e966
lint
dullbananas Mar 18, 2025
91f7abc
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Mar 25, 2025
3d30d7e
update cargo.toml files
dullbananas Mar 25, 2025
8208c8a
start removing new custom enums
dullbananas Mar 25, 2025
fcea7f7
Revert "start removing new custom enums"
dullbananas Mar 25, 2025
87de4a0
remove new trait impls on enums
dullbananas Mar 25, 2025
b9723fd
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Apr 1, 2025
7c5afda
change reportableobjects to type alias that uses either
dullbananas Apr 7, 2025
1452ff4
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Apr 7, 2025
8dcdcd7
fix fetcher::report
dullbananas Apr 7, 2025
b05924f
find and replace reportableobjects variant names
dullbananas Apr 7, 2025
fae2a11
delete crates/utils/translations
dullbananas Apr 7, 2025
9506e67
remove uses of custom siteorcommunity enum
dullbananas Apr 8, 2025
dfad1a0
clippy
dullbananas Apr 8, 2025
67d8a33
dont use separate module for reportableobjects
dullbananas Apr 8, 2025
6c1880f
Merge remote-tracking branch 'upstream/main' into federate-community-…
dullbananas Apr 21, 2025
0136631
remove ResolveReport::reciever
dullbananas Apr 21, 2025
ad6d294
replace match in activity_lists with Report::community
dullbananas Apr 22, 2025
f315240
combine variants for community and site in SendActivityData enum
dullbananas Apr 22, 2025
63253cb
add reportCommunity function to shared.ts
dullbananas Apr 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ lemmy_routes = { version = "=1.0.0-alpha.4", path = "./crates/routes" }
lemmy_db_views = { version = "=1.0.0-alpha.4", path = "./crates/db_views" }
lemmy_federate = { version = "=1.0.0-alpha.4", path = "./crates/federate" }
lemmy_email = { version = "=1.0.0-alpha.4", path = "./crates/email" }
activitypub_federation = { version = "0.6.3", default-features = false, features = [
activitypub_federation = { version = "0.6.4", default-features = false, features = [
"actix-web",
] }
diesel = { version = "2.2.7", features = [
Expand Down Expand Up @@ -166,6 +166,7 @@ clap = { version = "4.5.29", features = ["derive", "env"] }
pretty_assertions = "1.4.1"
derive-new = "0.7.0"
tuplex = "0.1.2"
either = "1.15.0"

[dependencies]
lemmy_api = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportRespons
import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport";
import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
import { CommunityReportResponse } from "lemmy-js-client/dist/types/CommunityReportResponse";
import { CreateCommunityReport } from "lemmy-js-client/dist/types/CreateCommunityReport";
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
Expand Down Expand Up @@ -797,6 +799,18 @@ export async function reportPost(
return api.createPostReport(form);
}

export async function reportCommunity(
api: LemmyHttp,
community_id: number,
reason: string,
): Promise<CommunityReportResponse> {
let form: CreateCommunityReport = {
community_id,
reason,
};
return api.createCommunityReport(form);
}

export async function listReports(
api: LemmyHttp,
show_community_rule_violations: boolean = false,
Expand Down
1 change: 1 addition & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ hound = "3.5.1"
sitemap-rs = "0.2.2"
totp-rs = { version = "5.6.0", features = ["gen_secret", "otpauth"] }
diesel-async = { workspace = true, features = ["deadpool", "postgres"] }
either = { workspace = true }

[dev-dependencies]
serial_test = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/reports/comment_report/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::check_report_reason;
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::comment::{CommentReportResponse, CreateCommentReport},
Expand Down Expand Up @@ -75,7 +76,7 @@ pub async fn create_comment_report(
SendActivityData::CreateReport {
object_id: comment_view.comment.ap_id.inner().clone(),
actor: local_user_view.person,
community: comment_view.community,
receiver: Either::Right(comment_view.community),
reason: data.reason.clone(),
},
&context,
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/reports/comment_report/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::comment::{CommentReportResponse, ResolveCommentReport},
Expand Down Expand Up @@ -44,7 +45,7 @@ pub async fn resolve_comment_report(
object_id: comment_report_view.comment.ap_id.inner().clone(),
actor: local_user_view.person,
report_creator: report.creator,
community: comment_report_view.community.clone(),
receiver: Either::Right(comment_report_view.community.clone()),
},
&context,
)?;
Expand Down
17 changes: 15 additions & 2 deletions crates/api/src/reports/community_report/create.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::check_report_reason;
use actix_web::web::{Data, Json};
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::community::{CommunityReportResponse, CreateCommunityReport},
send_activity::{ActivityChannel, SendActivityData},
utils::slur_regex,
};
use lemmy_db_schema::{
source::{
community::Community,
community_report::{CommunityReport, CommunityReportForm},
site::Site,
},
traits::{Crud, Reportable},
};
Expand All @@ -28,6 +32,7 @@ pub async fn create_community_report(
let person_id = local_user_view.person.id;
let community_id = data.community_id;
let community = Community::read(&mut context.pool(), community_id).await?;
let site = Site::read_from_instance_id(&mut context.pool(), community.instance_id).await?;

let report_form = CommunityReportForm {
creator_id: person_id,
Expand Down Expand Up @@ -61,7 +66,15 @@ pub async fn create_community_report(
.await?;
}

// TODO: consider federating this
ActivityChannel::submit_activity(
SendActivityData::CreateReport {
object_id: community.ap_id.inner().clone(),
actor: local_user_view.person,
receiver: Either::Left(site),
reason: data.reason.clone(),
},
&context,
)?;

Ok(Json(CommunityReportResponse {
community_report_view,
Expand Down
25 changes: 23 additions & 2 deletions crates/api/src/reports/community_report/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use actix_web::web::{Data, Json};
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::community::{CommunityReportResponse, ResolveCommunityReport},
send_activity::{ActivityChannel, SendActivityData},
utils::is_admin,
};
use lemmy_db_schema::{source::community_report::CommunityReport, traits::Reportable};
use lemmy_db_schema::{
source::{community_report::CommunityReport, site::Site},
traits::Reportable,
};
use lemmy_db_views::structs::{CommunityReportView, LocalUserView};
use lemmy_utils::error::LemmyResult;

Expand All @@ -25,6 +31,21 @@ pub async fn resolve_community_report(

let community_report_view =
CommunityReportView::read(&mut context.pool(), report_id, person_id).await?;
let site = Site::read_from_instance_id(
&mut context.pool(),
community_report_view.community.instance_id,
)
.await?;

ActivityChannel::submit_activity(
SendActivityData::SendResolveReport {
object_id: community_report_view.community.ap_id.inner().clone(),
actor: local_user_view.person,
report_creator: community_report_view.creator.clone(),
receiver: Either::Left(site),
},
&context,
)?;

Ok(Json(CommunityReportResponse {
community_report_view,
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/reports/post_report/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::check_report_reason;
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::post::{CreatePostReport, PostReportResponse},
Expand Down Expand Up @@ -65,7 +66,7 @@ pub async fn create_post_report(
SendActivityData::CreateReport {
object_id: post_view.post.ap_id.inner().clone(),
actor: local_user_view.person,
community: post_view.community,
receiver: Either::Right(post_view.community),
reason: data.reason.clone(),
},
&context,
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/reports/post_report/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use activitypub_federation::config::Data;
use actix_web::web::Json;
use either::Either;
use lemmy_api_common::{
context::LemmyContext,
reports::post::{PostReportResponse, ResolvePostReport},
Expand Down Expand Up @@ -42,7 +43,7 @@ pub async fn resolve_post_report(
object_id: post_report_view.post.ap_id.inner().clone(),
actor: local_user_view.person,
report_creator: report.creator,
community: post_report_view.community.clone(),
receiver: Either::Right(post_report_view.community.clone()),
},
&context,
)?;
Expand Down
1 change: 1 addition & 0 deletions crates/api_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ webmention = { version = "0.6.0", optional = true }
extism = { git = "https://github.com/extism/extism.git", branch = "pool", optional = true }
extism-convert = { git = "https://github.com/extism/extism.git", branch = "pool", optional = true }
once_cell = { version = "1.21.0", optional = true }
either = { workspace = true }

[dev-dependencies]
serial_test = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions crates/api_common/src/send_activity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{community::BanFromCommunity, context::LemmyContext, post::DeletePost};
use activitypub_federation::config::Data;
use either::Either;
use futures::future::BoxFuture;
use lemmy_db_schema::{
newtypes::{CommunityId, DbUrl, PersonId},
Expand All @@ -9,6 +10,7 @@ use lemmy_db_schema::{
person::Person,
post::Post,
private_message::PrivateMessage,
site::Site,
},
};
use lemmy_db_views::structs::PrivateMessageView;
Expand Down Expand Up @@ -96,14 +98,14 @@ pub enum SendActivityData {
CreateReport {
object_id: Url,
actor: Person,
community: Community,
receiver: Either<Site, Community>,
reason: String,
},
SendResolveReport {
object_id: Url,
actor: Person,
report_creator: Person,
community: Community,
receiver: Either<Site, Community>,
},
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ html2text = "0.14.0"
stringreader = "0.1.1"
enum_delegate = "0.2.0"
semver = "1.0.25"
either = "1.15.0"
either = { workspace = true }

[dev-dependencies]
serial_test = { workspace = true }
Expand Down
23 changes: 16 additions & 7 deletions crates/apub/src/activities/community/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::{
activities::send_lemmy_activity,
activity_lists::AnnouncableActivities,
fetcher::PostOrComment,
fetcher::{PostOrComment, ReportableObjects},
objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson},
protocol::activities::community::announce::AnnounceActivity,
};
use activitypub_federation::{config::Data, fetch::object_id::ObjectId, traits::Actor};
use either::Either;
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
source::{
Expand Down Expand Up @@ -79,14 +80,14 @@ pub(crate) async fn send_activity_in_community(
}

async fn report_inboxes(
object_id: ObjectId<PostOrComment>,
community: &ApubCommunity,
object_id: ObjectId<ReportableObjects>,
receiver: &Either<ApubSite, ApubCommunity>,
context: &Data<LemmyContext>,
) -> LemmyResult<ActivitySendTargets> {
// send report to the community where object was posted
let mut inboxes = ActivitySendTargets::to_inbox(community.shared_inbox_or_inbox());
let mut inboxes = ActivitySendTargets::to_inbox(receiver.shared_inbox_or_inbox());

if community.local {
if let Some(community) = local_community(receiver) {
// send to all moderators
let moderators =
CommunityModeratorView::for_community(&mut context.pool(), community.id).await?;
Expand All @@ -96,8 +97,9 @@ async fn report_inboxes(

// also send report to user's home instance if possible
let object_creator_id = match object_id.dereference_local(context).await? {
PostOrComment::Left(p) => p.creator_id,
PostOrComment::Right(c) => c.creator_id,
ReportableObjects::Left(PostOrComment::Left(p)) => p.creator_id,
ReportableObjects::Left(PostOrComment::Right(c)) => c.creator_id,
_ => return Ok(inboxes),
};
let object_creator = Person::read(&mut context.pool(), object_creator_id).await?;
let object_creator_site: Option<ApubSite> =
Expand All @@ -111,3 +113,10 @@ async fn report_inboxes(
}
Ok(inboxes)
}

fn local_community(site_or_community: &Either<ApubSite, ApubCommunity>) -> Option<&ApubCommunity> {
match site_or_community {
Either::Right(c) if c.local => Some(c),
_ => None,
}
}
Loading