Commit 7f6604f5 authored by Stan Hu's avatar Stan Hu

Merge branch '324090-cloud-license-skip-user-limit-validation' into 'master'

Skip user limit validation when saving cloud licenses

See merge request gitlab-org/gitlab!56260
parents 0ac6ffdd ba26bb06
......@@ -7,6 +7,7 @@ class License < ApplicationRecord
STARTER_PLAN = 'starter'.freeze
PREMIUM_PLAN = 'premium'.freeze
ULTIMATE_PLAN = 'ultimate'.freeze
CLOUD_LICENSE_TYPE = 'cloud'
ALLOWED_PERCENTAGE_OF_USERS_OVERAGE = (10 / 100.0).freeze
EE_ALL_PLANS = [STARTER_PLAN, PREMIUM_PLAN, ULTIMATE_PLAN].freeze
......@@ -545,6 +546,10 @@ class License < ApplicationRecord
starts_at > Date.current
end
def cloud?
license&.type == CLOUD_LICENSE_TYPE
end
def auto_renew
false
end
......@@ -615,6 +620,7 @@ class License < ApplicationRecord
end
def check_users_limit
return if cloud?
return unless restricted_user_count
if previous_user_count && (prior_historical_max <= previous_user_count)
......
---
title: Skip user limit validation when saving cloud licenses
merge_request: 56260
author:
type: added
......@@ -68,14 +68,13 @@ RSpec.describe License do
context 'threshold for users overage' do
let(:current_active_users_count) { 0 }
let(:new_license) do
gl_license = build(
let(:new_license) { build(:license, data: gitlab_license.export) }
let(:gitlab_license) do
build(
:gitlab_license,
starts_at: Date.current,
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
......@@ -101,6 +100,21 @@ RSpec.describe License do
it 'does not accept the license' do
expect(new_license).not_to be_valid
end
context 'when license is a cloud license' do
let(:gitlab_license) do
build(
:gitlab_license,
type: described_class::CLOUD_LICENSE_TYPE,
starts_at: Date.current,
restrictions: { active_user_count: 10, previous_user_count: previous_user_count }
)
end
it 'accepts the license' do
expect(new_license).to be_valid
end
end
end
end
......@@ -1375,6 +1389,28 @@ RSpec.describe License do
end
end
describe '#cloud?' do
subject { license.cloud? }
context 'when no license provided' do
before do
license.data = nil
end
it { is_expected.to be false }
end
context 'when the license is not a cloud license' do
it { is_expected.to be false }
end
context 'when the license is a cloud license' do
let(:gl_license) { build(:gitlab_license, type: described_class::CLOUD_LICENSE_TYPE) }
it { is_expected.to be true }
end
end
describe '#auto_renew' do
it 'is false' do
expect(license.auto_renew).to be false
......
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