From d567d4cfb6a01628d2c32c259767f8fbef4eee42 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 29 Nov 2024 12:38:06 +0000 Subject: [PATCH] match reported objects to known actors more will come later --- .../moderation/report_creation_service.rb | 15 +++++++++++++++ spec/requests/reports_spec.rb | 3 +-- spec/services/report_creation_service_spec.rb | 9 +++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/services/federails/moderation/report_creation_service.rb b/app/services/federails/moderation/report_creation_service.rb index 8ae6dde..597ad62 100644 --- a/app/services/federails/moderation/report_creation_service.rb +++ b/app/services/federails/moderation/report_creation_service.rb @@ -8,6 +8,7 @@ def initialize(activity) def call Report.create!( federails_actor: find_reporter, + object: find_objects.first, federated_url: @activity["id"], content: @activity["content"] ) @@ -21,5 +22,19 @@ def find_reporter # Anonymous reports will try to create invalid actors, so we end up here nil end + + def find_objects + objects = Array(@activity["object"]).map { |url| + begin + # Find reported actors + Federails::Actor.find_by_federation_url(url) + # Other objects could be here too, but they will come later + rescue ActiveRecord::RecordNotFound + nil + end + }.compact + Rails.logger.warn "Federails::Moderation cannot currently handle multiple objects in a single report, only the first has been logged" if objects.length > 1 + objects + end end end diff --git a/spec/requests/reports_spec.rb b/spec/requests/reports_spec.rb index 1610890..b3b19a4 100644 --- a/spec/requests/reports_spec.rb +++ b/spec/requests/reports_spec.rb @@ -1,6 +1,5 @@ RSpec.describe "Reports" do let(:user) { create :user } - let(:object) { create :note } let(:actor) { create :distant_actor } let(:valid_activity) { { "@context" => "https://www.w3.org/ns/activitystreams", @@ -9,7 +8,7 @@ "actor" => actor.federated_url, "content" => "I don't like spiders", "object" => [ - "http://localhost:3000/notes/#{object.to_param}" + user.federails_actor.federated_url ] } } diff --git a/spec/services/report_creation_service_spec.rb b/spec/services/report_creation_service_spec.rb index c5e4e61..92e5804 100644 --- a/spec/services/report_creation_service_spec.rb +++ b/spec/services/report_creation_service_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Federails::Moderation::ReportCreationService do - let(:object) { create :note } + let(:object) { create(:user).federails_actor } let(:actor) { create :distant_actor } let(:valid_activity) { { "@context" => "https://www.w3.org/ns/activitystreams", @@ -8,7 +8,8 @@ "actor" => actor.federated_url, "content" => "I don't like spiders", "object" => [ - "http://localhost:3000/notes/#{object.to_param}" + object.federated_url, + "https://localhost/unknown/object" ] } } @@ -30,6 +31,10 @@ it "associates report with actor" do expect(report.federails_actor).to eq actor end + + it "associates report with object" do + expect(report.object).to eq object + end end context "with anonymous report" do