From 518f7ba91b5b87896afa090b280dcddc93aa6dc6 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 27 Mar 2018 14:00:08 +0530 Subject: [PATCH] FIX: show private message topic count on admin dashboard reports --- app/models/admin_dashboard_data.rb | 1 + app/models/report.rb | 10 ++++++++-- app/models/topic.rb | 6 ++++++ config/locales/server.en.yml | 4 ++++ spec/models/report_spec.rb | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index 8ba294d4249..797e3176ebe 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -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', diff --git a/app/models/report.rb b/app/models/report.rb index 04f27453a0f..0a2871febff 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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 diff --git a/app/models/topic.rb b/app/models/topic.rb index a9169ad515a..3ab042196a8 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 761d2591c7d..f00e044a338 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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" diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index a7e5fc8bbb8..0d0d8201b02 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -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)