Handle Remove activity on featuredCollections (#38169)

This commit is contained in:
David Roetzel
2026-03-12 11:37:53 +01:00
committed by GitHub
parent 13c94db9e7
commit 353c8b2abf
2 changed files with 37 additions and 1 deletions

View File

@@ -12,6 +12,8 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
else
remove_featured
end
when @account.collections_url
remove_collection
end
end
@@ -34,4 +36,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
featured_tag = FeaturedTag.by_name(name).find_by(account: @account)
featured_tag&.destroy!
end
def remove_collection
collection = @account.collections.find_by(uri: value_or_id(@object))
collection&.destroy!
end
end

View File

@@ -3,7 +3,11 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Remove do
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
let(:sender) do
Fabricate(:remote_account,
featured_collection_url: 'https://example.com/featured',
collections_url: 'https://example.com/actor/1/featured_collections')
end
describe '#perform' do
subject { described_class.new(json, sender) }
@@ -59,5 +63,29 @@ RSpec.describe ActivityPub::Activity::Remove do
.to change { sender.featured_tags.exists?(tag: tag) }.to(false)
end
end
context 'when removing a featured collection' do
let(:collection) { Fabricate(:remote_collection, account: sender) }
let(:json) do
{
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => 'foo',
'type' => 'Remove',
'actor' => ActivityPub::TagManager.instance.uri_for(sender),
'object' => collection.uri,
'target' => sender.collections_url,
}
end
before do
Fabricate(:collection_item, collection:, uri: 'https://example.com/featured_items/1')
end
it 'deletes the collection' do
expect { subject.perform }
.to change(sender.collections, :count).by(-1)
.and change(CollectionItem, :count).by(-1)
end
end
end
end