Commit bc9dd91f authored by Stan Hu's avatar Stan Hu

Merge branch 'cleanup-license-initializer' into 'master'

Remove license check warning message on boot

See merge request gitlab-org/gitlab!25827
parents 5cb5db19 c518549f
# frozen_string_literal: true
Gitlab.ee do
begin
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
# Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false)
if ::License.block_changes? && message.present?
warn "WARNING: #{message}"
end
end
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
......@@ -18,7 +18,7 @@ module LicenseHelper
License.current&.maximum_user_count || 0
end
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?, in_html: true)
def license_message(signed_in: signed_in?, is_admin: current_user&.admin?)
return unless current_license
return unless signed_in
return unless (is_admin && current_license.notify_admins?) || current_license.notify_users?
......@@ -35,20 +35,18 @@ module LicenseHelper
message << block_changes_message
message <<
if is_admin
'Upload a new license in the admin area'
else
'Ask an admin to upload a new license'
end
message << if is_admin
'Upload a new license in the admin area'
else
'Ask an admin to upload a new license'
end
message << 'to'
message << (current_license.block_changes? ? 'restore' : 'ensure uninterrupted')
message << 'service.'
end
message << renewal_instructions_message(in_html: in_html) unless is_trial
message << renewal_instructions_message unless is_trial
message.join(' ').html_safe
end
......@@ -144,15 +142,12 @@ module LicenseHelper
User.active.count
end
def renewal_instructions_message(in_html: true)
def renewal_instructions_message
renewal_faq_url = 'https://about.gitlab.com/pricing/licensing-faq/#self-managed-gitlab'
renewal_faq_link_start = in_html ? "<a href='#{renewal_faq_url}' target='_blank'>".html_safe : ''
link_end = in_html ? '</a>'.html_safe : ''
message = _('For renewal instructions %{link_start}view our Licensing FAQ.%{link_end}') % { link_start: renewal_faq_link_start, link_end: link_end }
message += ' ' + renewal_faq_url unless in_html
renewal_faq_link_start = "<a href='#{renewal_faq_url}' target='_blank'>".html_safe
link_end = '</a>'.html_safe
message
_('For renewal instructions %{link_start}view our Licensing FAQ.%{link_end}') % { link_start: renewal_faq_link_start, link_end: link_end }
end
end
......@@ -10,7 +10,10 @@ describe LicenseHelper do
describe '#license_message' do
context 'license installed' do
subject { license_message(signed_in: true, is_admin: false) }
let(:license) { double('License') }
let(:faq_link_regex) { /For renewal instructions <a href.*>view our Licensing FAQ\.<\/a>/ }
before do
allow(License).to receive(:current).and_return(license)
......@@ -19,32 +22,16 @@ describe LicenseHelper do
allow(license).to receive(:remaining_days).and_return(4)
end
context 'in HTML' do
let(:faq_link_regex) { /For renewal instructions <a href.*>view our Licensing FAQ\.<\/a>/ }
subject { license_message(signed_in: true, is_admin: false) }
it 'does NOT have a license faq link if license is a trial' do
allow(license).to receive(:trial?).and_return(true)
expect(subject).not_to match(faq_link_regex)
end
it 'does NOT have a license faq link if license is a trial' do
allow(license).to receive(:trial?).and_return(true)
it 'has license faq link if license is not a trial' do
allow(license).to receive(:trial?).and_return(false)
expect(subject).to match(faq_link_regex)
end
expect(subject).not_to match(faq_link_regex)
end
context 'not in HTML' do
subject { license_message(signed_in: true, is_admin: false, in_html: false) }
it 'has license faq link if license is not a trial' do
allow(license).to receive(:trial?).and_return(false)
it 'has license faq link if license is not a trial' do
allow(license).to receive(:trial?).and_return(false)
expect(subject).to match(/For renewal instructions view our Licensing FAQ. https:.*/)
end
expect(subject).to match(faq_link_regex)
end
end
......
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