FIX: don't demote users to TL2 when default trust level is 3

Within 24 hours of signing up, new users were losing their
default trust level of 3. With this fix, demotions from
trust level 3 won't happen when the "default trust level"
setting is 3 or 4.
This commit is contained in:
Neil Lalonde 2020-04-16 12:28:16 -04:00
parent 1168d5c70a
commit 074509fd95
No known key found for this signature in database
GPG Key ID: FF871CA9037D0A91
4 changed files with 35 additions and 15 deletions

View File

@ -6,6 +6,7 @@ module Jobs
daily at: 4.hours
def execute(args)
if SiteSetting.default_trust_level < 3
# Demotions
demoted_user_ids = []
User.real
@ -24,6 +25,7 @@ module Jobs
Promotion.new(u).change_trust_level!(TrustLevel[2])
end
end
end
# Promotions
User.real.not_suspended.where(

View File

@ -67,6 +67,7 @@ class TrustLevel3Requirements
def requirements_lost?
return false if trust_level_locked
return false if SiteSetting.default_trust_level > 2
@user.suspended? ||
@user.silenced? ||

View File

@ -135,5 +135,14 @@ describe Jobs::Tl3Promotions do
run_job
expect(user.reload.trust_level).to eq(TrustLevel[3])
end
it "doesn't demote if default trust level for all users is 3" do
SiteSetting.default_trust_level = 3
user = Fabricate(:user, trust_level: TrustLevel[3], created_at: 1.year.ago)
expect(user).to_not be_on_tl3_grace_period
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
run_job
expect(user.reload.trust_level).to eq(TrustLevel[3])
end
end
end

View File

@ -586,6 +586,14 @@ describe TrustLevel3Requirements do
user.silenced_till = 4.weeks.from_now
expect(tl3_requirements.requirements_lost?).to eq(true)
end
[3, 4].each do |default_tl|
it "is not lost if default_trust_level is #{default_tl}" do
SiteSetting.default_trust_level = default_tl
tl3_requirements.stubs(:days_visited).returns(1)
expect(tl3_requirements.requirements_lost?).to eq(false)
end
end
end
end