2017-09-10 17:25:29 +05:30
|
|
|
module Gitlab
|
|
|
|
module PerformanceBar
|
|
|
|
ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids:v2'.freeze
|
|
|
|
EXPIRY_TIME = 5.minutes
|
|
|
|
|
|
|
|
def self.enabled?(user = nil)
|
2018-03-17 18:26:18 +05:30
|
|
|
return true if Rails.env.development?
|
2018-05-09 12:01:36 +05:30
|
|
|
return true if user&.admin?
|
2017-09-10 17:25:29 +05:30
|
|
|
return false unless user && allowed_group_id
|
|
|
|
|
|
|
|
allowed_user_ids.include?(user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.allowed_group_id
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::CurrentSettings.performance_bar_allowed_group_id
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.allowed_user_ids
|
|
|
|
Rails.cache.fetch(ALLOWED_USER_IDS_KEY, expires_in: EXPIRY_TIME) do
|
|
|
|
group = Group.find_by_id(allowed_group_id)
|
|
|
|
|
|
|
|
if group
|
|
|
|
GroupMembersFinder.new(group).execute.pluck(:user_id)
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.expire_allowed_user_ids_cache
|
|
|
|
Rails.cache.delete(ALLOWED_USER_IDS_KEY)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|