2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-21 10:59:13 -04:00
|
|
|
module WithPerformanceBar
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-08-26 09:57:59 -04:00
|
|
|
included do
|
2019-08-27 07:40:44 -04:00
|
|
|
before_action :set_peek_enabled_for_current_request
|
2019-08-26 09:57:59 -04:00
|
|
|
end
|
|
|
|
|
2019-08-27 07:40:44 -04:00
|
|
|
private
|
2017-06-21 10:59:13 -04:00
|
|
|
|
2019-08-27 07:40:44 -04:00
|
|
|
def set_peek_enabled_for_current_request
|
2018-09-20 15:32:54 -04:00
|
|
|
Gitlab::SafeRequestStore.fetch(:peek_enabled) { cookie_or_default_value }
|
2018-01-16 13:13:31 -05:00
|
|
|
end
|
|
|
|
|
2019-08-27 07:40:44 -04:00
|
|
|
# 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-01-16 13:13:31 -05:00
|
|
|
|
|
|
|
def cookie_or_default_value
|
2021-06-01 02:09:35 -04:00
|
|
|
if cookies[:perf_bar_enabled].blank? && Rails.env.development?
|
|
|
|
cookies[:perf_bar_enabled] = 'true'
|
|
|
|
end
|
2019-08-27 07:40:44 -04:00
|
|
|
|
2021-06-01 02:09:35 -04:00
|
|
|
cookie_enabled = cookies[:perf_bar_enabled] == 'true'
|
2021-04-27 08:10:12 -04:00
|
|
|
cookie_enabled && Gitlab::PerformanceBar.allowed_for_user?(current_user)
|
2017-06-21 10:59:13 -04:00
|
|
|
end
|
|
|
|
end
|