Commit 19b8d8af authored by Rémy Coutable's avatar Rémy Coutable

Hide 'peek' by using 'performance bar' instead

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent c8ce1f0d
...@@ -3,6 +3,8 @@ module WithPerformanceBar ...@@ -3,6 +3,8 @@ 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?
......
...@@ -23,7 +23,7 @@ module NavHelper ...@@ -23,7 +23,7 @@ module NavHelper
def nav_header_class def nav_header_class
class_name = '' class_name = ''
class_name << " with-horizontal-nav" if defined?(nav) && nav class_name << " with-horizontal-nav" if defined?(nav) && nav
class_name << " with-peek" if peek_enabled? class_name << " with-peek" if performance_bar_enabled?
class_name class_name
end end
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
= stylesheet_link_tag "application", media: "all" = stylesheet_link_tag "application", media: "all"
= stylesheet_link_tag "print", media: "print" = stylesheet_link_tag "print", media: "print"
= stylesheet_link_tag "test", media: "all" if Rails.env.test? = stylesheet_link_tag "test", media: "all" if Rails.env.test?
= stylesheet_link_tag 'peek' if peek_enabled? = stylesheet_link_tag 'peek' if performance_bar_enabled?
- if show_new_nav? - if show_new_nav?
= stylesheet_link_tag "new_nav", media: "all" = stylesheet_link_tag "new_nav", media: "all"
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
= webpack_bundle_tag "main" = webpack_bundle_tag "main"
= webpack_bundle_tag "raven" if current_application_settings.clientside_sentry_enabled = webpack_bundle_tag "raven" if current_application_settings.clientside_sentry_enabled
= webpack_bundle_tag "test" if Rails.env.test? = webpack_bundle_tag "test" if Rails.env.test?
= webpack_bundle_tag 'peek' if peek_enabled? = webpack_bundle_tag 'peek' if performance_bar_enabled?
- if content_for?(:page_specific_javascripts) - if content_for?(:page_specific_javascripts)
= yield :page_specific_javascripts = yield :page_specific_javascripts
......
...@@ -3,4 +3,6 @@ require 'flipper/middleware/memoizer' ...@@ -3,4 +3,6 @@ require 'flipper/middleware/memoizer'
unless Rails.env.test? unless Rails.env.test?
Rails.application.config.middleware.use Flipper::Middleware::Memoizer, Rails.application.config.middleware.use Flipper::Middleware::Memoizer,
lambda { Feature.flipper } lambda { Feature.flipper }
Feature.register_feature_groups
end end
...@@ -54,15 +54,13 @@ class Feature ...@@ -54,15 +54,13 @@ class Feature
adapter = Flipper::Adapters::ActiveRecord.new( adapter = Flipper::Adapters::ActiveRecord.new(
feature_class: FlipperFeature, gate_class: FlipperGate) feature_class: FlipperFeature, gate_class: FlipperGate)
Flipper.new(adapter).tap do Flipper.new(adapter)
register_feature_groups
end
end end
end end
def register_feature_groups def register_feature_groups
Flipper.register(:performance_team) do |actor| Flipper.register(:performance_team) do |actor|
Gitlab::PerformanceBar.allowed_actor?(actor) actor.thing&.is_a?(User) && Gitlab::PerformanceBar.allowed_user?(actor.thing)
end end
end end
end end
......
...@@ -4,15 +4,15 @@ module Gitlab ...@@ -4,15 +4,15 @@ module Gitlab
Feature.enabled?(:gitlab_performance_bar, current_user) Feature.enabled?(:gitlab_performance_bar, current_user)
end end
def self.allowed_actor?(actor) def self.allowed_user?(user)
return false unless actor.thing&.is_a?(User) && allowed_group return false unless allowed_group
if RequestStore.active? if RequestStore.active?
RequestStore.fetch('performance_bar:user_member_of_allowed_group') do RequestStore.fetch('performance_bar:user_member_of_allowed_group') do
user_member_of_allowed_group?(actor.thing) user_member_of_allowed_group?(user)
end end
else else
user_member_of_allowed_group?(actor.thing) user_member_of_allowed_group?(user)
end end
end end
...@@ -29,10 +29,7 @@ module Gitlab ...@@ -29,10 +29,7 @@ module Gitlab
end end
def self.user_member_of_allowed_group?(user) def self.user_member_of_allowed_group?(user)
GroupMembersFinder.new(allowed_group) GroupMembersFinder.new(allowed_group).execute.exists?(user_id: user.id)
.execute
.where(user_id: user.id)
.any?
end end
end end
end end
...@@ -25,15 +25,8 @@ describe Gitlab::PerformanceBar do ...@@ -25,15 +25,8 @@ describe Gitlab::PerformanceBar do
end end
end end
describe '.allowed_actor?' do describe '.allowed_user?' do
it 'returns false when given actor is not a User' do let(:user) { create(:user) }
actor = double('actor', thing: double)
expect(described_class.allowed_actor?(actor)).to be_falsy
end
context 'when given actor is a User' do
let(:actor) { double('actor', thing: create(:user)) }
before do before do
stub_performance_bar_setting(allowed_group: 'my-group') stub_performance_bar_setting(allowed_group: 'my-group')
...@@ -41,7 +34,7 @@ describe Gitlab::PerformanceBar do ...@@ -41,7 +34,7 @@ describe Gitlab::PerformanceBar do
context 'when allowed group does not exist' do context 'when allowed group does not exist' do
it 'returns false' do it 'returns false' do
expect(described_class.allowed_actor?(actor)).to be_falsy expect(described_class.allowed_user?(user)).to be_falsy
end end
end end
...@@ -50,18 +43,17 @@ describe Gitlab::PerformanceBar do ...@@ -50,18 +43,17 @@ describe Gitlab::PerformanceBar do
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 false' do
expect(described_class.allowed_actor?(actor)).to be_falsy expect(described_class.allowed_user?(user)).to be_falsy
end end
end end
context 'when user is a member of the allowed group' do context 'when user is a member of the allowed group' do
before do before do
my_group.add_developer(actor.thing) my_group.add_developer(user)
end end
it 'returns true' do it 'returns true' do
expect(described_class.allowed_actor?(actor)).to be_truthy expect(described_class.allowed_user?(user)).to be_truthy
end
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