mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Handle Remove of an individual collection item (#38170)
This commit is contained in:
@@ -14,6 +14,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||||||
end
|
end
|
||||||
when @account.collections_url
|
when @account.collections_url
|
||||||
remove_collection
|
remove_collection
|
||||||
|
else
|
||||||
|
@collection = @account.collections.find_by(uri: @json['target'])
|
||||||
|
|
||||||
|
remove_collection_item if @collection
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,4 +46,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||||||
|
|
||||||
collection&.destroy!
|
collection&.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_collection_item
|
||||||
|
collection_item = @collection.collection_items.find_by(uri: value_or_id(@object))
|
||||||
|
|
||||||
|
collection_item&.destroy!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -87,5 +87,27 @@ RSpec.describe ActivityPub::Activity::Remove do
|
|||||||
.and change(CollectionItem, :count).by(-1)
|
.and change(CollectionItem, :count).by(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when removing a featured item' do
|
||||||
|
let(:collection) { Fabricate(:remote_collection, account: sender) }
|
||||||
|
let(:collection_item) { Fabricate(:collection_item, collection:, uri: 'https://example.com/featured_items/1') }
|
||||||
|
let(:json) do
|
||||||
|
{
|
||||||
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id' => 'foo',
|
||||||
|
'type' => 'Remove',
|
||||||
|
'actor' => ActivityPub::TagManager.instance.uri_for(sender),
|
||||||
|
'object' => collection_item.uri,
|
||||||
|
'target' => collection.uri,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
before { json }
|
||||||
|
|
||||||
|
it 'deletes the collection item' do
|
||||||
|
expect { subject.perform }
|
||||||
|
.to change(collection.collection_items, :count).by(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user