diff --git a/app/jobs/scheduled/pending_queued_posts_reminder.rb b/app/jobs/scheduled/pending_queued_posts_reminder.rb index 37b9afe6f4e..867918dcef4 100644 --- a/app/jobs/scheduled/pending_queued_posts_reminder.rb +++ b/app/jobs/scheduled/pending_queued_posts_reminder.rb @@ -4,13 +4,20 @@ module Jobs every 1.hour def execute(args) - return true unless SiteSetting.notify_about_queued_posts_after > 0 && SiteSetting.contact_email + return true unless SiteSetting.notify_about_queued_posts_after > 0 queued_post_ids = should_notify_ids if queued_post_ids.size > 0 && last_notified_id.to_i < queued_post_ids.max - message = PendingQueuedPostsMailer.notify(count: queued_post_ids.size) - Email::Sender.new(message, :pending_queued_posts_reminder).send + PostCreator.create( + Discourse.system_user, + target_group_names: Group[:moderators].name, + archetype: Archetype.private_message, + subtype: TopicSubtype.system_message, + title: I18n.t('system_messages.queued_posts_reminder.subject_template', count: queued_post_ids.size), + raw: I18n.t('system_messages.queued_posts_reminder.text_body_template', base_url: Discourse.base_url) + ) + self.last_notified_id = queued_post_ids.max end diff --git a/app/mailers/pending_queued_posts_mailer.rb b/app/mailers/pending_queued_posts_mailer.rb deleted file mode 100644 index 525454b7d22..00000000000 --- a/app/mailers/pending_queued_posts_mailer.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_dependency 'email/message_builder' - -class PendingQueuedPostsMailer < ActionMailer::Base - include Email::BuildEmailHelper - - def notify(opts = {}) - return unless SiteSetting.contact_email - build_email(SiteSetting.contact_email, template: 'queued_posts_reminder', count: opts[:count]) - end -end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2035588b359..563313deba7 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1952,16 +1952,6 @@ en: %{notes} - queued_posts_reminder: - title: "Queued Posts Reminder" - subject_template: - one: "[%{email_prefix}] 1 post waiting to be reviewed" - other: "[%{email_prefix}] %{count} posts waiting to be reviewed" - text_body_template: | - Hello, - - Posts from new users were held for moderation and are currently waiting to be reviewed. [Approve or reject them here](%{base_url}/queued-posts). - flag_reasons: off_topic: "Your post was flagged as **off-topic**: the community feels it is not a good fit for the topic, as currently defined by the title and the first post." inappropriate: "Your post was flagged as **inappropriate**: the community feels it is offensive, abusive, or a violation of [our community guidelines](/guidelines)." @@ -2398,6 +2388,18 @@ en: You've quickly become a valuable member of our community. Thanks for joining, and keep up the great work! + queued_posts_reminder: + title: "Queued Posts Reminder" + subject_template: + one: "1 post waiting to be reviewed" + other: "%{count} posts waiting to be reviewed" + text_body_template: | + Hello, + + Posts from new users were held for moderation and are currently waiting to be reviewed. [Approve or reject them here](%{base_url}/queued-posts). + + + unsubscribe_link: | To unsubscribe from these emails, [click here](%{unsubscribe_url}). diff --git a/spec/jobs/pending_queued_posts_reminder_spec.rb b/spec/jobs/pending_queued_posts_reminder_spec.rb index 5e774287a95..3db6b6357e8 100644 --- a/spec/jobs/pending_queued_posts_reminder_spec.rb +++ b/spec/jobs/pending_queued_posts_reminder_spec.rb @@ -6,8 +6,9 @@ describe Jobs::PendingQueuedPostReminder do it "never emails" do described_class.any_instance.expects(:should_notify_ids).never - Email::Sender.any_instance.expects(:send).never - described_class.new.execute({}) + expect { + described_class.new.execute({}) + }.to_not change { Post.count } end end @@ -16,25 +17,32 @@ describe Jobs::PendingQueuedPostReminder do SiteSetting.notify_about_queued_posts_after = 24 end - it "doesn't email if there are no queued posts" do + it "doesn't create system message if there are no queued posts" do described_class.any_instance.stubs(:should_notify_ids).returns([]) described_class.any_instance.stubs(:last_notified_id).returns(nil) - Email::Sender.any_instance.expects(:send).never - described_class.new.execute({}) + expect { + described_class.new.execute({}) + }.to_not change { Post.count } end - it "emails if there are new queued posts" do + it "creates system message if there are new queued posts" do described_class.any_instance.stubs(:should_notify_ids).returns([1, 2]) described_class.any_instance.stubs(:last_notified_id).returns(nil) - Email::Sender.any_instance.expects(:send).once - described_class.new.execute({}) + expect { + described_class.new.execute({}) + }.to change { Post.count }.by(1) + expect(Topic.where( + subtype: TopicSubtype.system_message, + title: I18n.t('system_messages.queued_posts_reminder.subject_template', count: 2) + ).exists?).to eq(true) end - it "doesn't email again about the same posts" do + it "doesn't create system message again about the same posts" do described_class.any_instance.stubs(:should_notify_ids).returns([2]) described_class.any_instance.stubs(:last_notified_id).returns(2) - Email::Sender.any_instance.expects(:send).never - described_class.new.execute({}) + expect { + described_class.new.execute({}) + }.to_not change { Post.count } end end end