diff --git a/app/assets/javascripts/admin/templates/dashboard_next.hbs b/app/assets/javascripts/admin/templates/dashboard_next.hbs index a683ba27db8..be33186c52d 100644 --- a/app/assets/javascripts/admin/templates/dashboard_next.hbs +++ b/app/assets/javascripts/admin/templates/dashboard_next.hbs @@ -26,6 +26,7 @@
+ {{dashboard-mini-table dataSourceName="users_by_types"}} {{dashboard-mini-table dataSourceName="users_by_trust_level"}}
diff --git a/app/assets/stylesheets/common/admin/dashboard_next.scss b/app/assets/stylesheets/common/admin/dashboard_next.scss index 138085885f1..ff29f13878a 100644 --- a/app/assets/stylesheets/common/admin/dashboard_next.scss +++ b/app/assets/stylesheets/common/admin/dashboard_next.scss @@ -34,6 +34,8 @@ } .dashboard-mini-table { + margin-bottom: 1em; + .table-title { align-items: center; display: flex; diff --git a/app/models/report.rb b/app/models/report.rb index 2d6c8a3624c..521a74fb9ab 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2c4ac31006d..1d3169ab800 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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" diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 0d0d8201b02..8ef61d74b4a 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -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)