work on #2408
This commit is contained in:
29
app/logical/janitor_pruner.rb
Normal file
29
app/logical/janitor_pruner.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class JanitorPruner
|
||||
def inactive_janitors
|
||||
admin = User.admins.first
|
||||
|
||||
User.where("level = ?", User::Levels::JANITOR).select do |user|
|
||||
approval_count = Post.where("created_at >= ? and approver_id = ?", 2.months.ago, user.id).count
|
||||
approval_count == 0
|
||||
end
|
||||
end
|
||||
|
||||
def prune!
|
||||
inactive_janitors.each do |user|
|
||||
CurrentUser.scoped(admin, "127.0.0.1") do
|
||||
Dmail.create_split(
|
||||
:to_id => user.id,
|
||||
:title => "Janitor inactivity",
|
||||
:body => "You haven't approved a post in the past two months. In order to make sure the list of active janitors is up-to-date, you have lost your janitor privileges. Please reply to this message if you want to be reinstated."
|
||||
)
|
||||
|
||||
janitor_trial = JanitorTrial.where(user_id: user.id).first
|
||||
if janitor_trial
|
||||
user.promote_to!(janitor_trial.original_level, :skip_feedback => true)
|
||||
else
|
||||
user.promote_to!(User::Levels::GOLD, :skip_feedback => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/logical/monthly_maintenance.rb
Normal file
6
app/logical/monthly_maintenance.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class MonthlyMaintenance
|
||||
def run
|
||||
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
|
||||
JanitorTrial.new.message_candidates!
|
||||
end
|
||||
end
|
||||
@@ -2,5 +2,6 @@ class WeeklyMaintenance
|
||||
def run
|
||||
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
|
||||
UserPasswordResetNonce.prune!
|
||||
JanitorPruner.new.prune!
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user