diff --git a/app/models/account.rb b/app/models/account.rb index fd99dc3b18..0e80b99d8d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -469,8 +469,11 @@ class Account < ApplicationRecord save! end - def featureable? - local? && discoverable? + def featureable_by?(other_account) + return discoverable? if local? + return false unless Mastodon::Feature.collections_federation_enabled? + + feature_policy_for_account(other_account).in?(%i(automatic manual)) end private diff --git a/app/policies/account_policy.rb b/app/policies/account_policy.rb index 1fef35714c..c46eb08034 100644 --- a/app/policies/account_policy.rb +++ b/app/policies/account_policy.rb @@ -66,7 +66,7 @@ class AccountPolicy < ApplicationPolicy end def feature? - record.featureable? && !current_account.blocking?(record) && !current_account.blocked_by?(record) + record.featureable_by?(current_account) && !current_account.blocking?(record) && !current_account.blocked_by?(record) end def index_collections? diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index ca85b0fbfc..2fd32d1361 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -790,17 +790,20 @@ RSpec.describe Account do end end - describe '#featureable?' do - subject { Fabricate.build(:account, domain: (local ? nil : 'example.com'), discoverable:) } + describe '#featureable_by?' do + subject { Fabricate.build(:account, domain: (local ? nil : 'example.com'), discoverable:, feature_approval_policy:) } + + let(:local_account) { Fabricate(:account) } context 'when account is local' do let(:local) { true } + let(:feature_approval_policy) { nil } context 'when account is discoverable' do let(:discoverable) { true } it 'returns `true`' do - expect(subject.featureable?).to be true + expect(subject.featureable_by?(local_account)).to be true end end @@ -808,7 +811,7 @@ RSpec.describe Account do let(:discoverable) { false } it 'returns `false`' do - expect(subject.featureable?).to be false + expect(subject.featureable_by?(local_account)).to be false end end end @@ -816,9 +819,26 @@ RSpec.describe Account do context 'when account is remote' do let(:local) { false } let(:discoverable) { true } + let(:feature_approval_policy) { (0b10 << 16) | 0 } it 'returns `false`' do - expect(subject.featureable?).to be false + expect(subject.featureable_by?(local_account)).to be false + end + + context 'when collections federation is enabled', feature: :collections_federation do + context 'when the policy allows it' do + it 'returns `true`' do + expect(subject.featureable_by?(local_account)).to be true + end + end + + context 'when the policy forbids it' do + let(:feature_approval_policy) { 0 } + + it 'returns `false`' do + expect(subject.featureable_by?(local_account)).to be false + end + end end end end diff --git a/spec/policies/account_policy_spec.rb b/spec/policies/account_policy_spec.rb index 96fcbdb4d8..2f350bc092 100644 --- a/spec/policies/account_policy_spec.rb +++ b/spec/policies/account_policy_spec.rb @@ -165,7 +165,7 @@ RSpec.describe AccountPolicy do end context 'when account is not featureable' do - before { allow(alice).to receive(:featureable?).and_return(false) } + before { allow(alice).to receive(:featureable_by?).and_return(false) } it 'denies' do expect(subject).to_not permit(john, alice)