Commit 482eebb9 authored by Ruben Davila's avatar Ruben Davila

Refactor license_message helper.

Also updated other places where we don't need to show anything if the
license is trial
parent e16975a5
......@@ -12,31 +12,10 @@ module LicenseHelper
HistoricalData.max_historical_user_count
end
def license_message(signed_in: signed_in?, is_admin: (current_user && current_user.admin?))
def license_message(signed_in: signed_in?, is_admin: (current_user&.admin?))
yes_license_message(signed_in, is_admin) if current_license
end
def trial_license_message
return unless signed_in? && current_license&.trial?
return if current_license.remaining_days > 7
buy_now_link = link_to('Buy now!', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank')
message =
if current_license.expired?
if current_user.admin?
"Your GitLab Enterprise Edition trial license expired. #{buy_now_link}".html_safe
else
"Your GitLab Enterprise Edition trial license expired. Please contact your administrator."
end
elsif current_user.admin?
remaining_days = (current_license.expires_at - Date.today).to_i
"Your GitLab Enterprise Edition trial license will expire in #{pluralize(remaining_days, 'day')}. #{buy_now_link}".html_safe
end
message
end
private
def current_license
......@@ -46,15 +25,19 @@ module LicenseHelper
end
def yes_license_message(signed_in, is_admin)
return if current_license.trial?
return unless signed_in
return unless (is_admin && current_license.notify_admins?) || current_license.notify_users?
message = []
is_trial = current_license.trial?
message = ["Your Enterprise Edition #{'trial ' if is_trial}license"]
if current_license.expired?
message << "expired on #{current_license.expires_at}."
else
message << "will expire in #{pluralize(current_license.remaining_days, 'day')}."
end
message << 'The GitLab Enterprise Edition license'
message << (current_license.expired? ? 'expired' : 'will expire')
message << "on #{current_license.expires_at}."
message << link_to('Buy now!', "#{Gitlab::SUBSCRIPTIONS_URL}/plans", target: '_blank') if is_trial
if current_license.expired? && current_license.will_block_changes?
message << 'Pushing code and creation of issues and merge requests'
......@@ -78,7 +61,7 @@ module LicenseHelper
message << 'service.'
end
message.join(' ')
message.join(' ').html_safe
end
extend self
......
......@@ -266,7 +266,7 @@ class License < ActiveRecord::Base
end
def remaining_days
return if expired?
return 0 if expired?
(expires_at - Date.today).to_i
end
......
- if license_message.present?
- if license_message.present? && !current_license.trial?
.broadcast-message
= icon('bullhorn')
= license_message
......
......@@ -2,8 +2,8 @@
.navbar-border
%a.sr-only.gl-accessibility{ href: "#content-body", tabindex: "1" } Skip to content
.container-fluid
- if trial_license_message.present?
%p.text-center= trial_license_message
- if current_license&.trial? && license_message.present?
%p.text-center= license_message
.header-content
.dropdown.global-dropdown
%button.global-dropdown-toggle{ type: 'button', 'data-toggle' => 'dropdown' }
......
......@@ -9,7 +9,7 @@ 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 message.present?
if ::License.block_changes? && message.present?
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