Commit 62d53a43 authored by Corinna Wiesner's avatar Corinna Wiesner Committed by Matthias Käppler

Allow 10% overage for true-ups when uploading a license

The 10% overage when uploading a license was only applied to the users
in the license but not true-ups. Now, true-ups will also use a 10%
overage.

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67508
EE: true
parent 96294925
...@@ -685,7 +685,7 @@ class License < ApplicationRecord ...@@ -685,7 +685,7 @@ class License < ApplicationRecord
max_historical - daily_billable_users_count max_historical - daily_billable_users_count
end end
if trueup_qty >= expected_trueup_qty if trueup_quantity_with_threshold >= expected_trueup_qty
check_restricted_user_count check_restricted_user_count
else else
message = ["You have applied a True-up for #{trueup_qty} #{"user".pluralize(trueup_qty)}"] message = ["You have applied a True-up for #{trueup_qty} #{"user".pluralize(trueup_qty)}"]
...@@ -696,8 +696,12 @@ class License < ApplicationRecord ...@@ -696,8 +696,12 @@ class License < ApplicationRecord
end end
end end
def trueup_quantity_with_threshold
(restrictions[:trueup_quantity] * (1 + ALLOWED_PERCENTAGE_OF_USERS_OVERAGE)).to_i
end
def check_restricted_user_count def check_restricted_user_count
return unless restricted_user_count && restricted_user_count < daily_billable_users_count return unless restricted_user_count && restricted_user_count_with_threshold < daily_billable_users_count
add_limit_error(user_count: daily_billable_users_count) add_limit_error(user_count: daily_billable_users_count)
end end
......
...@@ -60,25 +60,41 @@ RSpec.describe License do ...@@ -60,25 +60,41 @@ RSpec.describe License do
end end
end end
context 'when quantity is ok' do context 'when quantity with threshold is more than the required quantity' do
before do before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 10) set_restrictions(restricted_user_count: 10, trueup_quantity: 10)
end end
it { is_expected.to be_valid } it { is_expected.to be_valid }
context 'but active users exceeds restricted user count' do context 'but active users with threshold exceeds restricted user count' do
before do before do
create_list(:user, 6) create_list(:user, 12)
end end
it { is_expected.not_to be_valid } it { is_expected.not_to be_valid }
end end
end end
context 'when quantity is wrong' do context 'when quantity with threshold is equal to the required quantity' do
before do before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 8) set_restrictions(restricted_user_count: 10, trueup_quantity: 11)
end
it { is_expected.to be_valid }
context 'but active users with threshold exceeds restricted user count' do
before do
create_list(:user, 12)
end
it { is_expected.not_to be_valid }
end
end
context 'when quantity with threshold is less than the required quantity' do
before do
set_restrictions(restricted_user_count: 10, trueup_quantity: 8)
end end
it { is_expected.not_to be_valid } it { is_expected.not_to be_valid }
...@@ -115,26 +131,32 @@ RSpec.describe License do ...@@ -115,26 +131,32 @@ RSpec.describe License do
describe '#check_restricted_user_count' do describe '#check_restricted_user_count' do
context 'when reconciliation_completed is true' do context 'when reconciliation_completed is true' do
context 'when restricted_user_count is equal or more than active_user_count' do before do
before do set_restrictions(restricted_user_count: 10, reconciliation_completed: true)
set_restrictions(restricted_user_count: 10, reconciliation_completed: true) create_list(:user, user_count)
end create(:historical_data, recorded_at: described_class.current.starts_at, active_user_count: 100)
end
context 'when restricted_user_count with threshold is more than active_user_count' do
let(:user_count) { 10 }
it { is_expected.to be_valid } it { is_expected.to be_valid }
end end
context 'when the restricted_user_count is less than active_user_count' do context 'when restricted_user_count with threshold is equal than active_user_count' do
before do let(:user_count) { 11 }
set_restrictions(restricted_user_count: 2, reconciliation_completed: true)
create_list(:user, 6) it { is_expected.to be_valid }
create(:historical_data, recorded_at: described_class.current.starts_at, active_user_count: 100) end
end
context 'when the restricted_user_count with threshold is less than active_user_count' do
let(:user_count) { 12 }
it 'add limit error' do it 'add limit error' do
expect(license.valid?).to be_falsey expect(license.valid?).to be_falsey
expect(license.errors.full_messages.to_sentence).to include( expect(license.errors.full_messages.to_sentence).to include(
'This GitLab installation currently has 6 active users, exceeding this license\'s limit of 2 by 4 users' 'This GitLab installation currently has 12 active users, exceeding this license\'s limit of 10 by 2 users'
) )
expect(license.errors.full_messages.to_sentence).not_to include( expect(license.errors.full_messages.to_sentence).not_to include(
'During the year before this license started' 'During the year before this license started'
...@@ -144,10 +166,10 @@ RSpec.describe License do ...@@ -144,10 +166,10 @@ RSpec.describe License do
end end
context 'when reconciliation_completed is false' do context 'when reconciliation_completed is false' do
context 'when the restricted_user_count is less than active_user_count' do context 'when the restricted_user_count with threshold is less than active_user_count' do
before do before do
set_restrictions(restricted_user_count: 2, reconciliation_completed: false) set_restrictions(restricted_user_count: 10, reconciliation_completed: false)
create_list(:user, 6) create_list(:user, 12)
create(:historical_data, recorded_at: described_class.current.starts_at, active_user_count: 100) create(:historical_data, recorded_at: described_class.current.starts_at, active_user_count: 100)
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