debian-mirror-gitlab/app/controllers/concerns/with_performance_bar.rb
2021-06-08 01:23:25 +05:30

31 lines
861 B
Ruby

# 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
cookie_enabled = if cookies[:perf_bar_enabled].present?
cookies[:perf_bar_enabled] == 'true'
else
cookies[:perf_bar_enabled] = 'true' if Rails.env.development?
end
cookie_enabled && Gitlab::PerformanceBar.allowed_for_user?(current_user)
end
end