mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
FEATURE: notify by email when there are posts from new users waiting to be reviewed
This commit is contained in:
parent
455ba6ae0c
commit
77595bcaa9
34
app/jobs/scheduled/pending_queued_posts_reminder.rb
Normal file
34
app/jobs/scheduled/pending_queued_posts_reminder.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Jobs
|
||||
class PendingQueuedPostReminder < Jobs::Scheduled
|
||||
|
||||
every 1.hour
|
||||
|
||||
def execute(args)
|
||||
return true unless SiteSetting.notify_about_queued_posts_after > 0 && SiteSetting.contact_email
|
||||
|
||||
if should_notify_ids.size > 0 && last_notified_id.to_i < should_notify_ids.max
|
||||
message = PendingQueuedPostsMailer.notify(count: should_notify_ids.size)
|
||||
Email::Sender.new(message, :pending_queued_posts_reminder).send
|
||||
self.last_notified_id = should_notify_ids.max
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def should_notify_ids
|
||||
@_should_notify_ids ||= QueuedPost.new_posts.visible.where('created_at < ?', SiteSetting.notify_about_queued_posts_after.hours.ago).pluck(:id)
|
||||
end
|
||||
|
||||
def last_notified_id
|
||||
(i = $redis.get(self.class.last_notified_key)) && i.to_i
|
||||
end
|
||||
|
||||
def last_notified_id=(arg)
|
||||
$redis.set(self.class.last_notified_key, arg)
|
||||
end
|
||||
|
||||
def self.last_notified_key
|
||||
"last_notified_queued_post_id"
|
||||
end
|
||||
end
|
||||
end
|
10
app/mailers/pending_queued_posts_mailer.rb
Normal file
10
app/mailers/pending_queued_posts_mailer.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
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
|
|
@ -1155,6 +1155,7 @@ en:
|
|||
|
||||
approve_post_count: "The amount of posts from a new user that must be approved"
|
||||
approve_unless_trust_level: "Posts for users below this trust level must be approved"
|
||||
notify_about_queued_posts_after: "If there are posts that have been waiting to be reviewed for more than this many hours, an email will be sent to the contact email. Set to 0 to disable these emails."
|
||||
|
||||
errors:
|
||||
invalid_email: "Invalid email address."
|
||||
|
@ -1424,6 +1425,15 @@ en:
|
|||
one: "1 flag waiting to be handled"
|
||||
other: "%{count} flags waiting to be handled"
|
||||
|
||||
queued_posts_reminder:
|
||||
subject_template:
|
||||
one: "[%{site_name}] 1 post waiting to be reviewed"
|
||||
other: "[%{site_name}] %{count} posts waiting to be reviewed"
|
||||
text_body_template: |
|
||||
Hello,
|
||||
|
||||
There are posts from new users that are waiting to be reviewed. [They can be approved or rejected 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)."
|
||||
|
|
|
@ -450,6 +450,9 @@ posting:
|
|||
approve_unless_trust_level:
|
||||
default: 0
|
||||
enum: 'TrustLevelSetting'
|
||||
notify_about_queued_posts_after:
|
||||
default: 24
|
||||
min: 0
|
||||
|
||||
email:
|
||||
email_time_window_mins:
|
||||
|
|
38
spec/jobs/pending_queued_posts_reminder_spec.rb
Normal file
38
spec/jobs/pending_queued_posts_reminder_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Jobs::PendingQueuedPostReminder do
|
||||
context "notify_about_queued_posts_after is 0" do
|
||||
before { SiteSetting.stubs(:notify_about_queued_posts_after).returns(0) }
|
||||
|
||||
it "never emails" do
|
||||
described_class.any_instance.expects(:should_notify_ids).never
|
||||
Email::Sender.any_instance.expects(:send).never
|
||||
described_class.new.execute({})
|
||||
end
|
||||
end
|
||||
|
||||
context "notify_about_queued_posts_after is 24" do
|
||||
before { SiteSetting.stubs(:notify_about_queued_posts_after).returns(24) }
|
||||
|
||||
it "doesn't email 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({})
|
||||
end
|
||||
|
||||
it "emails 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({})
|
||||
end
|
||||
|
||||
it "doesn't email 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({})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user