summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/with_performance_bar.rb
blob: adfad4de4dd42e55e4ae2fbe88e28b467e171319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module WithPerformanceBar
  extend ActiveSupport::Concern

  included do
    before_action :set_peek_enabled_for_current_request
  end

  private

  def set_peek_enabled_for_current_request
    Gitlab::SafeRequestStore.fetch(:peek_enabled) { cookie_or_default_value }
  end

  # Needed for Peek's routing to work;
  # Peek::ResultsController#restrict_non_access calls this method.
  def peek_enabled?
    Gitlab::PerformanceBar.enabled_for_request?
  end

  def cookie_or_default_value
    if cookies[:perf_bar_enabled].blank? && Rails.env.development?
      cookies[:perf_bar_enabled] = 'true'
    end

    cookie_enabled = cookies[:perf_bar_enabled] == 'true'
    cookie_enabled && Gitlab::PerformanceBar.allowed_for_user?(current_user)
  end
end