Commit d598d2a8 authored by Corinna Wiesner's avatar Corinna Wiesner

Remove cloud_license_enabled application setting

All feature for cloud licensing were previously guarded with the
application setting cloud_license_enabled. This setting is not needed
anymore and can be removed. All features that were guarded with this
setting will now be the default behavior.

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65538
EE: true
parent 1f4ce96d
......@@ -82,7 +82,7 @@ class Admin::LicensesController < Admin::ApplicationController
end
def check_cloud_license
redirect_to admin_subscription_path if Gitlab::CurrentSettings.cloud_license_enabled?
redirect_to admin_subscription_path
end
def license_params
......
......@@ -5,17 +5,5 @@ class Admin::SubscriptionsController < Admin::ApplicationController
feature_category :license
before_action :require_cloud_license_enabled
def show; end
private
def require_cloud_license_enabled
redirect_to admin_license_path unless cloud_license_enabled?
end
def cloud_license_enabled?
Gitlab::CurrentSettings.cloud_license_enabled?
end
end
......@@ -10,8 +10,6 @@ module Resolvers
type ::Types::Admin::CloudLicenses::CurrentLicenseType, null: true
def resolve
return unless application_settings.cloud_license_enabled?
authorize!
license
......@@ -19,10 +17,6 @@ module Resolvers
private
def application_settings
Gitlab::CurrentSettings.current_application_settings
end
def authorize!
Ability.allowed?(context[:current_user], :read_licenses) || raise_resource_not_available_error!
end
......
......@@ -9,8 +9,6 @@ module Resolvers
type [::Types::Admin::CloudLicenses::LicenseHistoryEntryType], null: true
def resolve
return unless application_settings.cloud_license_enabled?
authorize!
License.history
......@@ -18,10 +16,6 @@ module Resolvers
private
def application_settings
Gitlab::CurrentSettings.current_application_settings
end
def authorize!
Ability.allowed?(context[:current_user], :read_licenses) || raise_resource_not_available_error!
end
......
# frozen_string_literal: true
module Admin
module NavbarHelper
def navbar_controller_path
cloud_license_enabled? ? 'admin/subscriptions' : 'admin/licenses'
end
def navbar_item_name
cloud_license_enabled? ? _('Subscription') : _('License')
end
def navbar_item_path
cloud_license_enabled? ? admin_subscription_path : admin_license_path
end
private
def cloud_license_enabled?
Gitlab::CurrentSettings.cloud_license_enabled?
end
end
end
......@@ -5,13 +5,11 @@
module GitlabSubscriptions
class ActivateService
ERROR_MESSAGES = {
not_self_managed: 'Not self-managed instance',
disabled: 'Cloud licensing is disabled'
not_self_managed: 'Not self-managed instance'
}.freeze
def execute(activation_code)
return error(ERROR_MESSAGES[:not_self_managed]) if Gitlab.com?
return error(ERROR_MESSAGES[:disabled]) unless application_settings.cloud_license_enabled?
response = client.activate(activation_code)
......@@ -39,10 +37,6 @@ module GitlabSubscriptions
{ success: false, errors: Array(message) }
end
def application_settings
Gitlab::CurrentSettings.current_application_settings
end
def find_or_initialize_cloud_license(license_key)
return License.current.reset if License.current_cloud_license?(license_key)
......
= nav_link(controller: navbar_controller_path) do
= link_to navbar_item_path, class: "qa-link-license-menu" do
= nav_link(controller: 'admin/subscriptions') do
= link_to admin_subscription_path, class: "qa-link-license-menu" do
.nav-icon-container
= sprite_icon('license')
%span.nav-item-name
= navbar_item_name
= _('Subscription')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(controller: controller, html_options: { class: "fly-out-top-item" } ) do
= link_to navbar_item_path do
= link_to admin_subscription_path do
%strong.fly-out-top-item-name
= navbar_item_name
= _('Subscription')
......@@ -89,17 +89,8 @@ RSpec.describe Admin::LicensesController do
describe 'GET show' do
context 'with an existent license' do
it 'renders the license details' do
allow(License).to receive(:current).and_return(create(:license))
get :show
expect(response).to render_template(:show)
end
it 'redirects to new path when a valid license is entered/uploaded' do
allow(License).to receive(:current).and_return(create(:license))
stub_application_setting(cloud_license_enabled: true)
get :show
......@@ -113,7 +104,7 @@ RSpec.describe Admin::LicensesController do
get :show
expect(response).to render_template(:missing)
expect(response).to redirect_to(admin_subscription_path)
end
end
end
......
......@@ -36,50 +36,6 @@ RSpec.describe "Admin uploads license", :js do
end
end
context "when license key is provided in the query string" do
before do
License.destroy_all # rubocop: disable Cop/DestroyAll
visit(admin_license_path(trial_key: license.data))
page.within("#modal-upload-trial-license") do
expect(page).to have_content("Your trial license was issued").and have_button("Install license")
end
click_button("Install license")
end
context "when license is active immediately" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
it "installs license" do
expect(page).to have_content("The license was successfully uploaded and is now active")
end
end
context "when license starts in the future" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }, starts_at: Date.current + 1.month).export) }
it "installs license" do
expect(page).to have_content("The license was successfully uploaded and will be active from #{license.starts_at}. You can see the details below.")
.and have_content("You have a license that activates at a future date. Please see the License History table below.")
end
end
end
context "when license key is not provided in the query string, as it is a repeat trial" do
before do
License.destroy_all # rubocop: disable Cop/DestroyAll
visit(admin_license_path(trial_key: ""))
end
it "shows an info banner for repeat trial" do
expect(page).to have_selector('div#repeat-trial-info')
expect(page).to have_selector('div.bs-callout-info')
end
end
context "uploading license" do
before do
visit(new_admin_license_path)
......@@ -122,8 +78,6 @@ RSpec.describe "Admin uploads license", :js do
attach_and_upload(path)
expect(page).to have_content("The license was successfully uploaded and will be active from #{license.starts_at}. You can see the details below.")
.and have_content(license.licensee.each_value.first)
.and have_content("You have a license that activates at a future date. Please see the License History table below.")
end
end
end
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "Admin views license" do
let_it_be(:admin) { create(:admin) }
require 'spec_helper'
RSpec.describe 'Admin views license' do
before do
admin = create(:admin)
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(Date.today - 45.days)
end
context "when license is valid" do
before do
visit(admin_license_path)
end
it "shows license" do
expect(page).to have_content("Your license is valid")
page.within(".license-panel") do
expect(page).to have_content("Unlimited")
end
end
end
context "when license is regular" do
let_it_be(:license) { create(:license) }
let_it_be(:reference_date) { Date.parse('2020-01-22') }
context "when license is expired" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 1.day).export).save!(validate: false) }
it do
travel_to(reference_date) do
visit(admin_license_path)
expect(page).to have_content("Your subscription expired!")
expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
context "when license blocks changes" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 1.week).export).save!(validate: false) }
it do
travel_to(reference_date) do
visit(admin_license_path)
expect(page).to have_content 'You have 7 days to renew your subscription.'
expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
end
context "when license blocks changes" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 4.weeks, block_changes_at: reference_date - 1.day).export).save!(validate: false) }
it do
travel_to(reference_date) do
visit(admin_license_path)
expect(page).to have_content 'Please delete your current license if you want to downgrade to the free plan'
expect(page).to have_link 'Upgrade your plan', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
end
end
context "when viewing license history", :aggregate_failures do
before do
visit(admin_license_path)
end
it "shows licensee" do
license_history = page.find("#license_history")
License.history.each do |license|
expect(license_history).to have_content(license.licensee.each_value.first)
end
end
it "highlights the current license with a css class", :aggregate_failures do
license_history = page.find("#license_history")
highlighted_license_row = license_history.find("[data-testid='license-current']")
expect(highlighted_license_row).to have_content(license.licensee.fetch('Name'))
expect(highlighted_license_row).to have_content(license.licensee.fetch('Email'))
expect(highlighted_license_row).to have_content(license.licensee.fetch('Company'))
expect(highlighted_license_row).to have_content(license.plan.capitalize)
expect(highlighted_license_row).to have_content(I18n.l(license.created_at, format: :with_timezone))
expect(highlighted_license_row).to have_content(I18n.l(license.starts_at))
expect(highlighted_license_row).to have_content(I18n.l(license.expires_at))
end
end
end
context "with limited users" do
let_it_be(:license) { create(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
before do
it 'gets redirected to the new subscription page' do
visit(admin_license_path)
end
it "shows panel counts" do
page.within(".license-panel") do
expect(page).to have_content("2,000")
end
end
end
context "when existing licenses only contain a future-dated license" do
let_it_be(:license) { create(:license, data: create(:gitlab_license, starts_at: Date.current + 1.month).export) }
before do
License.where.not(id: license.id).delete_all
visit(admin_license_path)
end
context "when viewing license history" do
it "shows licensee" do
license_history = page.find("#license_history")
expect(license_history).to have_content(license.licensee.each_value.first)
end
it "has no highlighted license", :aggregate_failures do
license_history = page.find("#license_history")
expect(license_history).not_to have_selector("[data-testid='license-current']")
end
it "shows only the future-dated license", :aggregate_failures do
license_history = page.find("#license_history")
license_history_row = license_history.find('tbody tr', match: :first)
expect(license_history).to have_css('tbody tr', count: 1)
expect(license_history_row).to have_content(license.licensee.fetch('Name'))
expect(license_history_row).to have_content(license.licensee.fetch('Email'))
expect(license_history_row).to have_content(license.licensee.fetch('Company'))
expect(license_history_row).to have_content(license.plan.capitalize)
expect(license_history_row).to have_content(I18n.l(license.created_at, format: :with_timezone))
expect(license_history_row).to have_content(I18n.l(license.starts_at))
expect(license_history_row).to have_content(I18n.l(license.expires_at))
end
end
end
describe 'qrtly reconciliation alert', :js do
context 'on self-managed' do
context 'when qrtly reconciliation is available' do
let_it_be(:reconciliation) { create(:upcoming_reconciliation, :self_managed) }
before do
visit(admin_license_path)
end
it_behaves_like 'a visible dismissible qrtly reconciliation alert'
end
context 'when qrtly reconciliation is not available' do
before do
visit(admin_license_path)
end
it_behaves_like 'a hidden qrtly reconciliation alert'
end
end
context 'on dotcom' do
before do
visit(admin_license_path)
end
it_behaves_like 'a hidden qrtly reconciliation alert'
end
expect(page).to have_current_path(admin_subscription_path)
end
end
......@@ -8,7 +8,6 @@ RSpec.describe 'Admin views Subscription', :js do
before do
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
stub_application_setting(cloud_license_enabled: true)
end
context 'with a cloud license' do
......
......@@ -19,18 +19,6 @@ RSpec.describe Resolvers::Admin::CloudLicenses::CurrentLicenseResolver do
resolve(described_class, ctx: { current_user: current_user })
end
before do
stub_application_setting(cloud_license_enabled: true)
end
context 'when application setting for cloud license is disabled', :enable_admin_mode do
it 'returns nil' do
stub_application_setting(cloud_license_enabled: false)
expect(result).to be_nil
end
end
context 'when current user is unauthorized' do
it 'raises error' do
unauthorized_user = create(:user)
......
......@@ -19,18 +19,6 @@ RSpec.describe Resolvers::Admin::CloudLicenses::LicenseHistoryEntriesResolver do
resolve(described_class, ctx: { current_user: current_user })
end
before do
stub_application_setting(cloud_license_enabled: true)
end
context 'when application setting for cloud license is disabled', :enable_admin_mode do
it 'returns nil' do
stub_application_setting(cloud_license_enabled: false)
expect(result).to be_nil
end
end
context 'when current user is unauthorized' do
it 'raises error' do
unauthorized_user = create(:user)
......
......@@ -25,10 +25,6 @@ RSpec.describe GitlabSchema.types['CurrentLicense'], :enable_admin_mode do
%w[last_sync billable_users_count maximum_user_count users_over_license_count]
end
before do
stub_application_setting(cloud_license_enabled: true)
end
it { expect(described_class.graphql_name).to eq('CurrentLicense') }
it { expect(described_class).to include_graphql_fields(*fields) }
......
......@@ -30,10 +30,6 @@ RSpec.describe GitlabSchema.types['LicenseHistoryEntry'], :enable_admin_mode do
GitlabSchema.execute(query(field_name), context: { current_user: admin }).as_json
end
before do
stub_application_setting(cloud_license_enabled: true)
end
it { expect(described_class.graphql_name).to eq('LicenseHistoryEntry') }
include_examples 'license type fields', ['data', 'licenseHistoryEntries', 'nodes', -1]
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Admin::NavbarHelper do
let_it_be(:current_user) { build(:user) }
describe 'when cloud license is enabled' do
before do
stub_application_setting(cloud_license_enabled: true)
end
it 'returns the correct controller path' do
expect(helper.navbar_controller_path).to eq('admin/subscriptions')
end
it 'returns the correct navbar item name' do
expect(helper.navbar_item_name).to eq('Subscription')
end
it 'returns the correct navbar item path' do
expect(helper.navbar_item_path).to eq(admin_subscription_path)
end
end
describe 'when cloud license is not enabled' do
before do
stub_application_setting(cloud_license_enabled: false)
end
it 'returns the correct controller path' do
expect(helper.navbar_controller_path).to eq('admin/licenses')
end
it 'returns the correct navbar item name' do
expect(helper.navbar_item_name).to eq('License')
end
it 'returns the correct navbar item path' do
expect(helper.navbar_item_path).to eq(admin_license_path)
end
end
end
......@@ -26,23 +26,6 @@ RSpec.describe Admin::SubscriptionsController, :cloud_licenses do
enable_admin_mode!(admin)
end
context 'when the application setting is not active' do
before do
stub_application_setting(cloud_license_enabled: false)
end
it 'redirects to admin license path when the setting is not active' do
send_request
expect(response).to redirect_to admin_license_path
end
end
context 'when the application setting is active' do
before do
stub_application_setting(cloud_license_enabled: true)
end
it 'renders the Activation Form' do
send_request
......@@ -51,7 +34,6 @@ RSpec.describe Admin::SubscriptionsController, :cloud_licenses do
end
end
end
end
def send_request
get admin_subscription_path
......
......@@ -15,7 +15,7 @@ RSpec.describe 'Activate a subscription' do
let!(:application_setting) do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
create(:application_setting, cloud_license_enabled: true)
create(:application_setting)
end
let(:remote_response) do
......
......@@ -7,12 +7,10 @@ RSpec.describe GitlabSubscriptions::ActivateService do
let!(:application_settings) do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
create(:application_setting, cloud_license_enabled: cloud_license_enabled)
end
let_it_be(:license_key) { build(:gitlab_license, :cloud).export }
let(:cloud_license_enabled) { true }
let(:activation_code) { 'activation_code' }
def stub_client_activate
......@@ -115,17 +113,6 @@ RSpec.describe GitlabSubscriptions::ActivateService do
end
end
context 'when cloud licensing disabled' do
let(:customer_dot_response) { { success: false, errors: [described_class::ERROR_MESSAGES[:disabled]] }}
let(:cloud_license_enabled) { false }
it 'returns error' do
expect(Gitlab::SubscriptionPortal::Client).not_to receive(:activate)
expect(execute_service).to eq(customer_dot_response)
end
end
context 'when error is raised' do
it 'captures error' do
expect(Gitlab::SubscriptionPortal::Client).to receive(:activate).and_raise('foo')
......
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