Send email to contact_email if there are flags submitted more than 48 hours ago. Configurable with the notify_about_flags_after site setting.

This commit is contained in:
Neil Lalonde
2014-04-03 14:34:21 -04:00
parent 7fd0db857f
commit ecf211aa3f
7 changed files with 130 additions and 1 deletions

View File

@ -0,0 +1,21 @@
require_dependency 'flag_query'
module Jobs
class PendingFlagsReminder < Jobs::Scheduled
every 1.day
def execute(args)
if SiteSetting.notify_about_flags_after > 0 &&
PostAction.flagged_posts_count > 0 &&
FlagQuery.flagged_post_actions('active').where('post_actions.created_at < ?', 48.hours.ago).pluck(:id).count > 0
message = PendingFlagsMailer.notify
Email::Sender.new(message, :pending_flags_reminder).send
end
end
end
end

View File

@ -0,0 +1,30 @@
require_dependency 'email/message_builder'
require_dependency 'flag_query'
class PendingFlagsMailer < ActionMailer::Base
include Email::BuildEmailHelper
def notify
return unless SiteSetting.contact_email
@posts, users = FlagQuery.flagged_posts_report(Discourse.system_user, 'active', 0, 20)
@posts.each do |post| # Note: post is a Hash, not a Post.
counts = flag_reason_counts(post)
post[:reason_counts] = counts.map do |reason, count|
"#{I18n.t('post_action_types.' + reason.to_s + '.title')}: #{count}"
end.join(', ')
end
@hours = SiteSetting.notify_about_flags_after
build_email( SiteSetting.contact_email,
subject: "[#{SiteSetting.title}] " + I18n.t('flags_reminder.subject_template', {count: PostAction.flagged_posts_count}) )
end
private
def flag_reason_counts(post)
post[:post_actions].inject({}) {|h,v| h[v[:name_key]] ||= 0; h[v[:name_key]] += 1; h }
end
end

View File

@ -0,0 +1,27 @@
<p>
<%=t 'flags_reminder.flags_were_submitted', count: @hours %>
<a href="<%= Discourse.base_url + '/admin/flags/active' %>"><%=t 'flags_reminder.please_review' %></a>
</p>
<hr/>
<table>
<tr>
<td></td>
<td><%=t 'flags_reminder.post_number' %></td>
<td></td>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= link_to post[:title], "#{Discourse.base_url}/t/#{post[:topic_slug]}/#{post[:topic_id]}/#{post[:post_number]}" %></td>
<td align="center"><%= post[:post_number] %></td>
<td><%= post[:reason_counts] %></td>
</tr>
<% end %>
</table>
<hr/>
<p>
<%=t 'flags_reminder.how_to_disable' %>
</p>

View File

@ -0,0 +1,9 @@
<%=t 'flags_reminder.flags_were_submitted', count: @hours %> <%=t 'flags_reminder.please_review' %>
<%= Discourse.base_url + '/admin/flags/active' %>
<% @posts.each do |post| %>
<%= post[:title] %>: <%=t 'flags_reminder.post_number' %> <%= post[:post_number] %> - <%= post[:reason_counts] %>
<% end %>
<%=t 'flags_reminder.how_to_disable' %>