mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Allow remote accounts in Collections (#37989)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user