Allow users with group_locked_trust_level to be promoted to tl3 (#6249)

This commit is contained in:
Simon Cossar 2018-08-09 17:42:23 -07:00 committed by Sam
parent 0d5ebcb21d
commit 3cd4dc0f5f
2 changed files with 33 additions and 5 deletions

View File

@ -8,9 +8,8 @@ module Jobs
demoted_user_ids = [] demoted_user_ids = []
User.real.where( User.real.where(
trust_level: TrustLevel[3], trust_level: TrustLevel[3],
manual_locked_trust_level: nil, manual_locked_trust_level: nil
group_locked_trust_level: nil ).where("group_locked_trust_level IS NULL OR group_locked_trust_level < ?", TrustLevel[3]).find_each do |u|
).find_each do |u|
# Don't demote too soon after being promoted # Don't demote too soon after being promoted
next if u.on_tl3_grace_period? next if u.on_tl3_grace_period?
@ -23,8 +22,7 @@ module Jobs
# Promotions # Promotions
User.real.not_suspended.where( User.real.not_suspended.where(
trust_level: TrustLevel[2], trust_level: TrustLevel[2],
manual_locked_trust_level: nil, manual_locked_trust_level: nil
group_locked_trust_level: nil
).where.not(id: demoted_user_ids) ).where.not(id: demoted_user_ids)
.joins(:user_stat) .joins(:user_stat)
.where("user_stats.days_visited >= ?", SiteSetting.tl3_requires_days_visited) .where("user_stats.days_visited >= ?", SiteSetting.tl3_requires_days_visited)

View File

@ -24,6 +24,14 @@ describe Jobs::Tl3Promotions do
run_job run_job
end end
it "promotes a qualifying tl2 user who has a group_locked_trust_level" do
_group_locked_user = Fabricate(:user, trust_level: TrustLevel[2], group_locked_trust_level: TrustLevel[1])
create_qualifying_stats(_group_locked_user)
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
Promotion.any_instance.expects(:change_trust_level!).with(TrustLevel[3], anything).once
run_job
end
it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do
_tl1_user = Fabricate(:user, trust_level: TrustLevel[1]) _tl1_user = Fabricate(:user, trust_level: TrustLevel[1])
_tl0_user = Fabricate(:user, trust_level: TrustLevel[0]) _tl0_user = Fabricate(:user, trust_level: TrustLevel[0])
@ -83,5 +91,27 @@ describe Jobs::Tl3Promotions do
expect(user.reload.trust_level).to eq(TrustLevel[3]) expect(user.reload.trust_level).to eq(TrustLevel[3])
end end
it "demotes a user with a group_locked_trust_level of 2" do
user = nil
freeze_time(4.days.ago) do
user = Fabricate(:user, trust_level: TrustLevel[3], group_locked_trust_level: TrustLevel[2])
end
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
run_job
expect(user.reload.trust_level).to eq(TrustLevel[2])
end
it "doesn't demote user if their group_locked_trust_level is 3" do
user = nil
freeze_time(4.days.ago) do
user = Fabricate(:user, trust_level: TrustLevel[3], group_locked_trust_level: TrustLevel[3])
end
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
run_job
expect(user.reload.trust_level).to eq(TrustLevel[3])
end
end end
end end