diff --git a/app/views/admin/application_settings/general.html.haml b/app/views/admin/application_settings/general.html.haml index bc2fedec69c2cd1cef0587d01719e7ae846460eb..66b8b783ac2a6b94d15ac14a2c935917c58ed0b8 100644 --- a/app/views/admin/application_settings/general.html.haml +++ b/app/views/admin/application_settings/general.html.haml @@ -115,4 +115,4 @@ = render 'admin/application_settings/snowplow' = render 'admin/application_settings/eks' = render 'admin/application_settings/floc' -= render_if_exists 'admin/application_settings/license_file' += render_if_exists 'admin/application_settings/add_license' diff --git a/doc/user/admin_area/license_file.md b/doc/user/admin_area/license_file.md index 5999e774d26cfa38b9b6bf6aa4e7be2b99758e23..ff9e87680f9e9471ccd6646aefa1aaccc372eb04 100644 --- a/doc/user/admin_area/license_file.md +++ b/doc/user/admin_area/license_file.md @@ -18,8 +18,7 @@ Otherwise, to add your license: 1. Sign in to GitLab as an administrator. 1. On the top bar, select **Menu > Admin**. 1. On the left sidebar, select **Settings > General**. -1. In the **License file** area, select **Add a license**. -1. Add a license by either uploading the file or pasting the key. +1. In the **Add License** area, add a license by either uploading the file or entering the key. 1. Select the **Terms of Service** checkbox. 1. Select **Add license**. diff --git a/ee/app/assets/javascripts/admin/application_settings/general/add_license.js b/ee/app/assets/javascripts/admin/application_settings/general/add_license.js new file mode 100644 index 0000000000000000000000000000000000000000..394a3db54fccfbc28e9686ff2cd7c3c68a007601 --- /dev/null +++ b/ee/app/assets/javascripts/admin/application_settings/general/add_license.js @@ -0,0 +1,40 @@ +import Vue from 'vue'; +import LicenseDropzone from 'ee/admin/application_settings/general/components/license_dropzone.vue'; + +export default function initAddLicenseApp() { + const licenseFile = document.querySelector('#js-add-license-toggle .license-file'); + const licenseKey = document.querySelector('#js-add-license-toggle .license-key'); + const uploadLicenseButton = document.querySelector('#js-add-license-toggle [type="submit"]'); + const acceptEULACheckBox = document.addLicense.accept_eula; + const radioButtonList = document.addLicense.license_type; + + const showLicenseType = () => { + licenseFile.classList.toggle('hidden', radioButtonList.value === 'key'); + licenseKey.classList.toggle('hidden', radioButtonList.value === 'file'); + }; + + const toggleUploadLicenseButton = () => { + uploadLicenseButton.toggleAttribute('disabled', !acceptEULACheckBox.checked); + }; + + const initLicenseUploadDropzone = () => { + const el = document.getElementById('js-license-new-app'); + + return new Vue({ + el, + components: { + LicenseDropzone, + }, + render(createElement) { + return createElement(LicenseDropzone); + }, + }); + }; + + radioButtonList.forEach((element) => element.addEventListener('change', showLicenseType)); + acceptEULACheckBox.addEventListener('change', toggleUploadLicenseButton); + + showLicenseType(); + toggleUploadLicenseButton(); + initLicenseUploadDropzone(); +} diff --git a/ee/app/assets/javascripts/admin/licenses/new/components/license_new_app.vue b/ee/app/assets/javascripts/admin/application_settings/general/components/license_dropzone.vue similarity index 100% rename from ee/app/assets/javascripts/admin/licenses/new/components/license_new_app.vue rename to ee/app/assets/javascripts/admin/application_settings/general/components/license_dropzone.vue diff --git a/ee/app/assets/javascripts/admin/licenses/new/constants.js b/ee/app/assets/javascripts/admin/application_settings/general/constants.js similarity index 100% rename from ee/app/assets/javascripts/admin/licenses/new/constants.js rename to ee/app/assets/javascripts/admin/application_settings/general/constants.js diff --git a/ee/app/assets/javascripts/pages/admin/application_settings/general/index.js b/ee/app/assets/javascripts/pages/admin/application_settings/general/index.js index bb269761ea38352d558ae5ba157bb2ec17680aaf..991a71788176b7d6dc916d0a7bd73a584a5876d4 100644 --- a/ee/app/assets/javascripts/pages/admin/application_settings/general/index.js +++ b/ee/app/assets/javascripts/pages/admin/application_settings/general/index.js @@ -1,6 +1,8 @@ import '~/pages/admin/application_settings/general/index'; +import initAddLicenseApp from 'ee/admin/application_settings/general/add_license'; import { initMaintenanceModeSettings } from 'ee/maintenance_mode_settings'; import { initServicePingSettingsClickTracking } from 'ee/registration_features_discovery_message'; initMaintenanceModeSettings(); initServicePingSettingsClickTracking(); +initAddLicenseApp(); diff --git a/ee/app/assets/javascripts/pages/admin/licenses/new/index.js b/ee/app/assets/javascripts/pages/admin/licenses/new/index.js deleted file mode 100644 index b0a846b5fb2f8f21c5409ca71326aa1a19497a46..0000000000000000000000000000000000000000 --- a/ee/app/assets/javascripts/pages/admin/licenses/new/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import Vue from 'vue'; -import LicenseNewApp from 'ee/admin/licenses/new/components/license_new_app.vue'; - -const licenseFile = document.querySelector('.license-file'); -const licenseKey = document.querySelector('.license-key'); -const acceptEULACheckBox = document.querySelector('#accept_eula'); -const uploadLicenseBtn = document.querySelector('#js-upload-license'); -const licenseType = document.querySelectorAll('input[name="license_type"]'); - -const showLicenseType = () => { - const checkedFile = document.querySelector('input[name="license_type"]:checked').value === 'file'; - - licenseFile.classList.toggle('hidden', !checkedFile); - licenseKey.classList.toggle('hidden', checkedFile); -}; - -const toggleUploadLicenseButton = () => { - uploadLicenseBtn.toggleAttribute('disabled', !acceptEULACheckBox.checked); -}; - -const initLicenseUploadDropzone = () => { - const el = document.getElementById('js-license-new-app'); - - return new Vue({ - el, - components: { - LicenseNewApp, - }, - render(createElement) { - return createElement(LicenseNewApp); - }, - }); -}; - -licenseType.forEach((el) => el.addEventListener('change', showLicenseType)); -acceptEULACheckBox.addEventListener('change', toggleUploadLicenseButton); -showLicenseType(); -initLicenseUploadDropzone(); diff --git a/ee/app/controllers/admin/licenses_controller.rb b/ee/app/controllers/admin/licenses_controller.rb index 225d92258b52c280dbae7ee9c9dc6e9b997914ac..60fc5d8c362f0611ecfe54fe4b2cd3f094043f00 100644 --- a/ee/app/controllers/admin/licenses_controller.rb +++ b/ee/app/controllers/admin/licenses_controller.rb @@ -10,11 +10,6 @@ class Admin::LicensesController < Admin::ApplicationController feature_category :provision - def new - @content_class = 'limit-container-width' unless fluid_layout - @license ||= License.new(data: params[:trial_key]) - end - def create return upload_license_error if license_params[:data].blank? && license_params[:data_file].blank? @@ -22,16 +17,18 @@ def create return upload_license_error(cloud_license: true) if @license.online_cloud_license? - respond_with(@license, location: admin_subscription_path) do - if @license.save - notice = if @license.started? - _('The license was successfully uploaded and is now active. You can see the details below.') - else - _('The license was successfully uploaded and will be active from %{starts_at}. You can see the details below.' % { starts_at: @license.starts_at }) - end + if @license.save + notice = if @license.started? + _('The license was successfully uploaded and is now active. You can see the details below.') + else + _('The license was successfully uploaded and will be active from %{starts_at}. You can see the details below.' % { starts_at: @license.starts_at }) + end - flash[:notice] = notice - end + flash[:notice] = notice + redirect_to(admin_subscription_path) + else + flash[:alert] = @license.errors.full_messages.join.html_safe + redirect_to general_admin_application_settings_path end end @@ -82,6 +79,6 @@ def upload_license_error(cloud_license: false) end @license = License.new - redirect_to new_admin_license_path + redirect_to general_admin_application_settings_path end end diff --git a/ee/app/controllers/concerns/admin/license_request.rb b/ee/app/controllers/concerns/admin/license_request.rb index ba435237ea7387d0e3a26efa569d594ae3cf91fe..805a6662d6e4a1090cf37a8709591c8587a14b8b 100644 --- a/ee/app/controllers/concerns/admin/license_request.rb +++ b/ee/app/controllers/concerns/admin/license_request.rb @@ -16,7 +16,7 @@ def require_license return if license flash.keep - redirect_to new_admin_license_path + redirect_to general_admin_application_settings_path end end end diff --git a/ee/app/controllers/ee/admin/application_settings_controller.rb b/ee/app/controllers/ee/admin/application_settings_controller.rb index 949a5e1ae13dfdd2c78258aa4207090beb8b0d53..ee8d43f5dfcdfe0858a469bf37b0dbbe2344c617 100644 --- a/ee/app/controllers/ee/admin/application_settings_controller.rb +++ b/ee/app/controllers/ee/admin/application_settings_controller.rb @@ -38,6 +38,11 @@ def elasticsearch_warn_if_not_using_aliases define_method(action) { perform_update if submitted? } end + def general + super + @new_license ||= License.new(data: params[:trial_key]) # rubocop:disable Gitlab/ModuleWithInstanceVariables + end + def visible_application_setting_attributes attrs = super diff --git a/ee/app/helpers/license_helper.rb b/ee/app/helpers/license_helper.rb index 3c2fbcd8e7b2c0655a4b24df7a41ee9f4b8ce1f7..db4475bf8544347dafe64c5dd101102687f16cf9 100644 --- a/ee/app/helpers/license_helper.rb +++ b/ee/app/helpers/license_helper.rb @@ -3,7 +3,7 @@ module LicenseHelper include ActionView::Helpers::AssetTagHelper - delegate :new_admin_license_path, to: 'Gitlab::Routing.url_helpers' + delegate :general_admin_application_settings_path, to: 'Gitlab::Routing.url_helpers' def seats_calculation_message(license) return unless license.exclude_guests_from_active_count? diff --git a/ee/app/views/admin/application_settings/_add_license.html.haml b/ee/app/views/admin/application_settings/_add_license.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..61ac37005e5fe88ff2147b377da3ad9777bc3630 --- /dev/null +++ b/ee/app/views/admin/application_settings/_add_license.html.haml @@ -0,0 +1,50 @@ +- return unless @new_license.present? + +%section.settings#js-add-license-toggle{ class: ('expanded' if expanded_by_default?) } + .settings-header{ data: { testid: 'expand_add_license_header' } } + %h4 + = _('Add License') + %button.btn.gl-button.btn-default.js-settings-toggle{ type: 'button', data: { qa_selector: 'expand_add_license_button' } } + = expanded_by_default? ? 'Collapse' : 'Expand' + %p + - if License.current + = _('To continue using GitLab Enterprise Edition, upload the %{codeOpen}.gitlab-license%{codeClose} file or enter the license key you have received from GitLab Inc.').html_safe % {codeOpen: '<code>'.html_safe, codeClose: '</code>'.html_safe} + - else + = _('To start using GitLab Enterprise Edition, upload the %{codeOpen}.gitlab-license%{codeClose} file or enter the license key you have received from GitLab Inc.').html_safe % {codeOpen: '<code>'.html_safe, codeClose: '</code>'.html_safe} + + .settings-content + - eula_url = "https://#{ApplicationHelper.promo_host}/terms/#subscription" + - eula_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: eula_url } + + %hr + = form_for @new_license, url: admin_license_path, html: { name: 'addLicense', multipart: true, class: 'fieldset-form', autocomplete: 'off' } do |f| + .form-group + .form-check + = radio_button_tag :license_type, :file, @new_license.data.blank?, class: 'form-check-input' + = label_tag :license_type_file, class: 'form-check-label' do + .option-title + = _('Upload %{file_name} file').html_safe % { file_name: '<code>.gitlab-license</code>'.html_safe } + + .form-group.license-file.gl-mt-4 + #js-license-new-app + + .form-check.gl-my-4 + = radio_button_tag :license_type, :key, @new_license.data.present?, class: 'form-check-input', data: { qa_selector: 'license_type_key_radio' } + = label_tag :license_type_key, class: 'form-check-label' do + .option-title + = _('Enter license key') + .form-group.license-key.hidden + = f.label :data, _('License key'), class: 'gl-sr-only' + = f.text_area :data, class: "form-control license-key-field", data: { qa_selector: 'license_key_field' }, rows: 20 + + %hr + + %h4.gl-font-base= _("Terms of service") + + .form-group + = label_tag :accept_eula, nil, class: 'form-check-label' do + = check_box_tag :accept_eula, nil, false, data: { qa_selector: 'accept_eula_checkbox' } + = _('Unless otherwise agreed to in writing with GitLab, by clicking "Upload License" you agree that your use of GitLab Software is subject to the %{eula_link_start}Terms of Service%{eula_link_end}.').html_safe % { eula_link_start: eula_link_start, eula_url: eula_url, eula_link_end: '</a>'.html_safe } + + .form-actions + = f.submit 'Add license', class: 'gl-button btn btn-confirm', data: { qa_selector: 'license_upload_button' }, disabled: true diff --git a/ee/app/views/admin/application_settings/_license_file.html.haml b/ee/app/views/admin/application_settings/_license_file.html.haml deleted file mode 100644 index 4d8707f10e44ace13091089b719a01f4f4d060bc..0000000000000000000000000000000000000000 --- a/ee/app/views/admin/application_settings/_license_file.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%section.settings.expanded - .settings-header - %h4 - = _('License file') - - .settings-content - - link_start = '<a href="%{url}" data-qa-selector="license_upload_link">'.html_safe % { url: new_admin_license_path } - %p - = s_('%{link_start}Add a license%{link_end} that you have received from GitLab Inc.').html_safe % { link_start: link_start, link_end: '</a>'.html_safe } diff --git a/ee/app/views/admin/licenses/new.html.haml b/ee/app/views/admin/licenses/new.html.haml deleted file mode 100644 index e8eeba4e6994c938065ea599feb9c6abfc76f221..0000000000000000000000000000000000000000 --- a/ee/app/views/admin/licenses/new.html.haml +++ /dev/null @@ -1,55 +0,0 @@ -- page_title _("Add License") -- eula_url = "https://#{ApplicationHelper.promo_host}/terms/#subscription" -- eula_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: eula_url } -%h3.page-title= _('Add License') - -%p.light - - if License.current - = _('To continue using GitLab Enterprise Edition, upload the %{codeOpen}.gitlab-license%{codeClose} file or enter the license key you have received from GitLab Inc.').html_safe % {codeOpen: '<code>'.html_safe, codeClose: '</code>'.html_safe} - - else - = _('To start using GitLab Enterprise Edition, upload the %{codeOpen}.gitlab-license%{codeClose} file or enter the license key you have received from GitLab Inc.').html_safe % {codeOpen: '<code>'.html_safe, codeClose: '</code>'.html_safe} - -%hr -= form_for @license, url: admin_license_path, html: { multipart: true, class: 'fieldset-form' } do |f| - - if @license.errors.any? - #error_explanation - .gl-alert.gl-alert-danger.gl-mb-5 - = sprite_icon('warning', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title') - .gl-alert-body - %p= _('The form contains the following errors:') - %details - %summary= n_('%d error found:', '%d errors found:', @license.errors.full_messages.length) % @license.errors.full_messages.length - %ul - - @license.errors.full_messages.each do |msg| - %li= msg - - .form-group - .form-check - = radio_button_tag :license_type, :file, @license.data.blank?, class: 'form-check-input' - = label_tag :license_type_file, class: 'form-check-label' do - .option-title - = _('Upload %{file_name} file').html_safe % { file_name: '<code>.gitlab-license</code>'.html_safe } - - .form-group.license-file.gl-mt-4 - #js-license-new-app - - .form-check.gl-my-4 - = radio_button_tag :license_type, :key, @license.data.present?, class: 'form-check-input', data: { qa_selector: 'license_type_key_radio' } - = label_tag :license_type_key, class: 'form-check-label' do - .option-title - = _('Enter license key') - .form-group.license-key.hidden - = f.label :data, _('License key'), class: 'gl-sr-only' - = f.text_area :data, class: "form-control license-key-field", data: { qa_selector: 'license_key_field' }, rows: 20 - - %hr - - %h4.gl-font-base= _("Terms of service") - - .form-group - = label_tag :accept_eula, nil, class: 'form-check-label' do - = check_box_tag :accept_eula, nil, false, data: { qa_selector: 'accept_eula_checkbox' } - = _('Unless otherwise agreed to in writing with GitLab, by clicking "Upload License" you agree that your use of GitLab Software is subject to the %{eula_link_start}Terms of Service%{eula_link_end}.').html_safe % { eula_link_start: eula_link_start, eula_url: eula_url, eula_link_end: '</a>'.html_safe } - - .form-actions - = f.submit 'Add license', class: 'gl-button btn btn-confirm', data: { qa_selector: 'license_upload_button' }, disabled: true, id: 'js-upload-license' diff --git a/ee/app/views/shared/_manual_quarterly_reconciliation_banner.html.haml b/ee/app/views/shared/_manual_quarterly_reconciliation_banner.html.haml index 12371357343f78a7b12a466baaefb4fc5d78af9e..f0b62430ce9397bb43973120e55e170cccd6f757 100644 --- a/ee/app/views/shared/_manual_quarterly_reconciliation_banner.html.haml +++ b/ee/app/views/shared/_manual_quarterly_reconciliation_banner.html.haml @@ -12,4 +12,4 @@ = payload.body = c.actions do = link_to s_('SubscriptionBanner|Export license usage file'), admin_license_usage_export_path(format: :csv), class: 'btn gl-alert-action gl-button btn-confirm' - = link_to s_('SubscriptionBanner|Add new license'), new_admin_license_path, class: 'btn gl-alert-action gl-button btn-default' + = link_to s_('SubscriptionBanner|Add new license'), general_admin_application_settings_path, class: 'btn gl-alert-action gl-button btn-default' diff --git a/ee/app/views/shared/_manual_renewal_banner.html.haml b/ee/app/views/shared/_manual_renewal_banner.html.haml index a454c7f6a1f346c674a3772bea85fab008fc47ba..0631f32b712ef1d84b2bb3c51ba74617f8b60c55 100644 --- a/ee/app/views/shared/_manual_renewal_banner.html.haml +++ b/ee/app/views/shared/_manual_renewal_banner.html.haml @@ -12,4 +12,4 @@ = payload.body = c.actions do = link_to s_('SubscriptionBanner|Export license usage file'), admin_license_usage_export_path(format: :csv), class: 'btn gl-alert-action gl-button btn-confirm' - = link_to s_('SubscriptionBanner|Add new license'), new_admin_license_path, class: 'btn gl-alert-action gl-button btn-default' + = link_to s_('SubscriptionBanner|Add new license'), general_admin_application_settings_path, class: 'btn gl-alert-action gl-button btn-default' diff --git a/ee/config/routes/admin.rb b/ee/config/routes/admin.rb index bc051dc76deb47f9c651bf5a430e676864f23a16..1e221a545695a30aa136d4f595c19004abcbc8a5 100644 --- a/ee/config/routes/admin.rb +++ b/ee/config/routes/admin.rb @@ -30,7 +30,7 @@ end resources :user_permission_exports, controller: 'user_permission_exports', only: [:index] - resource :license, only: [:show, :new, :create, :destroy] do + resource :license, only: [:show, :create, :destroy] do get :download, on: :member post :sync_seat_link, on: :collection diff --git a/ee/spec/controllers/admin/licenses_controller_spec.rb b/ee/spec/controllers/admin/licenses_controller_spec.rb index 85ddf32f3ca987ce355e2df01ca2908c7fc50908..56e3d3e5d2b1a9136c45a0ada97117d0776acb3a 100644 --- a/ee/spec/controllers/admin/licenses_controller_spec.rb +++ b/ee/spec/controllers/admin/licenses_controller_spec.rb @@ -17,7 +17,7 @@ post :create, params: { license: { data: '' } } end.not_to change(License, :count) - expect(response).to redirect_to new_admin_license_path + expect(response).to redirect_to general_admin_application_settings_path expect(flash[:alert]).to include( 'The license you uploaded is invalid. If the issue persists, contact support at ' \ '<a href="https://support.gitlab.com">https://support.gitlab.com</a>' @@ -45,7 +45,7 @@ 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 general_admin_application_settings_path expect(flash[:alert]).to include( html_escape("It looks like you're attempting to activate your subscription. Use %{link} instead.") % { link: "<a href=\"#{admin_subscription_path}\">the Subscription page</a>".html_safe @@ -60,8 +60,8 @@ post :create, params: { license: { data: 'GA!89-)GaRBAGE' } } end.not_to change(License, :count) - expect(response).to render_template(:new) - expect(response.body).to include(_('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.')) + expect(response).to redirect_to general_admin_application_settings_path + expect(flash[:alert]).to include(_('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.')) end it 'redirects to the subscription page when a valid license is entered/uploaded' do diff --git a/ee/spec/features/admin/admin_settings_spec.rb b/ee/spec/features/admin/admin_settings_spec.rb index 7e4ca09581d160860568dff478c20b184e9f17d5..d3b9ec5f9c01af964f30a6caa9327d87a4b67949 100644 --- a/ee/spec/features/admin/admin_settings_spec.rb +++ b/ee/spec/features/admin/admin_settings_spec.rb @@ -407,12 +407,6 @@ end end end - - context 'License file link' do - it 'provides a link to add a License file' do - expect(page).to have_link(text: 'Add a license', href: new_admin_license_path) - end - end end def current_settings diff --git a/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb b/ee/spec/features/admin/licenses/admin_adds_license_spec.rb similarity index 59% rename from ee/spec/features/admin/licenses/admin_uploads_license_spec.rb rename to ee/spec/features/admin/licenses/admin_adds_license_spec.rb index 77d81adb5ee9934d43b0a8a5bd8a7a04797d69b3..fce4e6558f437d27f7dac9746907193bb5708115 100644 --- a/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb +++ b/ee/spec/features/admin/licenses/admin_adds_license_spec.rb @@ -2,21 +2,28 @@ require "spec_helper" -RSpec.describe "Admin uploads license", :js do +RSpec.describe "Admin add license", :js do + include StubENV + let_it_be(:admin) { create(:admin) } before do + # It's important to set this variable so that we don't save a memoized + # (supposed to be) in-memory record in `Gitlab::CurrentSettings.in_memory_application_settings` + stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') sign_in(admin) gitlab_enable_admin_mode_sign_in(admin) end context 'default state' do before do - visit(new_admin_license_path) + visit(general_admin_application_settings_path) + add_license_area = find('#js-add-license-toggle') + add_license_area.click_button('Expand') if add_license_area.has_button?('Expand') end - it 'has the correct title' do - expect(page.title).to have_content("Add License") + it 'has the correct headline' do + expect(page).to have_content("Add License") end it 'has unselected EULA checkbox by default' do @@ -42,14 +49,17 @@ context "uploading license" do before do - visit(new_admin_license_path) + visit(general_admin_application_settings_path) + add_license_area = find('#js-add-license-toggle') + add_license_area.click_button('Expand') if add_license_area.has_button?('Expand') - File.write(path, license.export) + File.write(path, new_license.export) end shared_examples 'active navigation item' do - it 'activates the "Subscription" navigation item' do - expect(find('.sidebar-top-level-items > li.active')).to have_content('Subscription') + it 'activates the "Settings General" navigation item' do + expect(find('.sidebar-top-level-items > li.active')).to have_content('Settings') + expect(find('.sidebar-top-level-items > li.active')).to have_content('General') end end @@ -57,7 +67,7 @@ let_it_be(:path) { Rails.root.join("tmp/valid_license.gitlab-license") } context "when license is active immediately" do - let_it_be(:license) { build(:gitlab_license) } + let_it_be(:new_license) { build(:gitlab_license) } it_behaves_like 'active navigation item' @@ -65,12 +75,12 @@ attach_and_upload(path) expect(page).to have_content("The license was successfully uploaded and is now active.") - .and have_content(license.licensee.each_value.first) + .and have_content(new_license.licensee.each_value.first) end end context "when license starts in the future" do - let_it_be(:license) { build(:gitlab_license, starts_at: Date.current + 1.month) } + let_it_be(:new_license) { build(:gitlab_license, starts_at: Date.current + 1.month) } context "when a current license exists" do it_behaves_like 'active navigation item' @@ -78,8 +88,10 @@ it "uploads license" 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) + expect(page) + .to have_content("The license was successfully uploaded and will be active from "\ + "#{new_license.starts_at}. You can see the details below.") + .and have_content(new_license.licensee.each_value.first) end end @@ -93,14 +105,16 @@ it "uploads license" 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.") + expect(page) + .to have_content("The license was successfully uploaded and will be active from "\ + "#{new_license.starts_at}. You can see the details below.") end end end end context "when license is invalid" do - let_it_be(:license) { build(:gitlab_license, expires_at: Date.yesterday) } + let_it_be(:new_license) { build(:gitlab_license, expires_at: Date.yesterday) } let_it_be(:path) { Rails.root.join("tmp/invalid_license.gitlab-license") } it_behaves_like 'active navigation item' @@ -108,7 +122,6 @@ it "doesn't upload license" do attach_and_upload(path) - find('.gl-alert details').click expect(page).to have_content("This license has already expired.") end end diff --git a/ee/spec/features/admin/subscriptions/admin_views_subscription_spec.rb b/ee/spec/features/admin/subscriptions/admin_views_subscription_spec.rb index 4153c71187cf6aadde370b5bfdf7d4d89b281faa..3edfbaab6c1c793468701d7d5a91efbaf5a32d96 100644 --- a/ee/spec/features/admin/subscriptions/admin_views_subscription_spec.rb +++ b/ee/spec/features/admin/subscriptions/admin_views_subscription_spec.rb @@ -225,7 +225,7 @@ context 'when uploading a license file' do it 'does not show a link to activate a license file' do page.within(find('#content-body', match: :first)) do - expect(page).not_to have_link('Activate a license', href: new_admin_license_path) + expect(page).not_to have_link('Activate a license', href: general_admin_application_settings_path) end end end diff --git a/ee/spec/frontend/admin/licenses/new/components/license_new_app_spec.js b/ee/spec/frontend/admin/application_settings/general/components/license_dropzone_spec.js similarity index 91% rename from ee/spec/frontend/admin/licenses/new/components/license_new_app_spec.js rename to ee/spec/frontend/admin/application_settings/general/components/license_dropzone_spec.js index e2a7cd9366c7dd66766631924b93b025b521f1d3..6a1e02717f2d512aab571bb9677c6f52e9c8dbad 100644 --- a/ee/spec/frontend/admin/licenses/new/components/license_new_app_spec.js +++ b/ee/spec/frontend/admin/application_settings/general/components/license_dropzone_spec.js @@ -1,8 +1,8 @@ import { GlSprintf } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue'; -import LicenseNewApp from 'ee/admin/licenses/new/components/license_new_app.vue'; -import { FILE_UPLOAD_ERROR_MESSAGE } from 'ee/admin/licenses/new/constants'; +import LicenseDropzone from 'ee/admin/application_settings/general/components/license_dropzone.vue'; +import { FILE_UPLOAD_ERROR_MESSAGE } from 'ee/admin/application_settings/general/constants'; import createFlash from '~/flash'; import UploadDropzone from '~/vue_shared/components/upload_dropzone/upload_dropzone.vue'; @@ -14,7 +14,7 @@ describe('Upload dropzone component', () => { const findUploadDropzone = () => wrapper.find(UploadDropzone); function createComponent() { - wrapper = shallowMount(LicenseNewApp, { + wrapper = shallowMount(LicenseDropzone, { stubs: { GlSprintf, }, diff --git a/ee/spec/views/admin/application_settings/general.html.haml_spec.rb b/ee/spec/views/admin/application_settings/general.html.haml_spec.rb index 6bd7b73e29a9a424a0ef3ddd09da9c396f6f5e06..432eb2f582efc3a8c20fd2b89fba30bdc4088af5 100644 --- a/ee/spec/views/admin/application_settings/general.html.haml_spec.rb +++ b/ee/spec/views/admin/application_settings/general.html.haml_spec.rb @@ -51,13 +51,27 @@ end context 'with a valid license and service ping disabled' do + let(:current_license) { build(:license) } + before do - license = build(:license) - allow(License).to receive(:current).and_return(license) + allow(License).to receive(:current).and_return(current_license) stub_application_setting(usage_ping_enabled: false) end it_behaves_like 'does not render registration features prompt', :application_setting_disabled_repository_size_limit end end + + describe 'add license' do + let(:current_license) { build(:license) } + + before do + assign(:new_license, current_license) + render + end + + it 'shows the Add License section' do + expect(rendered).to have_css('#js-add-license-toggle') + end + end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 4ba531e1416142878d5e2a260073f0a324a3cb94..6eea3dd006f3e345e11190c7b108b34dd0273a6a 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -225,11 +225,6 @@ msgid_plural "%d errors" msgstr[0] "" msgstr[1] "" -msgid "%d error found:" -msgid_plural "%d errors found:" -msgstr[0] "" -msgstr[1] "" - msgid "%d exporter" msgid_plural "%d exporters" msgstr[0] "" @@ -769,9 +764,6 @@ msgstr "" msgid "%{level_name} is not allowed since the fork source project has lower visibility." msgstr "" -msgid "%{link_start}Add a license%{link_end} that you have received from GitLab Inc." -msgstr "" - msgid "%{link_start}Remove the %{draft_snippet} prefix%{link_end} from the title to allow this merge request to be merged when it's ready." msgstr "" @@ -22484,9 +22476,6 @@ msgstr "" msgid "License compliance" msgstr "" -msgid "License file" -msgstr "" - msgid "License key" msgstr "" @@ -37565,9 +37554,6 @@ msgstr[1] "" msgid "The fork relationship has been removed." msgstr "" -msgid "The form contains the following errors:" -msgstr "" - msgid "The form contains the following warning:" msgstr "" diff --git a/qa/qa/ee/page/admin/license.rb b/qa/qa/ee/page/admin/license.rb deleted file mode 100644 index 1a34af9f87e8a429ab8fc750e9766c60d94cb79f..0000000000000000000000000000000000000000 --- a/qa/qa/ee/page/admin/license.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module QA - module EE - module Page - module Admin - class License < QA::Page::Base - view 'ee/app/views/admin/application_settings/_license_file.html.haml' do - element :license_upload_link - end - - view 'ee/app/assets/javascripts/admin/subscriptions/show/components/subscription_breakdown.vue' do - element :remove_license_link - end - - view 'ee/app/views/admin/licenses/new.html.haml' do - element :accept_eula_checkbox - element :license_key_field - element :license_type_key_radio - element :license_upload_button - end - - def license? - has_element?(:remove_license_link) - end - - def add_new_license(key) - raise 'License key empty!' if key.to_s.strip.empty? - - click_element(:license_upload_link) - choose_element(:license_type_key_radio) - fill_element(:license_key_field, key.strip) - check_element(:accept_eula_checkbox) - click_element(:license_upload_button) - end - end - end - end - end -end diff --git a/qa/qa/ee/page/admin/settings/component/add_license.rb b/qa/qa/ee/page/admin/settings/component/add_license.rb new file mode 100644 index 0000000000000000000000000000000000000000..6c0d9c339919a8bcf845342ce5b071a1a7aac244 --- /dev/null +++ b/qa/qa/ee/page/admin/settings/component/add_license.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module QA + module EE + module Page + module Admin + module Settings + module Component + class AddLicense < QA::Page::Base + view 'ee/app/views/admin/application_settings/_add_license.html.haml' do + element :expand_add_license_button + element :accept_eula_checkbox + element :license_key_field + element :license_type_key_radio + element :license_upload_button + end + + def add_new_license(key) + raise 'License key empty!' if key.to_s.strip.empty? + + click_element(:expand_add_license_button) + choose_element(:license_type_key_radio) + fill_element(:license_key_field, key.strip) + check_element(:accept_eula_checkbox) + click_element(:license_upload_button) + end + end + end + end + end + end + end +end diff --git a/qa/qa/ee/page/admin/subscription.rb b/qa/qa/ee/page/admin/subscription.rb index 2c76cf20f4e096028e3cef6b3408ede07c2a5506..450ee707b76e14385be8179493411bb432cce048 100644 --- a/qa/qa/ee/page/admin/subscription.rb +++ b/qa/qa/ee/page/admin/subscription.rb @@ -5,10 +5,18 @@ module EE module Page module Admin class Subscription < QA::Page::Base + view 'ee/app/assets/javascripts/admin/subscriptions/show/components/subscription_breakdown.vue' do + element :remove_license_link + end + view 'ee/app/assets/javascripts/admin/subscriptions/show/components/subscription_details_table.vue' do element :plan, ':data-qa-selector="qaSelectorValue(item)"' # rubocop:disable QA/ElementWithPattern end + def license? + has_element?(:remove_license_link) + end + def has_ultimate_subscription_plan? has_element?(:plan, text: 'Ultimate') end diff --git a/qa/qa/ee/resource/license.rb b/qa/qa/ee/resource/license.rb index 55db061045b2f9679839cc42cb777fd4ec18e773..aba91b6254eaec6d2a7748fac3595db47a168968 100644 --- a/qa/qa/ee/resource/license.rb +++ b/qa/qa/ee/resource/license.rb @@ -9,13 +9,13 @@ def fabricate!(license) QA::Page::Main::Menu.perform(&:go_to_admin_area) QA::Page::Admin::Menu.perform(&:click_subscription_menu_link) - EE::Page::Admin::License.perform do |license_page| - if license_page.license? + EE::Page::Admin::Settings::Component::AddLicense.perform do |admin_settings| + if EE::Page::Admin::Subscription.perform(&:license?) QA::Runtime::Logger.debug("A license already exists.") else QA::Page::Admin::Menu.perform(&:go_to_general_settings) - license_page.add_new_license(license) + admin_settings.add_new_license(license) license_length = license.to_s.strip.length license_info = "TEST_LICENSE_MODE: #{ENV['TEST_LICENSE_MODE']}. License key length: #{license_length}. " + (license_length > 5 ? "Last five characters: #{license.to_s.strip[-5..]}" : "") diff --git a/spec/views/admin/application_settings/general.html.haml_spec.rb b/spec/views/admin/application_settings/general.html.haml_spec.rb index 7d28175d13445f16bb581018e7b40877925282e9..503e41eabc906cd3c2987dc4584701e87adc56d0 100644 --- a/spec/views/admin/application_settings/general.html.haml_spec.rb +++ b/spec/views/admin/application_settings/general.html.haml_spec.rb @@ -6,13 +6,16 @@ let(:app_settings) { build(:application_setting) } let(:user) { create(:admin) } + before do + assign(:application_setting, app_settings) + allow(view).to receive(:current_user).and_return(user) + end + describe 'sourcegraph integration' do let(:sourcegraph_flag) { true } before do - assign(:application_setting, app_settings) allow(Gitlab::Sourcegraph).to receive(:feature_available?).and_return(sourcegraph_flag) - allow(view).to receive(:current_user).and_return(user) end context 'when sourcegraph feature is enabled' do @@ -35,11 +38,6 @@ end describe 'prompt user about registration features' do - before do - assign(:application_setting, app_settings) - allow(view).to receive(:current_user).and_return(user) - end - context 'when service ping is enabled' do before do stub_application_setting(usage_ping_enabled: true) @@ -60,4 +58,14 @@ it_behaves_like 'renders registration features prompt', :application_setting_disabled_repository_size_limit end end + + describe 'add license' do + before do + render + end + + it 'does not show the Add License section' do + expect(rendered).not_to have_css('#js-add-license-toggle') + end + end end