Handle Remove activity on featuredCollections (#38169)
This commit is contained in:
parent
13c94db9e7
commit
353c8b2abf
@ -12,6 +12,8 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||||||
else
|
else
|
||||||
remove_featured
|
remove_featured
|
||||||
end
|
end
|
||||||
|
when @account.collections_url
|
||||||
|
remove_collection
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,4 +36,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||||||
featured_tag = FeaturedTag.by_name(name).find_by(account: @account)
|
featured_tag = FeaturedTag.by_name(name).find_by(account: @account)
|
||||||
featured_tag&.destroy!
|
featured_tag&.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_collection
|
||||||
|
collection = @account.collections.find_by(uri: value_or_id(@object))
|
||||||
|
|
||||||
|
collection&.destroy!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,11 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ActivityPub::Activity::Remove do
|
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
|
describe '#perform' do
|
||||||
subject { described_class.new(json, sender) }
|
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)
|
.to change { sender.featured_tags.exists?(tag: tag) }.to(false)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user