dashboard next: adds report for user types

This commit is contained in:
Joffrey JAFFEUX 2018-04-16 13:03:43 +02:00 committed by GitHub
parent 9353ae4b5d
commit 06b6c805d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 0 deletions

View File

@ -26,6 +26,7 @@
<div class="section-columns">
<div class="section-column">
{{dashboard-mini-table dataSourceName="users_by_types"}}
{{dashboard-mini-table dataSourceName="users_by_trust_level"}}
</div>

View File

@ -34,6 +34,8 @@
}
.dashboard-mini-table {
margin-bottom: 1em;
.table-title {
align-items: center;
display: flex;

View File

@ -243,4 +243,22 @@ class Report
.group(:user_agent).sum(:count)
.map { |ua, count| { x: ua, y: count } }
end
def self.report_users_by_types(report)
report.data = []
label = Proc.new { |key| I18n.t("reports.users_by_types.xaxis_labels.#{key}") }
admins = User.real.where(admin: true).count
report.data << { x: label.call("admin"), y: admins } if admins > 0
moderators = User.real.where(moderator: true).count
report.data << { x: label.call("moderator"), y: moderators } if moderators > 0
suspended = User.suspended.count
report.data << { x: label.call("suspended"), y: suspended } if suspended > 0
silenced = User.silenced.count
report.data << { x: label.call("silenced"), y: silenced } if silenced > 0
end
end

View File

@ -869,6 +869,15 @@ en:
title: "Users per Trust Level"
xaxis: "Trust Level"
yaxis: "Number of Users"
users_by_types:
title: "Users per types"
xaxis: "Type"
yaxis: "Number of Users"
xaxis_labels:
admin: Admin
moderator: Moderator
suspended: Suspended
silenced: Silenced
emails:
title: "Emails Sent"
xaxis: "Day"

View File

@ -250,6 +250,33 @@ describe Report do
end
end
describe 'users by types level report' do
let(:report) { Report.find('users_by_types') }
context "no users" do
it "returns an empty report" do
expect(report.data).to be_blank
end
end
context "with users at different trust levels" do
before do
3.times { Fabricate(:user, admin: true) }
2.times { Fabricate(:user, moderator: true) }
UserSilencer.silence(Fabricate(:user), Fabricate.build(:admin))
Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago)
end
it "returns a report with data" do
expect(report.data).to be_present
expect(report.data.find { |d| d[:x] == "admin" }[:y]).to eq 3
expect(report.data.find { |d| d[:x] == "moderator" }[:y]).to eq 2
expect(report.data.find { |d| d[:x] == "silenced" }[:y]).to eq 1
expect(report.data.find { |d| d[:x] == "suspended" }[:y]).to eq 1
end
end
end
describe 'posts counts' do
it "only counts regular posts" do
post = Fabricate(:post)