mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 22:23:00 +08:00
59d04c0695
Changed internals so trust levels are referred to with TrustLevel[1], TrustLevel[2] etc. This gives us much better flexibility naming trust levels, these names are meant to be controlled by various communities.
31 lines
947 B
Ruby
31 lines
947 B
Ruby
module Jobs
|
|
|
|
class LeaderPromotions < Jobs::Scheduled
|
|
daily at: 4.hours
|
|
|
|
def execute(args)
|
|
# Demotions
|
|
demoted_user_ids = []
|
|
User.real.where(trust_level: TrustLevel[3]).find_each do |u|
|
|
# Don't demote too soon after being promoted
|
|
next if UserHistory.for(u, :auto_trust_level_change)
|
|
.where('created_at >= ?', SiteSetting.leader_promotion_min_duration.to_i.days.ago)
|
|
.where(previous_value: TrustLevel[2].to_s)
|
|
.where(new_value: TrustLevel[3].to_s)
|
|
.exists?
|
|
|
|
if Promotion.tl3_lost?(u)
|
|
demoted_user_ids << u.id
|
|
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
|
end
|
|
end
|
|
|
|
# Promotions
|
|
User.real.where(trust_level: TrustLevel[2]).where.not(id: demoted_user_ids).find_each do |u|
|
|
Promotion.new(u).review_tl2
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|