debian-mirror-gitlab/app/controllers/concerns/with_performance_bar.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
780 B
Ruby
Raw Normal View History

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
2021-09-04 01:27:46 +05:30
if cookies[:perf_bar_enabled].blank? && Rails.env.development?
cookies[:perf_bar_enabled] = 'true'
end
2019-12-04 20:38:33 +05:30
2021-09-04 01:27:46 +05:30
cookie_enabled = cookies[:perf_bar_enabled] == 'true'
2021-06-08 01:23:25 +05:30
cookie_enabled && Gitlab::PerformanceBar.allowed_for_user?(current_user)
2017-09-10 17:25:29 +05:30
end
end