Commit fa2464fd authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'users-statistics-page-updates' into 'master'

Correct Display of Billable Users on Users Statistics Page

See merge request gitlab-org/gitlab!56152
parents 178e9234 f55797cc
...@@ -70,3 +70,5 @@ class UsersStatistics < ApplicationRecord ...@@ -70,3 +70,5 @@ class UsersStatistics < ApplicationRecord
end end
end end
end end
UsersStatistics.prepend_if_ee('EE::UsersStatistics')
...@@ -50,10 +50,11 @@ ...@@ -50,10 +50,11 @@
= s_('AdminArea|Bots') = s_('AdminArea|Bots')
%td.p-3.text-right %td.p-3.text-right
= @users_statistics&.bots.to_i = @users_statistics&.bots.to_i
= render_if_exists 'admin/dashboard/billable_users_row'
%tr.bg-gray-light.gl-text-gray-900 %tr.bg-gray-light.gl-text-gray-900
%td.p-3 %td.p-3
%strong %strong
= render_if_exists 'admin/dashboard/billable_users_text' = s_('AdminArea|Active users')
%td.p-3.text-right %td.p-3.text-right
%strong %strong
= @users_statistics&.active.to_i = @users_statistics&.active.to_i
......
# frozen_string_literal: true
module EE
module UsersStatistics
def billable
(base_billable_users + guest_billable_users).sum
end
private
def base_billable_users
[
with_highest_role_reporter,
with_highest_role_developer,
with_highest_role_maintainer,
with_highest_role_owner
]
end
def guest_billable_users
if License.current&.exclude_guests_from_active_count?
[]
else
[without_groups_and_projects, with_highest_role_guest]
end
end
end
end
- billable_users_url = help_page_path('subscriptions/self_managed/index', anchor: 'billable-users')
- billable_users_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer nofollow">'.html_safe % { url: billable_users_url }
%tr
%td.p-3
= s_('AdminArea|Billable users')
%span.gl-outline-0.gl-ml-2{ href: "#", tabindex: "0", role: "button", data: { container: "body",
toggle: "popover",
placement: "top",
html: "true",
trigger: "focus",
content: s_("AdminArea|%{billable_users_link_start}Learn more%{billable_users_link_end} about what defines a billable user").html_safe % { billable_users_link_start: billable_users_link_start, billable_users_link_end: '</a>'.html_safe } } }
= sprite_icon('question', size: 16, css_class: 'gl-text-gray-700')
%td.p-3.text-right
= @users_statistics&.billable.to_i
- billable_users_url = help_page_path('subscriptions/self_managed/index', anchor: 'billable-users')
- billable_users_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer nofollow">'.html_safe % { url: billable_users_url }
= s_('AdminArea|Billable users')
%span.gl-outline-0.gl-ml-2{ href: "#", tabindex: "0", role: "button", data: { container: "body",
toggle: "popover",
placement: "top",
html: "true",
trigger: "focus",
content: s_("AdminArea|%{billable_users_link_start}Learn more%{billable_users_link_end} about what defines a billable user").html_safe % { billable_users_link_start: billable_users_link_start, billable_users_link_end: '</a>'.html_safe } } }
= sprite_icon('question', size: 16, css_class: 'gl-text-gray-700')
---
title: Correct billable users calculation on users statistics page
merge_request: 56152
author:
type: fixed
...@@ -66,9 +66,10 @@ RSpec.describe 'Admin Dashboard' do ...@@ -66,9 +66,10 @@ RSpec.describe 'Admin Dashboard' do
expect(page).to have_content("Users with highest role Maintainer 6") expect(page).to have_content("Users with highest role Maintainer 6")
expect(page).to have_content("Users with highest role Owner 5") expect(page).to have_content("Users with highest role Owner 5")
expect(page).to have_content("Bots 2") expect(page).to have_content("Bots 2")
expect(page).to have_content("Billable users 69")
expect(page).to have_content("Active users 71")
expect(page).to have_content("Blocked users 7") expect(page).to have_content("Blocked users 7")
expect(page).to have_content("Total users 78") expect(page).to have_content("Total users 78")
expect(page).to have_content("Billable users 71")
end end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe UsersStatistics do
let(:users_statistics) { build(:users_statistics) }
describe '#billable' do
it 'sums users statistics values excluding blocked users and bots' do
expect(users_statistics.billable).to eq(69)
end
context 'when there is an ultimate license' do
before do
license = create(:license, plan: License::ULTIMATE_PLAN)
allow(License).to receive(:current).and_return(license)
end
it 'excludes blocked users, bots, guest users, and users without a group or project' do
expect(users_statistics.billable).to eq(41)
end
end
end
end
...@@ -30,7 +30,6 @@ RSpec.describe 'admin visits dashboard' do ...@@ -30,7 +30,6 @@ RSpec.describe 'admin visits dashboard' do
describe 'Users statistic' do describe 'Users statistic' do
let_it_be(:users_statistics) { create(:users_statistics) } let_it_be(:users_statistics) { create(:users_statistics) }
let_it_be(:users_count_label) { Gitlab.ee? ? 'Billable users 71' : 'Active users 71' }
it 'shows correct amounts of users', :aggregate_failures do it 'shows correct amounts of users', :aggregate_failures do
visit admin_dashboard_stats_path visit admin_dashboard_stats_path
...@@ -42,9 +41,16 @@ RSpec.describe 'admin visits dashboard' do ...@@ -42,9 +41,16 @@ RSpec.describe 'admin visits dashboard' do
expect(page).to have_content('Users with highest role Maintainer 6') expect(page).to have_content('Users with highest role Maintainer 6')
expect(page).to have_content('Users with highest role Owner 5') expect(page).to have_content('Users with highest role Owner 5')
expect(page).to have_content('Bots 2') expect(page).to have_content('Bots 2')
if Gitlab.ee?
expect(page).to have_content('Billable users 69')
else
expect(page).not_to have_content('Billable users 69')
end
expect(page).to have_content('Blocked users 7') expect(page).to have_content('Blocked users 7')
expect(page).to have_content('Total users 78') expect(page).to have_content('Total users 78')
expect(page).to have_content(users_count_label) expect(page).to have_content('Active users 71')
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment