FEATURE: add setting pending_users_reminder_delay to configure when to send reminders to moderators about user approvals based on how long new users have been waiting

This commit is contained in:
Neil Lalonde 2015-11-20 16:05:57 -05:00
parent 5597957cc6
commit 523138f1fd
4 changed files with 35 additions and 8 deletions

View File

@ -3,11 +3,15 @@ require_dependency 'admin_user_index_query'
module Jobs
class PendingUsersReminder < Jobs::Scheduled
every 9.hours
every 1.hour
def execute(args)
if SiteSetting.must_approve_users
if SiteSetting.must_approve_users && SiteSetting.pending_users_reminder_delay >= 0
query = AdminUserIndexQuery.new({query: 'pending'}).find_users_query # default order is: users.created_at DESC
if SiteSetting.pending_users_reminder_delay > 0
query = query.where('users.created_at < ?', SiteSetting.pending_users_reminder_delay.hours.ago)
end
newest_username = query.limit(1).pluck(:username).first
return true if newest_username == previous_newest_username # already notified

View File

@ -868,6 +868,7 @@ en:
allow_html_tables: "Allow tables to be entered in Markdown using HTML tags. TABLE, THEAD, TD, TR, TH will be whitelisted (requires full rebake on all old posts containing tables)"
post_undo_action_window_mins: "Number of minutes users are allowed to undo recent actions on a post (like, flag, etc)."
must_approve_users: "Staff must approve all new user accounts before they are allowed to access the site. WARNING: enabling this for a live site will revoke access for existing non-staff users!"
pending_users_reminder_delay: "Notify moderators if new users have been waiting for approval for longer than this many hours. Set to -1 to disable notifications."
ga_tracking_code: "Google analytics (ga.js) tracking code code, eg: UA-12345678-9; see http://google.com/analytics"
ga_domain_name: "Google analytics (ga.js) domain name, eg: mysite.com; see http://google.com/analytics"
ga_universal_tracking_code: "Google Universal Analytics (analytics.js) tracking code code, eg: UA-12345678-9; see http://google.com/analytics"

View File

@ -271,6 +271,9 @@ login:
type: list
forgot_password_strict: false
log_out_strict: true
pending_users_reminder_delay:
min: -1
default: 8
users:
min_username_length:

View File

@ -13,12 +13,31 @@ describe Jobs::PendingUsersReminder do
Jobs::PendingUsersReminder.new.execute({})
end
it "sends a message when there are pending users" do
Fabricate(:moderator, approved: true, approved_by_id: -1, approved_at: 1.week.ago)
Fabricate(:user)
Group.refresh_automatic_group!(:moderators)
PostCreator.expects(:create).once
Jobs::PendingUsersReminder.new.execute({})
context "there are pending users" do
before do
Fabricate(:moderator, approved: true, approved_by_id: -1, approved_at: 1.week.ago)
Group.refresh_automatic_group!(:moderators)
end
it "sends a message if user was created more than pending_users_reminder_delay hours ago" do
SiteSetting.pending_users_reminder_delay = 8
Fabricate(:user, created_at: 9.hours.ago)
PostCreator.expects(:create).once
Jobs::PendingUsersReminder.new.execute({})
end
it "doesn't send a message if user was created less than pending_users_reminder_delay hours ago" do
SiteSetting.pending_users_reminder_delay = 8
Fabricate(:user, created_at: 2.hours.ago)
PostCreator.expects(:create).never
Jobs::PendingUsersReminder.new.execute({})
end
it "doesn't send a message if pending_users_reminder_delay is -1" do
SiteSetting.pending_users_reminder_delay = -1
PostCreator.expects(:create).never
Jobs::PendingUsersReminder.new.execute({})
end
end
end