Commit 5211112c authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'sarnold-push-licensed-feature-flags' into 'master'

Add push_licensed_feature to gon helper

See merge request gitlab-org/gitlab!48414
parents 623f2a60 d1dc4340
...@@ -51,7 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -51,7 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController
real_time_feature_flag = :real_time_issue_sidebar real_time_feature_flag = :real_time_issue_sidebar
real_time_enabled = Gitlab::ActionCable::Config.in_app? || Feature.enabled?(real_time_feature_flag, @project) real_time_enabled = Gitlab::ActionCable::Config.in_app? || Feature.enabled?(real_time_feature_flag, @project)
push_to_gon_features(real_time_feature_flag, real_time_enabled) push_to_gon_attributes(:features, real_time_feature_flag, real_time_enabled)
record_experiment_user(:invite_members_version_a) record_experiment_user(:invite_members_version_a)
record_experiment_user(:invite_members_version_b) record_experiment_user(:invite_members_version_b)
......
...@@ -21,6 +21,6 @@ class Groups::UsageQuotasController < Groups::ApplicationController ...@@ -21,6 +21,6 @@ class Groups::UsageQuotasController < Groups::ApplicationController
end end
def push_additional_repo_storage_by_namespace_feature def push_additional_repo_storage_by_namespace_feature
push_to_gon_features(:additional_repo_storage_by_namespace, @group.additional_repo_storage_by_namespace_enabled?) push_to_gon_attributes(:features, :additional_repo_storage_by_namespace, @group.additional_repo_storage_by_namespace_enabled?)
end end
end end
...@@ -13,6 +13,6 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController ...@@ -13,6 +13,6 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController
private private
def push_additional_repo_storage_by_namespace_feature def push_additional_repo_storage_by_namespace_feature
push_to_gon_features(:additional_repo_storage_by_namespace, current_user.namespace.additional_repo_storage_by_namespace_enabled?) push_to_gon_attributes(:features, :additional_repo_storage_by_namespace, current_user.namespace.additional_repo_storage_by_namespace_enabled?)
end end
end end
...@@ -11,6 +11,20 @@ module EE ...@@ -11,6 +11,20 @@ module EE
gon.roadmap_epics_limit = 1000 gon.roadmap_epics_limit = 1000
end end
# Exposes if a licensed feature is available.
#
# name - The name of the licensed feature
# obj - the object to check the licensed feature on (project, namespace)
def push_licensed_feature(name, obj = nil)
enabled = if obj
obj.feature_available?(name)
else
::License.feature_available?(name)
end
push_to_gon_attributes(:licensed_features, name, enabled)
end
end end
end end
end end
...@@ -26,4 +26,47 @@ RSpec.describe EE::Gitlab::GonHelper do ...@@ -26,4 +26,47 @@ RSpec.describe EE::Gitlab::GonHelper do
helper.add_gon_variables helper.add_gon_variables
end end
end end
describe '#push_licensed_feature' do
let_it_be(:feature) { License::EEU_FEATURES.first }
shared_examples 'sets the licensed features flag' do
it 'pushes the licensed feature flag to the frotnend' do
gon = instance_double('gon')
stub_licensed_features(feature => true)
allow(helper)
.to receive(:gon)
.and_return(gon)
expect(gon)
.to receive(:push)
.with({ licensed_features: { feature.to_s.camelize(:lower) => true } }, true)
subject
end
end
context 'no obj given' do
subject { helper.push_licensed_feature(feature) }
before do
expect(License).to receive(:feature_available?).with(feature)
end
it_behaves_like 'sets the licensed features flag'
end
context 'obj given' do
let(:project) { create(:project) }
subject { helper.push_licensed_feature(feature, project) }
before do
expect(project).to receive(:feature_available?).with(feature).and_call_original
end
it_behaves_like 'sets the licensed features flag'
end
end
end end
...@@ -61,15 +61,15 @@ module Gitlab ...@@ -61,15 +61,15 @@ module Gitlab
def push_frontend_feature_flag(name, *args, **kwargs) def push_frontend_feature_flag(name, *args, **kwargs)
enabled = Feature.enabled?(name, *args, **kwargs) enabled = Feature.enabled?(name, *args, **kwargs)
push_to_gon_features(name, enabled) push_to_gon_attributes(:features, name, enabled)
end end
def push_to_gon_features(name, enabled) def push_to_gon_attributes(key, name, enabled)
var_name = name.to_s.camelize(:lower) var_name = name.to_s.camelize(:lower)
# Here the `true` argument signals gon that the value should be merged # Here the `true` argument signals gon that the value should be merged
# into any existing ones, instead of overwriting them. This allows you to # into any existing ones, instead of overwriting them. This allows you to
# use this method to push multiple feature flags. # use this method to push multiple feature flags.
gon.push({ features: { var_name => enabled } }, true) gon.push({ key => { var_name => enabled } }, true)
end end
def default_avatar_url def default_avatar_url
......
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