Commit 43298757 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '349810_modify_upload_license_error_language' into 'master'

Modify upload license error language

See merge request gitlab-org/gitlab!80382
parents 2aec9150 d6897441
......@@ -20,7 +20,7 @@ class Admin::LicensesController < Admin::ApplicationController
@license = License.new(license_params)
return upload_license_error if @license.online_cloud_license?
return upload_license_error(cloud_license: true) if @license.online_cloud_license?
respond_with(@license, location: admin_subscription_path) do
if @license.save
......@@ -67,8 +67,20 @@ class Admin::LicensesController < Admin::ApplicationController
license_params
end
def upload_license_error
flash[:alert] = _('Please enter or upload a valid license.')
def upload_license_error(cloud_license: false)
flash[:alert] = if cloud_license
html_escape(
_(
"It looks like you're attempting to activate your subscription. Use " \
"%{a_start}the Subscription page%{a_end} instead."
)
) % { a_start: "<a href=\"#{admin_subscription_path}\">".html_safe, a_end: '</a>'.html_safe }
else
html_escape(
_('The license you uploaded is invalid. If the issue persists, contact support at %{link}.')
) % { link: '<a href="https://support.gitlab.com">https://support.gitlab.com</a>'.html_safe }
end
@license = License.new
redirect_to new_admin_license_path
end
......
......@@ -680,7 +680,13 @@ class License < ApplicationRecord
def valid_license
return if license?
self.errors.add(:base, _('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.'))
error_message = if online_cloud_license?
_('The license key is invalid.')
else
_('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.')
end
self.errors.add(:base, error_message)
end
# This method, `previous_started_at` and `previous_expired_at` are
......
......@@ -18,7 +18,10 @@ RSpec.describe Admin::LicensesController do
end.not_to change(License, :count)
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(
'The license you uploaded is invalid. If the issue persists, contact support at ' \
'<a href="https://support.gitlab.com">https://support.gitlab.com</a>'
)
end
context 'when the license is for a cloud license' do
......@@ -43,7 +46,11 @@ RSpec.describe Admin::LicensesController do
end.not_to change(License, :count)
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(
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
}
)
end
end
end
......
......@@ -11,7 +11,32 @@ RSpec.describe License do
describe 'validations' do
describe '#valid_license' do
subject(:license) { build(:license, data: gl_license.class.encryptor.encrypt(gl_license.to_json)) }
context 'when the license is provided' do
shared_examples 'an invalid license' do
it 'adds an error' do
expect(license).not_to be_valid
expect(license.errors.full_messages.to_sentence).to include error_message
end
end
context 'with online cloud license' do
let(:gl_license) { build(:gitlab_license, :cloud, starts_at: 'not-a-date') }
let(:error_message) { 'The license key is invalid.' }
it_behaves_like 'an invalid license'
end
context 'with offline cloud license' do
let(:gl_license) { build(:gitlab_license, :cloud, :offline_enabled, starts_at: 'not-a-date') }
let(:error_message) do
'The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.'
end
it_behaves_like 'an invalid license'
end
it { is_expected.to be_valid }
end
......@@ -20,7 +45,11 @@ RSpec.describe License do
license.data = nil
end
it { is_expected.not_to be_valid }
it 'adds an error' do
expect(license).not_to be_valid
expect(license.errors.full_messages.to_sentence)
.to include 'The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.'
end
end
end
......
......@@ -20374,6 +20374,9 @@ msgstr ""
msgid "It looks like you have some draft commits in this branch."
msgstr ""
msgid "It looks like you're attempting to activate your subscription. Use %{a_start}the Subscription page%{a_end} instead."
msgstr ""
msgid "It may be several days before you see feature usage data."
msgstr ""
......@@ -27144,9 +27147,6 @@ msgstr ""
msgid "Please enter a valid time interval"
msgstr ""
msgid "Please enter or upload a valid license."
msgstr ""
msgid "Please enter your current password."
msgstr ""
......@@ -36348,6 +36348,9 @@ msgstr ""
msgid "The latest pipeline for this merge request has failed."
msgstr ""
msgid "The license key is invalid."
msgstr ""
msgid "The license key is invalid. Make sure it is exactly as you received it from GitLab Inc."
msgstr ""
......@@ -36363,6 +36366,9 @@ msgstr ""
msgid "The license was successfully uploaded and will be active from %{starts_at}. You can see the details below."
msgstr ""
msgid "The license you uploaded is invalid. If the issue persists, contact support at %{link}."
msgstr ""
msgid "The list creation wizard is already open"
msgstr ""
......
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