Fix ActivityPub::Activity::Create trying to re-create known statuses when author changes (#39916)

This commit is contained in:
Claire
2026-07-22 16:29:39 +02:00
parent 554bde91ef
commit f3567797bf
2 changed files with 29 additions and 2 deletions

View File

@@ -33,6 +33,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
if @status.nil?
process_status
elsif @status.account_id != @account.id
Rails.logger.debug { "Not processing #{object_uri}: authorship change is not supported" }
return reject_payload!
elsif @options[:delivered_to_account_id].present?
postprocess_audience_and_deliver
end
@@ -84,7 +87,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def find_existing_status
status = status_from_uri(object_uri)
status ||= Status.find_by(uri: @object['atomUri']) if @object['atomUri'].present?
status if status&.account_id == @account.id
status
end
def process_status_params

View File

@@ -448,6 +448,30 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'when the status is already known' do
let(:recipient) { Fabricate(:account) }
let(:object_json) do
build_object(
to: ActivityPub::TagManager.instance.uri_for(recipient)
)
end
let!(:status) { Fabricate(:status, uri: object_json[:id], account: sender, text: object_json[:content]) }
it 'keeps the status intact' do
expect(subject.perform).to eq status
end
context 'when the known status is attributed to a different actor' do
let(:status) { Fabricate(:status, uri: object_json[:id], account: Fabricate(:account, domain: 'example.com')) }
it 'returns nil' do
expect(subject.perform).to be_nil
end
end
end
context 'when direct' do
let(:recipient) { Fabricate(:account) }
@@ -1335,7 +1359,7 @@ RSpec.describe ActivityPub::Activity::Create do
def build_object(options = {})
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
id: [ActivityPub::TagManager.instance.uri_for(sender), '/bar'].join,
type: 'Note',
content: 'Lorem ipsum',
}.merge(options)