Commit 2aec9150 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '349611_modify_license_upload' into 'master'

Allow offline cloud license upload

See merge request gitlab-org/gitlab!79957
parents fd10ab10 98215f5e
......@@ -20,7 +20,7 @@ class Admin::LicensesController < Admin::ApplicationController
@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
if @license.save
......
......@@ -590,6 +590,10 @@ class License < ApplicationRecord
!!license&.offline_cloud_licensing?
end
def online_cloud_license?
cloud_license? && !offline_cloud_license?
end
def customer_service_enabled?
!!license&.operational_metrics?
end
......
......@@ -22,6 +22,19 @@ RSpec.describe Admin::LicensesController do
end
context 'when the license is for a cloud license' do
context 'with offline cloud license' do
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
post :create, params: { license: { data: license.data } }
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)
......@@ -33,6 +46,7 @@ RSpec.describe Admin::LicensesController do
expect(flash[:alert]).to include 'Please enter or upload a valid license.'
end
end
end
it 'renders new with an alert when an invalid license is entered/uploaded' do
expect do
......@@ -69,7 +83,7 @@ RSpec.describe Admin::LicensesController do
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 = {
trial: false,
plan: License::PREMIUM_PLAN,
......@@ -80,6 +94,7 @@ RSpec.describe Admin::LicensesController do
gl_license = build(
:gitlab_license,
cloud_licensing_enabled: cloud_licensing_enabled,
offline_cloud_licensing_enabled: offline_cloud_licensing_enabled,
restrictions: license_restrictions
)
......
......@@ -1516,6 +1516,36 @@ RSpec.describe License do
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
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