Commit 7b6e75e7 authored by Robert Speicher's avatar Robert Speicher

Merge branch '184-allow-for-acceptable-user-growth-during-sm-license-upload' into 'master'

Allow some extra users when registering a new license

See merge request gitlab-org/gitlab!46407
parents 6c244364 7d8b888e
......@@ -6,6 +6,7 @@ class License < ApplicationRecord
STARTER_PLAN = 'starter'.freeze
PREMIUM_PLAN = 'premium'.freeze
ULTIMATE_PLAN = 'ultimate'.freeze
ALLOWED_PERCENTAGE_OF_USERS_OVERAGE = (10 / 100.0).freeze
EES_FEATURES = %i[
audit_events
......@@ -562,13 +563,20 @@ class License < ApplicationRecord
end
end
def restricted_user_count_with_threshold
# overage should only be applied for new subscriptions not for renewals.
return restricted_user_count if previous_user_count
(restricted_user_count * (1 + ALLOWED_PERCENTAGE_OF_USERS_OVERAGE)).to_i
end
def check_users_limit
return unless restricted_user_count
if previous_user_count && (prior_historical_max <= previous_user_count)
return if restricted_user_count >= current_active_users_count
else
return if restricted_user_count >= prior_historical_max
return if restricted_user_count_with_threshold >= prior_historical_max
end
user_count = prior_historical_max == 0 ? current_active_users_count : prior_historical_max
......
......@@ -28,6 +28,7 @@ RSpec.describe License do
end
describe '#check_users_limit' do
context 'for each plan' do
before do
create(:group_member, :guest)
create(:group_member, :reporter)
......@@ -65,6 +66,59 @@ RSpec.describe License do
end
end
context 'threshold for users overage' do
let(:current_active_users_count) { 0 }
let(:new_license) do
gl_license = build(
:gitlab_license,
starts_at: Date.today,
restrictions: { active_user_count: 10, previous_user_count: previous_user_count }
)
build(:license, data: gl_license.export)
end
context 'when current active users count is above the limit set by the license' do
before do
create_list(:user, current_active_users_count)
HistoricalData.track!
end
context 'when license is from a fresh subscription' do
let(:previous_user_count) { nil }
context 'when current active users count is under the threshold' do
let(:current_active_users_count) { 11 }
it 'accepts the license' do
expect(new_license).to be_valid
end
end
context 'when current active users count is above the threshold' do
let(:current_active_users_count) { 12 }
it 'does not accept the license' do
expect(new_license).not_to be_valid
end
end
end
context 'when license is from a renewal' do
let(:previous_user_count) { 1 }
context 'when current active users count is under the threshold' do
let(:current_active_users_count) { 11 }
it 'does not accept the license' do
expect(new_license).not_to be_valid
end
end
end
end
end
end
describe "Historical active user count" do
let(:active_user_count) { described_class.current_active_users.count + 10 }
let(:date) { described_class.current.starts_at }
......
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