approver pruner: send weekly warning dmails to inactive approvers.

Send weekly warning dmails to approvers in danger of losing their
approver permissions. Don't send warnings if we're more than three weeks
away from demotion so that approvers aren't warned prematurely.
This commit is contained in:
evazion
2020-02-27 00:08:48 -06:00
parent 4b9a29743a
commit 3d410398a3
3 changed files with 24 additions and 0 deletions

View File

@@ -30,4 +30,19 @@ module ApproverPruner
end
end
end
def dmail_inactive_approvers!
days_until_next_month = (Date.current.next_month.beginning_of_month - Date.current).to_i
return unless days_until_next_month <= 21
inactive_approvers.each do |user|
Dmail.create_automated(to: user, title: "You will lose approval privileges soon", body: <<~BODY)
You've approved fewer than #{MINIMUM_APPROVALS} posts in the past
#{APPROVAL_PERIOD.inspect}. You will lose your approval privileges in
#{days_until_next_month} #{"day".pluralize(days_until_next_month)}
unless you have approved at least #{MINIMUM_APPROVALS} posts by the end
of the month.
BODY
end
end
end

View File

@@ -21,6 +21,7 @@ module DanbooruMaintenance
def weekly
safely { UserPasswordResetNonce.prune! }
safely { TagRelationshipRetirementService.find_and_retire! }
safely { ApproverPruner.dmail_inactive_approvers! }
end
def monthly

View File

@@ -27,5 +27,13 @@ class ApproverPrunerTest < ActiveSupport::TestCase
assert_not_includes(ApproverPruner.inactive_approvers.map(&:id), @user.id)
end
should "dmail inactive approvers" do
travel_to(Date.parse("2020-01-20")) do
ApproverPruner.dmail_inactive_approvers!
end
assert_equal("You will lose approval privileges soon", @approver.dmails.received.last.title)
end
end
end