Commit 98215f5e authored by Corinna Wiesner's avatar Corinna Wiesner

Allow offline cloud license upload

Allow the upload of offline cloud licenses in the admin area.

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79957
EE: true
parent f536b8cd
...@@ -20,7 +20,7 @@ class Admin::LicensesController < Admin::ApplicationController ...@@ -20,7 +20,7 @@ class Admin::LicensesController < Admin::ApplicationController
@license = License.new(license_params) @license = License.new(license_params)
return upload_license_error if @license.cloud_license? return upload_license_error if @license.online_cloud_license?
respond_with(@license, location: admin_subscription_path) do respond_with(@license, location: admin_subscription_path) do
if @license.save if @license.save
......
...@@ -590,6 +590,10 @@ class License < ApplicationRecord ...@@ -590,6 +590,10 @@ class License < ApplicationRecord
!!license&.offline_cloud_licensing? !!license&.offline_cloud_licensing?
end end
def online_cloud_license?
cloud_license? && !offline_cloud_license?
end
def customer_service_enabled? def customer_service_enabled?
!!license&.operational_metrics? !!license&.operational_metrics?
end end
......
...@@ -22,15 +22,29 @@ RSpec.describe Admin::LicensesController do ...@@ -22,15 +22,29 @@ RSpec.describe Admin::LicensesController do
end end
context 'when the license is for a cloud license' do context 'when the license is for a cloud license' do
it 'redirects back' do context 'with offline cloud license' do
license = build_license(cloud_licensing_enabled: true) it 'redirects to the subscription page when a valid license is entered/uploaded' do
license = build_license(cloud_licensing_enabled: true, offline_cloud_licensing_enabled: true)
expect do expect do
post :create, params: { license: { data: license.data } } post :create, params: { license: { data: license.data } }
end.not_to change(License, :count) end.to change(License, :count).by(1)
expect(response).to redirect_to(admin_subscription_path)
end
end
context 'with online cloud license' do
it 'redirects back' do
license = build_license(cloud_licensing_enabled: true)
expect do
post :create, params: { license: { data: license.data } }
end.not_to change(License, :count)
expect(response).to redirect_to new_admin_license_path expect(response).to redirect_to new_admin_license_path
expect(flash[:alert]).to include 'Please enter or upload a valid license.' expect(flash[:alert]).to include 'Please enter or upload a valid license.'
end
end end
end end
...@@ -69,7 +83,7 @@ RSpec.describe Admin::LicensesController do ...@@ -69,7 +83,7 @@ RSpec.describe Admin::LicensesController do
end end
end end
def build_license(cloud_licensing_enabled: false, restrictions: {}) def build_license(cloud_licensing_enabled: false, offline_cloud_licensing_enabled: false, restrictions: {})
license_restrictions = { license_restrictions = {
trial: false, trial: false,
plan: License::PREMIUM_PLAN, plan: License::PREMIUM_PLAN,
...@@ -80,6 +94,7 @@ RSpec.describe Admin::LicensesController do ...@@ -80,6 +94,7 @@ RSpec.describe Admin::LicensesController do
gl_license = build( gl_license = build(
:gitlab_license, :gitlab_license,
cloud_licensing_enabled: cloud_licensing_enabled, cloud_licensing_enabled: cloud_licensing_enabled,
offline_cloud_licensing_enabled: offline_cloud_licensing_enabled,
restrictions: license_restrictions restrictions: license_restrictions
) )
......
...@@ -1516,6 +1516,36 @@ RSpec.describe License do ...@@ -1516,6 +1516,36 @@ RSpec.describe License do
end end
end end
describe '#online_cloud_license?' do
subject { license.online_cloud_license? }
context 'when no license provided' do
before do
license.data = nil
end
it { is_expected.to be false }
end
context 'when the license has cloud licensing and offline cloud licensing enabled' do
let(:gl_license) { build(:gitlab_license, :cloud, :offline_enabled) }
it { is_expected.to be false }
end
context 'when the license has cloud licensing enabled and offline cloud licensing disabled' do
let(:gl_license) { build(:gitlab_license, :cloud, :offline_disabled) }
it { is_expected.to be true }
end
context 'when the license has cloud licensing and offline cloud licensing disabled' do
let(:gl_license) { build(:gitlab_license) }
it { is_expected.to be false }
end
end
describe '#customer_service_enabled?' do describe '#customer_service_enabled?' do
subject { license.customer_service_enabled? } subject { license.customer_service_enabled? }
......
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