mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Check daily if there are new users who need to be approved and send a pm to moderators
This commit is contained in:
parent
068a674c39
commit
3708d47c87
4 changed files with 73 additions and 4 deletions
|
@ -42,10 +42,16 @@ class GroupMessage
|
|||
end
|
||||
|
||||
def message_params
|
||||
@message_params ||= {
|
||||
username: @opts[:user].username,
|
||||
user_url: admin_user_path(@opts[:user].username)
|
||||
}
|
||||
@message_params ||= begin
|
||||
h = @opts[:message_params]||{}
|
||||
if @opts[:user]
|
||||
h.merge!({
|
||||
username: @opts[:user].username,
|
||||
user_url: admin_user_path(@opts[:user].username)
|
||||
})
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def sent_recently?
|
||||
|
|
|
@ -952,6 +952,15 @@ en:
|
|||
|
||||
You can now create new replies and topics again.
|
||||
|
||||
pending_users_reminder:
|
||||
subject_template:
|
||||
one: "There is 1 unapproved user"
|
||||
other: "There are %{count} unapproved users"
|
||||
text_body_template: |
|
||||
There are new users waiting to be approved.
|
||||
|
||||
[Please review them in the admin section](/admin/users/list/pending).
|
||||
|
||||
unsubscribe_link: "To unsubscribe from these emails, visit your [user preferences](%{user_preferences_url})."
|
||||
|
||||
user_notifications:
|
||||
|
|
20
lib/jobs/pending_users_reminder.rb
Normal file
20
lib/jobs/pending_users_reminder.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require_dependency 'admin_user_index_query'
|
||||
|
||||
module Jobs
|
||||
|
||||
class PendingUsersReminder < Jobs::Scheduled
|
||||
|
||||
recurrence { daily.hour_of_day(9) }
|
||||
|
||||
def execute(args)
|
||||
if SiteSetting.must_approve_users
|
||||
count = AdminUserIndexQuery.new({query: 'pending'}).find_users_query.count
|
||||
if count > 0
|
||||
GroupMessage.create(Group[:moderators].name, :pending_users_reminder, {limit_once_per: false, message_params: {count: count}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
34
spec/components/jobs/pending_users_reminder_spec.rb
Normal file
34
spec/components/jobs/pending_users_reminder_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Jobs::PendingUsersReminder do
|
||||
|
||||
context 'must_approve_users is true' do
|
||||
before do
|
||||
SiteSetting.stubs(:must_approve_users).returns(true)
|
||||
end
|
||||
|
||||
it "doesn't send a message to anyone when there are no pending users" do
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 0))
|
||||
GroupMessage.any_instance.expects(:create).never
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
|
||||
it "sends a message to moderators when there are pending users" do
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1))
|
||||
GroupMessage.expects(:create).with(Group[:moderators].name, :pending_users_reminder, anything)
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
end
|
||||
|
||||
context 'must_approve_users is false' do
|
||||
before do
|
||||
SiteSetting.stubs(:must_approve_users).returns(false)
|
||||
end
|
||||
|
||||
it "doesn't send a message to anyone when there are pending users" do
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1))
|
||||
GroupMessage.any_instance.expects(:create).never
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue