mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 02:52:44 +08:00
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
|
daily at: 4.hours
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
# Demotions
|
if SiteSetting.default_trust_level < 3
|
||||||
demoted_user_ids = []
|
# Demotions
|
||||||
User.real
|
demoted_user_ids = []
|
||||||
.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")
|
User.real
|
||||||
.where(
|
.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")
|
||||||
trust_level: TrustLevel[3],
|
.where(
|
||||||
manual_locked_trust_level: nil
|
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|
|
.where("group_granted_trust_level IS NULL OR group_granted_trust_level < ?", TrustLevel[3])
|
||||||
# Don't demote too soon after being promoted
|
.find_each do |u|
|
||||||
next if u.on_tl3_grace_period?
|
# Don't demote too soon after being promoted
|
||||||
|
next if u.on_tl3_grace_period?
|
||||||
|
|
||||||
if Promotion.tl3_lost?(u)
|
if Promotion.tl3_lost?(u)
|
||||||
demoted_user_ids << u.id
|
demoted_user_ids << u.id
|
||||||
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ class TrustLevel3Requirements
|
||||||
|
|
||||||
def requirements_lost?
|
def requirements_lost?
|
||||||
return false if trust_level_locked
|
return false if trust_level_locked
|
||||||
|
return false if SiteSetting.default_trust_level > 2
|
||||||
|
|
||||||
@user.suspended? ||
|
@user.suspended? ||
|
||||||
@user.silenced? ||
|
@user.silenced? ||
|
||||||
|
|
|
@ -135,5 +135,14 @@ describe Jobs::Tl3Promotions do
|
||||||
run_job
|
run_job
|
||||||
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -586,6 +586,14 @@ describe TrustLevel3Requirements do
|
||||||
user.silenced_till = 4.weeks.from_now
|
user.silenced_till = 4.weeks.from_now
|
||||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user