diff --git a/app/services/group_message.rb b/app/services/group_message.rb index 2095f3d73..2980f8ff5 100644 --- a/app/services/group_message.rb +++ b/app/services/group_message.rb @@ -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? diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 59ccf20b8..98f2bdb8b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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: diff --git a/lib/jobs/pending_users_reminder.rb b/lib/jobs/pending_users_reminder.rb new file mode 100644 index 000000000..63867bc94 --- /dev/null +++ b/lib/jobs/pending_users_reminder.rb @@ -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 diff --git a/spec/components/jobs/pending_users_reminder_spec.rb b/spec/components/jobs/pending_users_reminder_spec.rb new file mode 100644 index 000000000..3c640f37c --- /dev/null +++ b/spec/components/jobs/pending_users_reminder_spec.rb @@ -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