FEATURE: adds revision_count to moderators_activity (#6218)
Co-Authored-By: Simon Cossar <scossar@users.noreply.github.com>
This commit is contained in:
parent
b6939093eb
commit
849f0d00f6
|
@ -721,6 +721,10 @@ class Report
|
||||||
{
|
{
|
||||||
property: :post_count,
|
property: :post_count,
|
||||||
title: I18n.t("reports.moderators_activity.labels.post_count")
|
title: I18n.t("reports.moderators_activity.labels.post_count")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: :revision_count,
|
||||||
|
title: I18n.t("reports.moderators_activity.labels.revision_count")
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -787,6 +791,19 @@ class Report
|
||||||
ON df.user_id = af.user_id
|
ON df.user_id = af.user_id
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
revision_count_query = <<~SQL
|
||||||
|
SELECT pr.user_id,
|
||||||
|
COUNT(*) AS revision_count
|
||||||
|
FROM post_revisions pr
|
||||||
|
JOIN users u
|
||||||
|
ON u.id = pr.user_id
|
||||||
|
WHERE u.moderator = 'true'
|
||||||
|
AND u.id > 0
|
||||||
|
AND pr.created_at >= '#{report.start_date}'
|
||||||
|
AND pr.created_at <= '#{report.end_date}'
|
||||||
|
GROUP BY pr.user_id
|
||||||
|
SQL
|
||||||
|
|
||||||
topic_count_query = <<~SQL
|
topic_count_query = <<~SQL
|
||||||
SELECT t.user_id,
|
SELECT t.user_id,
|
||||||
COUNT(*) AS topic_count
|
COUNT(*) AS topic_count
|
||||||
|
@ -841,6 +858,10 @@ class Report
|
||||||
mod_data[row.user_id][:flag_count] = row.flag_count
|
mod_data[row.user_id][:flag_count] = row.flag_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DB.query(revision_count_query).each do |row|
|
||||||
|
mod_data[row.user_id][:revision_count] = row.revision_count
|
||||||
|
end
|
||||||
|
|
||||||
DB.query(topic_count_query).each do |row|
|
DB.query(topic_count_query).each do |row|
|
||||||
mod_data[row.user_id][:topic_count] = row.topic_count
|
mod_data[row.user_id][:topic_count] = row.topic_count
|
||||||
end
|
end
|
||||||
|
|
|
@ -864,6 +864,7 @@ en:
|
||||||
topic_count: Topics created
|
topic_count: Topics created
|
||||||
post_count: Posts created
|
post_count: Posts created
|
||||||
pm_count: PMs created
|
pm_count: PMs created
|
||||||
|
revision_count: Revisions
|
||||||
flags_status:
|
flags_status:
|
||||||
title: "Flags status"
|
title: "Flags status"
|
||||||
values:
|
values:
|
||||||
|
|
|
@ -534,94 +534,159 @@ describe Report do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'moderator activity' do
|
describe 'moderator activity' do
|
||||||
let(:report) { Report.find('moderators_activity', start_date: 1.months.ago.beginning_of_day, end_date: Date.today) }
|
let(:report) {
|
||||||
let(:previous_report) { Report.find('moderators_activity', start_date: 2.months.ago.beginning_of_day, end_date: 1.month.ago.end_of_day) }
|
Report.find('moderators_activity')
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:sam) { Fabricate(:user, moderator: true, username: 'sam') }
|
||||||
|
|
||||||
|
let(:jeff) { Fabricate(:user, moderator: true, username: 'jeff') }
|
||||||
|
|
||||||
include_examples 'no data'
|
include_examples 'no data'
|
||||||
|
|
||||||
context "with moderators" do
|
context "with moderators" do
|
||||||
before do
|
before do
|
||||||
freeze_time(Date.today)
|
freeze_time(Date.today)
|
||||||
|
|
||||||
bob = Fabricate(:user, moderator: true, username: 'bob')
|
|
||||||
bob.user_visits.create(visited_at: 2.days.ago, time_read: 200)
|
|
||||||
bob.user_visits.create(visited_at: 1.day.ago, time_read: 100)
|
|
||||||
Fabricate(:topic, user: bob, created_at: 1.day.ago)
|
|
||||||
sally = Fabricate(:user, moderator: true, username: 'sally')
|
|
||||||
sally.user_visits.create(visited_at: 2.days.ago, time_read: 1000)
|
|
||||||
sally.user_visits.create(visited_at: 1.day.ago, time_read: 2000)
|
|
||||||
topic = Fabricate(:topic)
|
|
||||||
2.times {
|
|
||||||
Fabricate(:post, user: sally, topic: topic, created_at: 1.day.ago)
|
|
||||||
}
|
|
||||||
flag_user = Fabricate(:user)
|
|
||||||
flag_post = Fabricate(:post, user: flag_user)
|
|
||||||
action = PostAction.new(user_id: flag_user.id,
|
|
||||||
post_action_type_id: PostActionType.types[:off_topic],
|
|
||||||
post_id: flag_post.id,
|
|
||||||
agreed_by_id: sally.id,
|
|
||||||
created_at: 1.day.ago,
|
|
||||||
agreed_at: Time.now)
|
|
||||||
action.save
|
|
||||||
bob.user_visits.create(visited_at: 45.days.ago, time_read: 200)
|
|
||||||
old_topic = Fabricate(:topic, user: bob, created_at: 45.days.ago)
|
|
||||||
3.times {
|
|
||||||
Fabricate(:post, user: bob, topic: old_topic, created_at: 45.days.ago)
|
|
||||||
}
|
|
||||||
old_flag_user = Fabricate(:user)
|
|
||||||
old_flag_post = Fabricate(:post, user: old_flag_user, created_at: 45.days.ago)
|
|
||||||
old_action = PostAction.new(user_id: old_flag_user.id,
|
|
||||||
post_action_type_id: PostActionType.types[:spam],
|
|
||||||
post_id: old_flag_post.id,
|
|
||||||
agreed_by_id: bob.id,
|
|
||||||
created_at: 44.days.ago,
|
|
||||||
agreed_at: 44.days.ago)
|
|
||||||
old_action.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a report with data" do
|
context "time read" do
|
||||||
expect(report.data).to be_present
|
before do
|
||||||
end
|
sam.user_visits.create(visited_at: 2.days.ago, time_read: 200)
|
||||||
|
sam.user_visits.create(visited_at: 1.day.ago, time_read: 100)
|
||||||
|
|
||||||
it "returns data for two moderators" do
|
jeff.user_visits.create(visited_at: 2.days.ago, time_read: 1000)
|
||||||
expect(report.data.count).to eq(2)
|
jeff.user_visits.create(visited_at: 1.day.ago, time_read: 2000)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the correct usernames" do
|
Fabricate(:topic, created_at: 1.day.ago)
|
||||||
expect(report.data[0][:username]).to eq('bob')
|
|
||||||
expect(report.data[1][:username]).to eq('sally')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the correct read times" do
|
it "returns the correct read times" do
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
expect(report.data[0][:time_read]).to eq(300)
|
expect(report.data[0][:time_read]).to eq(300)
|
||||||
|
expect(report.data[1][:username]).to eq('jeff')
|
||||||
expect(report.data[1][:time_read]).to eq(3000)
|
expect(report.data[1][:time_read]).to eq(3000)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "returns the correct agreed flag count" do
|
context "flags" do
|
||||||
expect(report.data[0][:flag_count]).to be_blank
|
before do
|
||||||
expect(report.data[1][:flag_count]).to eq(1)
|
flagged_post = Fabricate(:post)
|
||||||
|
PostAction.act(jeff, flagged_post, PostActionType.types[:off_topic])
|
||||||
|
PostAction.agree_flags!(flagged_post, jeff)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the correct read times" do
|
||||||
|
expect(report.data.count).to eq(1)
|
||||||
|
expect(report.data[0][:flag_count]).to eq(1)
|
||||||
|
expect(report.data[0][:username]).to eq("jeff")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "topics" do
|
||||||
|
before do
|
||||||
|
Fabricate(:topic, user: sam)
|
||||||
|
Fabricate(:topic, user: sam)
|
||||||
|
Fabricate(:topic, user: jeff)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the correct topic count" do
|
it "returns the correct topic count" do
|
||||||
expect(report.data[0][:topic_count]).to eq(1)
|
expect(report.data[0][:topic_count]).to eq(2)
|
||||||
expect(report.data[1][:topic_count]).to be_blank
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
expect(report.data[1][:topic_count]).to eq(1)
|
||||||
|
expect(report.data[1][:username]).to eq('jeff')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the correct post count" do
|
context "private messages" do
|
||||||
expect(report.data[0][:post_count]).to be_blank
|
before do
|
||||||
expect(report.data[1][:post_count]).to eq(2)
|
Fabricate(:private_message_topic, user: jeff)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the correct data for the time period" do
|
it "doesn’t count private topic" do
|
||||||
expect(previous_report.data[0][:flag_count]).to eq(1)
|
expect(report.data[0][:topic_count]).to eq(2)
|
||||||
expect(previous_report.data[0][:topic_count]).to eq(1)
|
expect(report.data[1][:topic_count]).to eq(1)
|
||||||
expect(previous_report.data[0][:post_count]).to eq(3)
|
end
|
||||||
expect(previous_report.data[0][:time_read]).to eq(200)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
expect(previous_report.data[1][:flag_count]).to be_blank
|
context "posts" do
|
||||||
expect(previous_report.data[1][:topic_count]).to be_blank
|
before do
|
||||||
expect(previous_report.data[1][:post_count]).to be_blank
|
Fabricate(:post, user: sam)
|
||||||
expect(previous_report.data[1][:time_read]).to be_blank
|
Fabricate(:post, user: sam)
|
||||||
|
Fabricate(:post, user: jeff)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the correct topic count" do
|
||||||
|
expect(report.data[0][:topic_count]).to eq(2)
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
expect(report.data[1][:topic_count]).to eq(1)
|
||||||
|
expect(report.data[1][:username]).to eq('jeff')
|
||||||
|
end
|
||||||
|
|
||||||
|
context "private messages" do
|
||||||
|
before do
|
||||||
|
Fabricate(:private_message_post, user: jeff)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn’t count private post" do
|
||||||
|
expect(report.data[0][:post_count]).to eq(2)
|
||||||
|
expect(report.data[1][:post_count]).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "private messages" do
|
||||||
|
before do
|
||||||
|
Fabricate(:post, user: sam)
|
||||||
|
Fabricate(:topic, user: sam)
|
||||||
|
Fabricate(:post, user: jeff)
|
||||||
|
Fabricate(:private_message_post, user: jeff)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the correct topic count" do
|
||||||
|
expect(report.data[0][:pm_count]).to be_blank
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
expect(report.data[1][:pm_count]).to eq(1)
|
||||||
|
expect(report.data[1][:username]).to eq('jeff')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "revisions" do
|
||||||
|
before do
|
||||||
|
post = Fabricate(:post)
|
||||||
|
post.revise(sam, raw: 'updated body', edit_reason: 'not cool')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the correct revisions count" do
|
||||||
|
expect(report.data[0][:revision_count]).to eq(1)
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
end
|
||||||
|
|
||||||
|
context "revise own post" do
|
||||||
|
before do
|
||||||
|
post = Fabricate(:post, user: sam)
|
||||||
|
Fabricate(:post, user: sam)
|
||||||
|
.revise(sam, raw: 'updated body', edit_reason: 'not cool')
|
||||||
|
|
||||||
|
Fabricate(:post)
|
||||||
|
.revise(sam, raw: 'updated body', edit_reason: 'not cool')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesnt count a revison on your own post" do
|
||||||
|
expect(report.data[0][:revision_count]).to eq(2)
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "previous data" do
|
||||||
|
before do
|
||||||
|
Fabricate(:topic, user: sam, created_at: 1.year.ago)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn’t count old data" do
|
||||||
|
expect(report.data[0][:topic_count]).to be_blank
|
||||||
|
expect(report.data[0][:username]).to eq('sam')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue