diff --git a/app/jobs/scheduled/pending_users_reminder.rb b/app/jobs/scheduled/pending_users_reminder.rb index c5c6febf229..95b02ea172f 100644 --- a/app/jobs/scheduled/pending_users_reminder.rb +++ b/app/jobs/scheduled/pending_users_reminder.rb @@ -9,7 +9,24 @@ module Jobs 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}}) + target_usernames = Group[:moderators].users.map do |u| + u.id > 0 && u.notifications.joins(:topic) + .where("notifications.id > ?", u.seen_notification_id) + .where("notifications.read = false") + .where("topics.subtype = '#{TopicSubtype.pending_users_reminder}'") + .count == 0 ? u.username : nil + end.compact + + unless target_usernames.empty? + PostCreator.create( + Discourse.system_user, + target_usernames: target_usernames, + archetype: Archetype.private_message, + subtype: TopicSubtype.pending_users_reminder, + title: I18n.t("system_messages.pending_users_reminder.subject_template", {count: count}), + raw: I18n.t("system_messages.pending_users_reminder.text_body_template", {count: count, base_url: Discourse.base_url}) + ) + end end end end diff --git a/lib/topic_subtype.rb b/lib/topic_subtype.rb index bf2f992e5e2..0d8224c4e45 100644 --- a/lib/topic_subtype.rb +++ b/lib/topic_subtype.rb @@ -37,6 +37,10 @@ class TopicSubtype 'notify_user' end + def self.pending_users_reminder + 'pending_users' + end + def self.register(name, options={}) @subtypes ||= {} @subtypes[name] = TopicSubtype.new(name, options) diff --git a/spec/jobs/pending_users_reminder_spec.rb b/spec/jobs/pending_users_reminder_spec.rb index 3c640f37c24..a0cbbfb9ce8 100644 --- a/spec/jobs/pending_users_reminder_spec.rb +++ b/spec/jobs/pending_users_reminder_spec.rb @@ -9,13 +9,15 @@ describe Jobs::PendingUsersReminder do 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 + PostCreator.expects(:create).never Jobs::PendingUsersReminder.new.execute({}) end - it "sends a message to moderators when there are pending users" do + it "sends a message when there are pending users" do + Fabricate(:moderator) + Group.refresh_automatic_group!(:moderators) AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1)) - GroupMessage.expects(:create).with(Group[:moderators].name, :pending_users_reminder, anything) + PostCreator.expects(:create).once Jobs::PendingUsersReminder.new.execute({}) end end @@ -27,7 +29,7 @@ describe Jobs::PendingUsersReminder do 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 + PostCreator.expects(:create).never Jobs::PendingUsersReminder.new.execute({}) end end