From c82f23d75f9be3d44fc2d38a2173baa29f74eabd Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Thu, 1 Oct 2026 09:30:44 +0000 Subject: [PATCH] Fix FASP Subscriptions when capability is disabled (#40787) --- app/models/fasp/subscription.rb | 1 + .../announce_account_lifecycle_event_worker.rb | 2 +- .../announce_content_lifecycle_event_worker.rb | 2 +- app/workers/fasp/announce_trend_worker.rb | 2 +- spec/fabricators/fasp/provider_fabricator.rb | 9 +++++++++ ...announce_account_lifecycle_event_worker_spec.rb | 14 +++++++++++++- ...announce_content_lifecycle_event_worker_spec.rb | 14 +++++++++++++- spec/workers/fasp/announce_trend_worker_spec.rb | 14 +++++++++++++- 8 files changed, 52 insertions(+), 6 deletions(-) diff --git a/app/models/fasp/subscription.rb b/app/models/fasp/subscription.rb index e2e554ed74d..3ff19d162ca 100644 --- a/app/models/fasp/subscription.rb +++ b/app/models/fasp/subscription.rb @@ -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 diff --git a/app/workers/fasp/announce_account_lifecycle_event_worker.rb b/app/workers/fasp/announce_account_lifecycle_event_worker.rb index fc7fb235ea4..539716dbfbb 100644 --- a/app/workers/fasp/announce_account_lifecycle_event_worker.rb +++ b/app/workers/fasp/announce_account_lifecycle_event_worker.rb @@ -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 diff --git a/app/workers/fasp/announce_content_lifecycle_event_worker.rb b/app/workers/fasp/announce_content_lifecycle_event_worker.rb index d4450a8aece..b987a54bbdf 100644 --- a/app/workers/fasp/announce_content_lifecycle_event_worker.rb +++ b/app/workers/fasp/announce_content_lifecycle_event_worker.rb @@ -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 diff --git a/app/workers/fasp/announce_trend_worker.rb b/app/workers/fasp/announce_trend_worker.rb index dc1d94a2712..776a1d56669 100644 --- a/app/workers/fasp/announce_trend_worker.rb +++ b/app/workers/fasp/announce_trend_worker.rb @@ -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 diff --git a/spec/fabricators/fasp/provider_fabricator.rb b/spec/fabricators/fasp/provider_fabricator.rb index e04aa179a2a..2c01afb18e8 100644 --- a/spec/fabricators/fasp/provider_fabricator.rb +++ b/spec/fabricators/fasp/provider_fabricator.rb @@ -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 diff --git a/spec/workers/fasp/announce_account_lifecycle_event_worker_spec.rb b/spec/workers/fasp/announce_account_lifecycle_event_worker_spec.rb index 9d4457d5e3e..0418af1259d 100644 --- a/spec/workers/fasp/announce_account_lifecycle_event_worker_spec.rb +++ b/spec/workers/fasp/announce_account_lifecycle_event_worker_spec.rb @@ -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 diff --git a/spec/workers/fasp/announce_content_lifecycle_event_worker_spec.rb b/spec/workers/fasp/announce_content_lifecycle_event_worker_spec.rb index b655b0be2ee..f995d8a1570 100644 --- a/spec/workers/fasp/announce_content_lifecycle_event_worker_spec.rb +++ b/spec/workers/fasp/announce_content_lifecycle_event_worker_spec.rb @@ -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 diff --git a/spec/workers/fasp/announce_trend_worker_spec.rb b/spec/workers/fasp/announce_trend_worker_spec.rb index 64eea7f03cb..7b6343ca1bf 100644 --- a/spec/workers/fasp/announce_trend_worker_spec.rb +++ b/spec/workers/fasp/announce_trend_worker_spec.rb @@ -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