mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Handle Remove activity on featuredCollections (#38169)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user