Skip to content

Commit

Permalink
match reported objects to known actors
Browse files Browse the repository at this point in the history
more will come later
  • Loading branch information
Floppy committed Nov 29, 2024
1 parent a13f21d commit d567d4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/services/federails/moderation/report_creation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand All @@ -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
3 changes: 1 addition & 2 deletions spec/requests/reports_spec.rb
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
]
} }

Expand Down
9 changes: 7 additions & 2 deletions spec/services/report_creation_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
]
} }

Expand All @@ -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
Expand Down

0 comments on commit d567d4c

Please sign in to comment.