Allow remote accounts in Collections (#37989)
This commit is contained in:
parent
970ac04be7
commit
51b81b3ce9
@ -469,8 +469,11 @@ class Account < ApplicationRecord
|
|||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def featureable?
|
def featureable_by?(other_account)
|
||||||
local? && discoverable?
|
return discoverable? if local?
|
||||||
|
return false unless Mastodon::Feature.collections_federation_enabled?
|
||||||
|
|
||||||
|
feature_policy_for_account(other_account).in?(%i(automatic manual))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -66,7 +66,7 @@ class AccountPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def feature?
|
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
|
end
|
||||||
|
|
||||||
def index_collections?
|
def index_collections?
|
||||||
|
|||||||
@ -790,17 +790,20 @@ RSpec.describe Account do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#featureable?' do
|
describe '#featureable_by?' do
|
||||||
subject { Fabricate.build(:account, domain: (local ? nil : 'example.com'), discoverable:) }
|
subject { Fabricate.build(:account, domain: (local ? nil : 'example.com'), discoverable:, feature_approval_policy:) }
|
||||||
|
|
||||||
|
let(:local_account) { Fabricate(:account) }
|
||||||
|
|
||||||
context 'when account is local' do
|
context 'when account is local' do
|
||||||
let(:local) { true }
|
let(:local) { true }
|
||||||
|
let(:feature_approval_policy) { nil }
|
||||||
|
|
||||||
context 'when account is discoverable' do
|
context 'when account is discoverable' do
|
||||||
let(:discoverable) { true }
|
let(:discoverable) { true }
|
||||||
|
|
||||||
it 'returns `true`' do
|
it 'returns `true`' do
|
||||||
expect(subject.featureable?).to be true
|
expect(subject.featureable_by?(local_account)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -808,7 +811,7 @@ RSpec.describe Account do
|
|||||||
let(:discoverable) { false }
|
let(:discoverable) { false }
|
||||||
|
|
||||||
it 'returns `false`' do
|
it 'returns `false`' do
|
||||||
expect(subject.featureable?).to be false
|
expect(subject.featureable_by?(local_account)).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -816,9 +819,26 @@ RSpec.describe Account do
|
|||||||
context 'when account is remote' do
|
context 'when account is remote' do
|
||||||
let(:local) { false }
|
let(:local) { false }
|
||||||
let(:discoverable) { true }
|
let(:discoverable) { true }
|
||||||
|
let(:feature_approval_policy) { (0b10 << 16) | 0 }
|
||||||
|
|
||||||
it 'returns `false`' do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -165,7 +165,7 @@ RSpec.describe AccountPolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when account is not featureable' do
|
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
|
it 'denies' do
|
||||||
expect(subject).to_not permit(john, alice)
|
expect(subject).to_not permit(john, alice)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user