Prefer to_json in self destruct scheduler (#38263)

This commit is contained in:
Matt Jankowski
2026-03-18 09:21:03 -04:00
committed by GitHub
parent d52d0e4ded
commit e537292e2a
2 changed files with 17 additions and 7 deletions

View File

@@ -55,13 +55,10 @@ class Scheduler::SelfDestructScheduler
end
def delete_account!(account)
payload = ActiveModelSerializers::SerializableResource.new(
account,
serializer: ActivityPub::DeleteActorSerializer,
adapter: ActivityPub::Adapter
).as_json
json = JSON.generate(ActivityPub::LinkedDataSignature.new(payload).sign!(account))
json = ActivityPub::LinkedDataSignature
.new(deletion_payload(account))
.sign!(account)
.to_json
ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url|
[json, account.id, inbox_url]
@@ -70,4 +67,12 @@ class Scheduler::SelfDestructScheduler
# Do not call `Account#suspend!` because we don't want to issue a deletion request
account.update!(suspended_at: Time.now.utc, suspension_origin: :local)
end
def deletion_payload(account)
ActiveModelSerializers::SerializableResource.new(
account,
serializer: ActivityPub::DeleteActorSerializer,
adapter: ActivityPub::Adapter
).as_json
end
end

View File

@@ -39,6 +39,8 @@ RSpec.describe Scheduler::SelfDestructScheduler do
end
context 'when sidekiq is operational' do
let!(:other_account) { Fabricate :account, inbox_url: 'https://host.example/inbox', domain: 'host.example', protocol: :activitypub }
it 'suspends local non-suspended accounts' do
worker.perform
@@ -51,6 +53,9 @@ RSpec.describe Scheduler::SelfDestructScheduler do
worker.perform
expect(ActivityPub::DeliveryWorker)
.to have_enqueued_sidekiq_job(match_json_values(type: 'Delete', signature: be_present), account.id, other_account.inbox_url)
expect(account.reload.suspended_at).to be > 1.day.ago
expect { deletion_request.reload }.to raise_error(ActiveRecord::RecordNotFound)
end