license_helper.rb 2.94 KB
Newer Older
1
module LicenseHelper
2 3 4 5 6
  include ActionView::Helpers::AssetTagHelper
  include ActionView::Helpers::UrlHelper

  delegate :new_admin_license_path, to: 'Gitlab::Routing.url_helpers'

7 8 9 10
  def current_active_user_count
    User.active.count
  end

11
  def max_historical_user_count
Stan Hu's avatar
Stan Hu committed
12
    HistoricalData.max_historical_user_count
13 14
  end

15 16
  def license_message(signed_in: signed_in?, is_admin: current_user&.admin?)
    return unless current_license
17 18
    return unless signed_in
    return unless (is_admin && current_license.notify_admins?) || current_license.notify_users?
19

20
    is_trial = current_license.trial?
21
    message = ["Your #{'trial ' if is_trial}license"]
22

23
    message << expiration_message
Douwe Maan's avatar
Douwe Maan committed
24

25
    message << link_to('Buy now!', ::EE::SUBSCRIPTIONS_PLANS_URL, target: '_blank') if is_trial
26

27
    if current_license.expired? && current_license.will_block_changes?
28
      message << 'Pushing code and creation of issues and merge requests'
Douwe Maan's avatar
Douwe Maan committed
29

30
      message << block_changes_message
31

32
      message <<
33

34
        if is_admin
35
          'Upload a new license in the admin area'
36
        else
37
          'Ask an admin to upload a new license'
38
        end
39

40
      message << 'to'
41
      message << (current_license.block_changes? ? 'restore' : 'ensure uninterrupted')
42
      message << 'service.'
43
    end
44

45
    message.join(' ').html_safe
46 47
  end

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  def expiration_message
    if current_license.expired?
      "expired on #{current_license.expires_at}."
    else
      "will expire in #{pluralize(current_license.remaining_days, 'day')}."
    end
  end

  def block_changes_message
    if current_license.block_changes?
      'has been disabled.'
    else
      "will be disabled on #{current_license.block_changes_at}."
    end
  end

64 65 66 67 68 69 70 71
  def seats_calculation_message
    if current_license&.exclude_guests_from_active_count?
      content_tag :p do
        "Users with a Guest role or those who don't belong to a Project or Group will not use a seat from your license."
      end
    end
  end

72 73 74 75 76 77
  def current_license
    return @current_license if defined?(@current_license)

    @current_license = License.current
  end

78
  def new_trial_url
Rémy Coutable's avatar
Rémy Coutable committed
79
    return_to_url = CGI.escape(Gitlab.config.gitlab.url)
80
    uri = URI.parse(::EE::SUBSCRIPTIONS_URL)
81
    uri.path = '/trials/new'
82
    uri.query = "return_to=#{return_to_url}"
83 84 85
    uri.to_s
  end

86
  def upgrade_plan_url
Tim Zallmann's avatar
Tim Zallmann committed
87 88 89
    group = @project&.group || @group
    if group
      group_billings_path(group)
Tim Zallmann's avatar
Tim Zallmann committed
90
    else
Tim Zallmann's avatar
Tim Zallmann committed
91
      profile_billings_path
Tim Zallmann's avatar
Tim Zallmann committed
92
    end
93 94
  end

Tim Zallmann's avatar
Tim Zallmann committed
95
  def show_promotions?(selected_user = current_user)
96
    return false unless selected_user
97

Lin Jen-Shin's avatar
Lin Jen-Shin committed
98 99
    if Gitlab::CurrentSettings.current_application_settings
      .should_check_namespace_plan?
100 101 102 103 104
      true
    else
      license = License.current
      license.nil? || license.expired?
    end
105 106
  end

107
  def show_advanced_search_promotion?
108
    !Gitlab::CurrentSettings.should_check_namespace_plan? && show_promotions? && show_callout?('promote_advanced_search_dismissed') && !License.feature_available?(:elastic_search)
109 110
  end

111 112
  extend self
end