Fix FASP Subscriptions when capability is disabled (#40787)

This commit is contained in:
David Roetzel
2026-10-01 09:30:44 +00:00
committed by GitHub
parent a0f8661951
commit c82f23d75f
8 changed files with 52 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ class Fasp::Subscription < ApplicationRecord
scope :category_account, -> { where(category: 'account') }
scope :lifecycle, -> { where(subscription_type: 'lifecycle') }
scope :trends, -> { where(subscription_type: 'trends') }
scope :active, -> { joins(fasp_provider: :fasp_capabilities).where(fasp_capabilities: { name: 'data_sharing', enabled: true }) }
def threshold=(threshold)
self.threshold_timeframe = threshold['timeframe'] || 15

View File

@@ -4,7 +4,7 @@ class Fasp::AnnounceAccountLifecycleEventWorker < Fasp::BaseWorker
sidekiq_options retry: 5
def perform(uri, event_type)
Fasp::Subscription.includes(:fasp_provider).category_account.lifecycle.each do |subscription|
Fasp::Subscription.includes(:fasp_provider).active.category_account.lifecycle.each do |subscription|
with_provider(subscription.fasp_provider) do
announce(subscription, uri, event_type)
end

View File

@@ -4,7 +4,7 @@ class Fasp::AnnounceContentLifecycleEventWorker < Fasp::BaseWorker
sidekiq_options retry: 5
def perform(uri, event_type)
Fasp::Subscription.includes(:fasp_provider).category_content.lifecycle.each do |subscription|
Fasp::Subscription.includes(:fasp_provider).active.category_content.lifecycle.each do |subscription|
with_provider(subscription.fasp_provider) do
announce(subscription, uri, event_type)
end

View File

@@ -7,7 +7,7 @@ class Fasp::AnnounceTrendWorker < Fasp::BaseWorker
status = ::Status.includes(:account).find(status_id)
return unless status.account.indexable?
Fasp::Subscription.includes(:fasp_provider).category_content.trends.each do |subscription|
Fasp::Subscription.includes(:fasp_provider).active.category_content.trends.each do |subscription|
with_provider(subscription.fasp_provider) do
announce(subscription, status.uri) if trending?(subscription, status, trend_source)
end

View File

@@ -60,3 +60,12 @@ Fabricator(:account_search_fasp, from: :fasp_provider) do
def fasp.update_remote_capabilities = true
end
end
Fabricator(:data_sharing_fasp, from: :fasp_provider) do
confirmed true
fasp_capabilities do
[
Fabricate.build(:fasp_capability, name: 'data_sharing', enabled: true),
]
end
end

View File

@@ -8,7 +8,7 @@ RSpec.describe Fasp::AnnounceAccountLifecycleEventWorker do
subject { described_class.new.perform(account_uri, 'new') }
let(:account_uri) { 'https://masto.example.com/accounts/1' }
let(:provider) { Fabricate(:confirmed_fasp) }
let(:provider) { Fabricate(:data_sharing_fasp) }
let(:subscription) do
Fabricate(:fasp_subscription, fasp_provider: provider, category: 'account')
end
@@ -43,4 +43,16 @@ RSpec.describe Fasp::AnnounceAccountLifecycleEventWorker do
it_behaves_like('worker handling fasp delivery failures')
end
context 'when `data_sharing` is disabled for provider' do
before do
provider.fasp_capabilities.where(name: 'data_sharing').update_all(enabled: false)
end
it 'does not send anything to the provider' do
subject
expect(stubbed_request).to_not have_been_made
end
end
end

View File

@@ -8,7 +8,7 @@ RSpec.describe Fasp::AnnounceContentLifecycleEventWorker do
subject { described_class.new.perform(status_uri, 'new') }
let(:status_uri) { 'https://masto.example.com/status/1' }
let(:provider) { Fabricate(:confirmed_fasp) }
let(:provider) { Fabricate(:data_sharing_fasp) }
let(:subscription) do
Fabricate(:fasp_subscription, fasp_provider: provider)
end
@@ -43,4 +43,16 @@ RSpec.describe Fasp::AnnounceContentLifecycleEventWorker do
it_behaves_like('worker handling fasp delivery failures')
end
context 'when `data_sharing` is disabled for provider' do
before do
provider.fasp_capabilities.where(name: 'data_sharing').update_all(enabled: false)
end
it 'does not send anything to the provider' do
subject
expect(stubbed_request).to_not have_been_made
end
end
end

View File

@@ -8,7 +8,7 @@ RSpec.describe Fasp::AnnounceTrendWorker do
subject { described_class.new.perform(status.id, 'favourite') }
let(:status) { Fabricate(:status) }
let(:provider) { Fabricate(:confirmed_fasp) }
let(:provider) { Fabricate(:data_sharing_fasp) }
let(:subscription) do
Fabricate(:fasp_subscription,
fasp_provider: provider,
@@ -53,6 +53,18 @@ RSpec.describe Fasp::AnnounceTrendWorker do
it_behaves_like('worker handling fasp delivery failures')
end
context 'when `data_sharing` is disabled for provider' do
before do
provider.fasp_capabilities.where(name: 'data_sharing').update_all(enabled: false)
end
it 'does not send anything to the provider' do
subject
expect(stubbed_request).to_not have_been_made
end
end
end
context 'when the configured threshold is not met' do