FIX: show private message topic count on admin dashboard reports
This commit is contained in:
parent
94deb482ae
commit
518f7ba91b
|
@ -21,6 +21,7 @@ class AdminDashboardData
|
|||
|
||||
PRIVATE_MESSAGE_REPORTS ||= [
|
||||
'user_to_user_private_messages',
|
||||
'user_to_user_private_messages_with_replies',
|
||||
'system_private_messages',
|
||||
'notify_moderators_private_messages',
|
||||
'notify_user_private_messages',
|
||||
|
|
|
@ -202,14 +202,20 @@ class Report
|
|||
# Private messages counts:
|
||||
|
||||
def self.private_messages_report(report, topic_subtype)
|
||||
basic_report_about report, Post, :private_messages_count_per_day, report.start_date, report.end_date, topic_subtype
|
||||
add_counts report, Post.private_posts.with_topic_subtype(topic_subtype), 'posts.created_at'
|
||||
basic_report_about report, Topic, :private_message_topics_count_per_day, report.start_date, report.end_date, topic_subtype
|
||||
add_counts report, Topic.private_messages.with_subtype(topic_subtype), 'topics.created_at'
|
||||
end
|
||||
|
||||
def self.report_user_to_user_private_messages(report)
|
||||
private_messages_report report, TopicSubtype.user_to_user
|
||||
end
|
||||
|
||||
def self.report_user_to_user_private_messages_with_replies(report)
|
||||
topic_subtype = TopicSubtype.user_to_user
|
||||
basic_report_about report, Post, :private_messages_count_per_day, report.start_date, report.end_date, topic_subtype
|
||||
add_counts report, Post.private_posts.with_topic_subtype(topic_subtype), 'posts.created_at'
|
||||
end
|
||||
|
||||
def self.report_system_private_messages(report)
|
||||
private_messages_report report, TopicSubtype.system_message
|
||||
end
|
||||
|
|
|
@ -191,6 +191,8 @@ class Topic < ActiveRecord::Base
|
|||
where("topics.category_id IS NULL OR topics.category_id IN (SELECT id FROM categories WHERE #{condition[0]})", condition[1])
|
||||
}
|
||||
|
||||
scope :with_subtype, ->(subtype) { where('topics.subtype = ?', subtype) }
|
||||
|
||||
attr_accessor :ignore_category_auto_close
|
||||
attr_accessor :skip_callbacks
|
||||
|
||||
|
@ -1307,6 +1309,10 @@ SQL
|
|||
MiniSuffix.domain(URI.parse(URI.encode(self.featured_link)).hostname)
|
||||
end
|
||||
|
||||
def self.private_message_topics_count_per_day(start_date, end_date, topic_subtype)
|
||||
private_messages.with_subtype(topic_subtype).where('topics.created_at >= ? AND topics.created_at <= ?', start_date, end_date).group('date(topics.created_at)').order('date(topics.created_at)').count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_category_topic_count_by(num)
|
||||
|
|
|
@ -873,6 +873,10 @@ en:
|
|||
title: "User-to-User"
|
||||
xaxis: "Day"
|
||||
yaxis: "Number of messages"
|
||||
user_to_user_private_messages_with_replies:
|
||||
title: "User-to-User (with replies)"
|
||||
xaxis: "Day"
|
||||
yaxis: "Number of messages"
|
||||
system_private_messages:
|
||||
title: "System"
|
||||
xaxis: "Day"
|
||||
|
|
|
@ -166,7 +166,7 @@ describe Report do
|
|||
end
|
||||
|
||||
describe 'private messages' do
|
||||
let(:report) { Report.find('user_to_user_private_messages') }
|
||||
let(:report) { Report.find('user_to_user_private_messages_with_replies') }
|
||||
|
||||
it 'topic report).to not include private messages' do
|
||||
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
||||
|
|
Loading…
Reference in New Issue