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:
parent
1168d5c70a
commit
074509fd95
|
@ -6,22 +6,24 @@ module Jobs
|
|||
daily at: 4.hours
|
||||
|
||||
def execute(args)
|
||||
# Demotions
|
||||
demoted_user_ids = []
|
||||
User.real
|
||||
.joins("LEFT JOIN (SELECT gu.user_id, MAX(g.grant_trust_level) AS group_granted_trust_level FROM groups g, group_users gu WHERE g.id = gu.group_id GROUP BY gu.user_id) tl ON users.id = tl.user_id")
|
||||
.where(
|
||||
trust_level: TrustLevel[3],
|
||||
manual_locked_trust_level: nil
|
||||
)
|
||||
.where("group_granted_trust_level IS NULL OR group_granted_trust_level < ?", TrustLevel[3])
|
||||
.find_each do |u|
|
||||
# Don't demote too soon after being promoted
|
||||
next if u.on_tl3_grace_period?
|
||||
if SiteSetting.default_trust_level < 3
|
||||
# Demotions
|
||||
demoted_user_ids = []
|
||||
User.real
|
||||
.joins("LEFT JOIN (SELECT gu.user_id, MAX(g.grant_trust_level) AS group_granted_trust_level FROM groups g, group_users gu WHERE g.id = gu.group_id GROUP BY gu.user_id) tl ON users.id = tl.user_id")
|
||||
.where(
|
||||
trust_level: TrustLevel[3],
|
||||
manual_locked_trust_level: nil
|
||||
)
|
||||
.where("group_granted_trust_level IS NULL OR group_granted_trust_level < ?", TrustLevel[3])
|
||||
.find_each do |u|
|
||||
# Don't demote too soon after being promoted
|
||||
next if u.on_tl3_grace_period?
|
||||
|
||||
if Promotion.tl3_lost?(u)
|
||||
demoted_user_ids << u.id
|
||||
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
||||
if Promotion.tl3_lost?(u)
|
||||
demoted_user_ids << u.id
|
||||
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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? ||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue