mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
Handle Remove of an individual collection item (#38170)
This commit is contained in:
parent
420136e83b
commit
eeed483518
|
|
@ -14,6 +14,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||
end
|
||||
when @account.collections_url
|
||||
remove_collection
|
||||
else
|
||||
@collection = @account.collections.find_by(uri: @json['target'])
|
||||
|
||||
remove_collection_item if @collection
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -42,4 +46,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||
|
||||
collection&.destroy!
|
||||
end
|
||||
|
||||
def remove_collection_item
|
||||
collection_item = @collection.collection_items.find_by(uri: value_or_id(@object))
|
||||
|
||||
collection_item&.destroy!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -87,5 +87,27 @@ RSpec.describe ActivityPub::Activity::Remove do
|
|||
.and change(CollectionItem, :count).by(-1)
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user