Commit 3b4065ff authored by James Lopez's avatar James Lopez

Merge branch '33121-refactor-user-counts' into 'master'

Refactor Maximum User Counts

See merge request gitlab-org/gitlab!19071
parents cdc791c5 2fd8356f
---
title: Refactor maximum user counts in license
merge_request: 19071
author: briankabiro
type: changed
......@@ -17,6 +17,7 @@ GET /license
"starts_at": "2018-01-27",
"expires_at": "2022-01-27",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
......@@ -46,6 +47,7 @@ GET /licenses
"starts_at": "2018-01-27",
"expires_at": "2022-01-27",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
......@@ -64,6 +66,7 @@ GET /licenses
"starts_at": "2018-01-27",
"expires_at": "2022-01-27",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
......@@ -112,6 +115,7 @@ Example response:
"starts_at": "2018-01-27",
"expires_at": "2022-01-27",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
......@@ -155,6 +159,7 @@ Example response:
"starts_at": "2018-01-27",
"expires_at": "2022-01-27",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
......
......@@ -14,12 +14,8 @@ module LicenseHelper
active_user_count - User.active.excluding_guests.count
end
def max_historical_user_count
HistoricalData.max_historical_user_count
end
def current_active_user_count
License.current&.current_active_users_count || 0
def maximum_user_count
License.current&.maximum_user_count || 0
end
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?)
......
......@@ -417,6 +417,10 @@ class License < ApplicationRecord
HistoricalData.max_historical_user_count(license: self, from: from, to: to)
end
def maximum_user_count
[historical_max, current_active_users_count].max
end
def historical_max_with_default_period
@historical_max_with_default_period ||=
historical_max
......
......@@ -6,9 +6,10 @@
- else
- licensed_users = 'Unlimited'
- maximum_user_count = [max_historical_user_count, current_active_user_count].max
- if restricted && maximum_user_count > restricted
- users_over_license = maximum_user_count - restricted
- max_user_count = maximum_user_count
- if restricted && max_user_count > restricted
- users_over_license = max_user_count - restricted
- else
- users_over_license = 0
......@@ -37,7 +38,7 @@
.well-segment.well-centered
%h3.center
Maximum Users:
= number_with_delimiter maximum_user_count
= number_with_delimiter max_user_count
%hr
This is the highest peak of users on your installation since the license started, and
this is the minimum number you need to purchase when you renew your license.
......
......@@ -539,6 +539,7 @@ module EE
:starts_at,
:expires_at,
:historical_max,
:maximum_user_count,
:licensee,
:add_ons
......
......@@ -71,24 +71,15 @@ describe LicenseHelper do
end
end
describe '#max_historical_user_count' do
it 'returns the max historical user count' do
count = 5
expect(HistoricalData).to receive(:max_historical_user_count).and_return(count)
expect(max_historical_user_count).to eq(count)
end
end
describe '#current_active_user_count' do
describe '#maximum_user_count' do
context 'when current license is set' do
it 'returns the current_active_users_count for the current license' do
it 'returns the maximum_user_count for the current license' do
license = double
allow(License).to receive(:current).and_return(license)
count = 5
allow(license).to receive(:current_active_users_count).and_return(count)
allow(license).to receive(:maximum_user_count).and_return(count)
expect(current_active_user_count).to eq(count)
expect(maximum_user_count).to eq(count)
end
end
......@@ -96,7 +87,7 @@ describe LicenseHelper do
it 'returns 0' do
allow(License).to receive(:current).and_return(nil)
expect(current_active_user_count).to eq(0)
expect(maximum_user_count).to eq(0)
end
end
end
......
......@@ -626,6 +626,27 @@ describe License do
end
end
describe '#maximum_user_count' do
using RSpec::Parameterized::TableSyntax
subject { license.maximum_user_count }
where(:current_active_users_count, :historical_max, :expected) do
100 | 50 | 100
50 | 100 | 100
50 | 50 | 50
end
with_them do
before do
allow(license).to receive(:current_active_users_count) { current_active_users_count }
allow(license).to receive(:historical_max) { historical_max }
end
it { is_expected.to eq(expected) }
end
end
def set_restrictions(opts)
gl_license.restrictions = {
active_user_count: opts[:restricted_user_count],
......
......@@ -22,7 +22,8 @@ describe API::License, api: true do
add_ons: license.add_ons,
expired: license.expired?,
overage: license.overage,
user_limit: license.restricted_user_count
user_limit: license.restricted_user_count,
maximum_user_count: license.maximum_user_count
}
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