Commit cdc1179f authored by Rémy Coutable's avatar Rémy Coutable

Improve feature flag check for the performance bar

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 19b8d8af
...@@ -3,8 +3,6 @@ module WithPerformanceBar ...@@ -3,8 +3,6 @@ module WithPerformanceBar
included do included do
include Peek::Rblineprof::CustomControllerHelpers include Peek::Rblineprof::CustomControllerHelpers
alias_method :performance_bar_enabled?, :peek_enabled?
helper_method :performance_bar_enabled?
end end
def peek_enabled? def peek_enabled?
......
module PerformanceBarHelper
# This is a hack since using `alias_method :performance_bar_enabled?, :peek_enabled?`
# in WithPerformanceBar breaks tests (but works in the browser).
def performance_bar_enabled?
peek_enabled?
end
end
...@@ -462,7 +462,7 @@ production: &base ...@@ -462,7 +462,7 @@ production: &base
# Performance bar settings # Performance bar settings
performance_bar: performance_bar:
# This setting controls what group can see the performance bar. # This setting controls what group can see the performance bar.
# allowed_group: performance-group # allowed_group: my-org/performance-group
# #
# 4. Advanced settings # 4. Advanced settings
......
...@@ -60,7 +60,9 @@ class Feature ...@@ -60,7 +60,9 @@ class Feature
def register_feature_groups def register_feature_groups
Flipper.register(:performance_team) do |actor| Flipper.register(:performance_team) do |actor|
actor.thing&.is_a?(User) && Gitlab::PerformanceBar.allowed_user?(actor.thing) user = actor.thing
user&.is_a?(User) && Gitlab::PerformanceBar.allowed_user?(user)
end end
end end
end end
......
...@@ -21,10 +21,10 @@ module Gitlab ...@@ -21,10 +21,10 @@ module Gitlab
if RequestStore.active? if RequestStore.active?
RequestStore.fetch('performance_bar:allowed_group') do RequestStore.fetch('performance_bar:allowed_group') do
Group.by_path(Gitlab.config.performance_bar.allowed_group) Group.find_by_full_path(Gitlab.config.performance_bar.allowed_group)
end end
else else
Group.by_path(Gitlab.config.performance_bar.allowed_group) Group.find_by_full_path(Gitlab.config.performance_bar.allowed_group)
end end
end end
......
...@@ -74,10 +74,33 @@ describe Gitlab::PerformanceBar do ...@@ -74,10 +74,33 @@ describe Gitlab::PerformanceBar do
let!(:my_group) { create(:group, path: 'my-group') } let!(:my_group) { create(:group, path: 'my-group') }
context 'when user is not a member of the allowed group' do context 'when user is not a member of the allowed group' do
it 'returns false' do it 'returns the group' do
expect(described_class.allowed_group).to eq(my_group) expect(described_class.allowed_group).to eq(my_group)
end end
end end
end end
context 'when allowed group is nested', :nested_groups do
let!(:nested_my_group) { create(:group, parent: create(:group, path: 'my-org'), path: 'my-group') }
before do
create(:group, path: 'my-group')
stub_performance_bar_setting(allowed_group: 'my-org/my-group')
end
it 'returns the nested group' do
expect(described_class.allowed_group).to eq(nested_my_group)
end
end
context 'when a nested group has the same path', :nested_groups do
before do
create(:group, :nested, path: 'my-group')
end
it 'returns false' do
expect(described_class.allowed_group).to be_falsy
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment