Commit 8177803e authored by Sean McGivern's avatar Sean McGivern

Fix license initializer

This would fail after an AR connection was established by
8_metrics.rb (to load the application settings), because it would try to
render a route. For now, just ignore the problem by not creating a link
- the link is less useful in console output anyway.
parent 5eabc1da
...@@ -12,29 +12,43 @@ module LicenseHelper ...@@ -12,29 +12,43 @@ module LicenseHelper
HistoricalData.max_historical_user_count HistoricalData.max_historical_user_count
end end
def license_message(signed_in: signed_in?, is_admin: (current_user && current_user.is_admin?)) # in_html is set to false from an initializer, which shouldn't try to render
# HTML links.
#
def license_message(signed_in: signed_in?, is_admin: (current_user && current_user.is_admin?), in_html: true)
@license_message ||= @license_message ||=
if License.current if License.current
yes_license_message(signed_in, is_admin) yes_license_message(signed_in, is_admin)
else else
no_license_message(is_admin) no_license_message(is_admin, in_html: in_html)
end end
end end
private private
def no_license_message(is_admin) def no_license_message(is_admin, in_html: true)
upload_a_license =
if in_html
link_to('Upload a license', new_admin_license_path)
else
'Upload a license'
end
message = [] message = []
message << 'No GitLab Enterprise Edition license has been provided yet.' message << 'No GitLab Enterprise Edition license has been provided yet.'
message << 'Pushing code and creation of issues and merge requests has been disabled.' message << 'Pushing code and creation of issues and merge requests has been disabled.'
message << message <<
if is_admin if is_admin
"#{link_to('Upload a license', new_admin_license_path)} in the admin area to activate this functionality." "#{upload_a_license} in the admin area to activate this functionality."
else else
'Ask an admin to upload a license to activate this functionality.' 'Ask an admin to upload a license to activate this functionality.'
end end
content_tag(:p, message.join(' ').html_safe) if in_html
content_tag(:p, message.join(' ').html_safe)
else
message.join(' ')
end
end end
def yes_license_message(signed_in, is_admin) def yes_license_message(signed_in, is_admin)
......
...@@ -8,7 +8,7 @@ end ...@@ -8,7 +8,7 @@ end
# Needed to run migration # Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses') if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true) message = LicenseHelper.license_message(signed_in: true, is_admin: false, in_html: false)
if message.present? if message.present?
warn "WARNING: #{message}" warn "WARNING: #{message}"
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