mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: send the queued posts reminder as a message to moderators instead of an email to the contact_email
This commit is contained in:
parent
31ecb4fecf
commit
beea5cac48
@ -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
|
||||
|
||||
|
@ -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
|
@ -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}).
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user