diff options
author | Rémy Coutable <remy@rymai.me> | 2017-06-21 16:59:13 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-07-06 11:18:25 +0200 |
commit | 186048a404b2f5b84f4472a7d05cbb2309b1e9bf (patch) | |
tree | 8e850caf2a8315b799ee36cfd6be34f230d85b4d /lib | |
parent | afd5c34d9f1bf5ad7d85209dfecbaf28c6c12496 (diff) | |
download | gitlab-ce-186048a404b2f5b84f4472a7d05cbb2309b1e9bf.tar.gz |
Allow to enable the performance bar per user or Flipper group
A `performance_team` Flipper group has been created. By default this
group is nil but this can be customized in `gitlab.yml` via the
performance_bar.allowed_group setting.
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/feature.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/performance_bar.rb | 20 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/feature.rb b/lib/feature.rb index 363f66ba60e..853a00c75a4 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -54,7 +54,15 @@ class Feature adapter = Flipper::Adapters::ActiveRecord.new( feature_class: FlipperFeature, gate_class: FlipperGate) - Flipper.new(adapter) + Flipper.new(adapter).tap do + register_feature_groups + end + end + end + + def register_feature_groups + Flipper.register(:performance_team) do |actor| + Gitlab::PerformanceBar.allowed_actor?(actor) end end end diff --git a/lib/gitlab/performance_bar.rb b/lib/gitlab/performance_bar.rb index 163a40ad306..2ca2cbeac08 100644 --- a/lib/gitlab/performance_bar.rb +++ b/lib/gitlab/performance_bar.rb @@ -1,7 +1,23 @@ module Gitlab module PerformanceBar - def self.enabled? - Feature.enabled?('gitlab_performance_bar') + def self.enabled?(current_user = nil) + Feature.enabled?(:gitlab_performance_bar, current_user) + end + + def self.allowed_actor?(actor) + group = allowed_group + return false unless actor&.is_a?(User) && group + + GroupMembersFinder.new(group) + .execute + .where(user_id: actor.id) + .any? + end + + def self.allowed_group + return nil unless Gitlab.config.performance_bar.allowed_group + + Group.by_path(Gitlab.config.performance_bar.allowed_group) end end end |