2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
module WithPerformanceBar
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
included do
|
|
|
|
before_action :set_peek_enabled_for_current_request
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def set_peek_enabled_for_current_request
|
2018-12-05 23:21:45 +05:30
|
|
|
Gitlab::SafeRequestStore.fetch(:peek_enabled) { cookie_or_default_value }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
# Needed for Peek's routing to work;
|
|
|
|
# Peek::ResultsController#restrict_non_access calls this method.
|
|
|
|
def peek_enabled?
|
|
|
|
Gitlab::PerformanceBar.enabled_for_request?
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def cookie_or_default_value
|
2019-12-04 20:38:33 +05:30
|
|
|
return false unless Gitlab::PerformanceBar.enabled_for_user?(current_user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if cookies[:perf_bar_enabled].present?
|
|
|
|
cookies[:perf_bar_enabled] == 'true'
|
|
|
|
else
|
|
|
|
cookies[:perf_bar_enabled] = 'true' if Rails.env.development?
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|