FEATURE: Add site setting to restrict ignore feature to trust level (#11297)

This adds a new min_trust_level_to_allow_ignore site setting that enables admins to control the point at which a user is allowed to ignore other users.
This commit is contained in:
tshenry
2020-11-20 10:05:20 -08:00
committed by GitHub
parent 1ea6bbab34
commit 0ec62358d9
4 changed files with 23 additions and 13 deletions

View File

@@ -2960,6 +2960,9 @@ describe Guardian do
end
describe '#can_ignore_user?' do
before do
SiteSetting.min_trust_level_to_allow_ignore = 1
end
let(:guardian) { Guardian.new(trust_level_2) }
@@ -2983,26 +2986,29 @@ describe Guardian do
end
end
context "when ignorer's trust level is below tl2" do
let(:guardian) { Guardian.new(trust_level_1) }
let!(:trust_level_1) { build(:user, trust_level: 1) }
it 'does not allow ignoring user' do
expect(guardian.can_ignore_user?(another_user)).to eq(false)
end
end
context "when ignorer is staff" do
let(:guardian) { Guardian.new(admin) }
it 'allows ignoring user' do
expect(guardian.can_ignore_user?(another_user)).to eq(true)
end
end
context "when ignorer's trust level is tl2" do
let(:guardian) { Guardian.new(trust_level_2) }
context "when ignorer's trust level is below min_trust_level_to_allow_ignore" do
let(:guardian) { Guardian.new(trust_level_0) }
it 'does not allow ignoring user' do
expect(guardian.can_ignore_user?(another_user)).to eq(false)
end
end
context "when ignorer's trust level is equal to min_trust_level_to_allow_ignore site setting" do
let(:guardian) { Guardian.new(trust_level_1) }
it 'allows ignoring user' do
expect(guardian.can_ignore_user?(another_user)).to eq(true)
end
end
context "when ignorer's trust level is above min_trust_level_to_allow_ignore site setting" do
let(:guardian) { Guardian.new(trust_level_3) }
it 'allows ignoring user' do
expect(guardian.can_ignore_user?(another_user)).to eq(true)
end