Commit 4dd78aa2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'improve-insights-feature-check' into 'master'

Improve the Insights feature availability check

See merge request gitlab-org/gitlab-ee!9910
parents 7af50aff 8df03494
...@@ -203,7 +203,7 @@ Get an overview of the vulnerabilities of all the projects in a group and its su ...@@ -203,7 +203,7 @@ Get an overview of the vulnerabilities of all the projects in a group and its su
## Insights **[ULTIMATE]** ## Insights **[ULTIMATE]**
Placeholder. > Introduced in [GitLab Ultimate][ee] 11.9 behind the `insights` feature flag.
## Transfer groups to another group ## Transfer groups to another group
......
...@@ -15,7 +15,7 @@ module EE ...@@ -15,7 +15,7 @@ module EE
:membership_lock, :membership_lock,
:repository_size_limit :repository_size_limit
].tap do |params_ee| ].tap do |params_ee|
params_ee << { insight_attributes: :project_id } if ::Feature.enabled?(:group_insights) && current_group&.feature_available?(:insights) params_ee << { insight_attributes: :project_id } if current_group&.insights_available?
params_ee << :project_creation_level if current_group&.feature_available?(:project_creation_level) params_ee << :project_creation_level if current_group&.feature_available?(:project_creation_level)
params_ee << :file_template_project_id if current_group&.feature_available?(:custom_file_templates_for_namespace) params_ee << :file_template_project_id if current_group&.feature_available?(:custom_file_templates_for_namespace)
params_ee << :custom_project_templates_group_id if License.feature_available?(:custom_project_templates) params_ee << :custom_project_templates_group_id if License.feature_available?(:custom_project_templates)
......
# frozen_string_literal: true
module InsightsFeature
extend ActiveSupport::Concern
# This allows to:
# 1. Disable the :insights by default even if the license allows it
# 1. Enable the Insights feature for an arbitrary group/project
# Once we're ready to release the feature, we could just replace
# `{group,project}.insights_available?` with
# `{group,project}.feature_available?(:insights)` and remove this module.
def insights_available?
::Feature.enabled?(:insights, self) && feature_available?(:insights)
end
end
...@@ -11,6 +11,7 @@ module EE ...@@ -11,6 +11,7 @@ module EE
prepended do prepended do
include TokenAuthenticatable include TokenAuthenticatable
include InsightsFeature
add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) } add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) }
......
...@@ -18,6 +18,7 @@ module EE ...@@ -18,6 +18,7 @@ module EE
include Elastic::ProjectsSearch include Elastic::ProjectsSearch
include EE::DeploymentPlatform # rubocop: disable Cop/InjectEnterpriseEditionModule include EE::DeploymentPlatform # rubocop: disable Cop/InjectEnterpriseEditionModule
include EachBatch include EachBatch
include InsightsFeature
ignore_column :mirror_last_update_at, ignore_column :mirror_last_update_at,
:mirror_last_successful_update_at, :mirror_last_successful_update_at,
......
- return unless Feature.enabled?(:group_insights) && @group.feature_available?(:insights) - return unless @group.insights_available?
%section.settings.gs-advanced.no-animate#js-templates{ class: ('expanded' if expanded) } %section.settings.gs-advanced.no-animate#js-templates{ class: ('expanded' if expanded) }
.settings-header .settings-header
......
...@@ -394,4 +394,10 @@ describe Group do ...@@ -394,4 +394,10 @@ describe Group do
end end
end end
end end
describe '#insights_available?' do
it_behaves_like 'an entity with the Insights feature' do
let(:entity) { group }
end
end
end end
...@@ -1718,6 +1718,12 @@ describe Project do ...@@ -1718,6 +1718,12 @@ describe Project do
end end
end end
describe '#insights_available?' do
it_behaves_like 'an entity with the Insights feature' do
let(:entity) { create(:project) }
end
end
# Despite stubbing the current node as the primary or secondary, the # Despite stubbing the current node as the primary or secondary, the
# behaviour for EE::Project#lfs_http_url_to_repo() is to call # behaviour for EE::Project#lfs_http_url_to_repo() is to call
# Project#lfs_http_url_to_repo() which does not have a Geo context. # Project#lfs_http_url_to_repo() which does not have a Geo context.
......
# This needs an `entity` object: Project or Group.
RSpec.shared_examples 'an entity with the Insights feature' do
before do
# This is needed because all feature flags are enabled by default in tests
allow(Feature).to receive(:enabled?)
.with(:insights, entity)
.and_return(false)
end
context 'when license does not allow it' do
before do
stub_licensed_features(insights: false)
end
it { expect(entity).not_to be_insights_available }
context 'when the feature flag is enabled globally' do
before do
stub_feature_flags(insights: true)
end
it { expect(entity).not_to be_insights_available }
end
context 'when the feature flag is enabled for the entity' do
before do
stub_feature_flags(insights: { enabled: true, thing: entity })
end
it { expect(entity).not_to be_insights_available }
end
end
context 'when license allows it' do
before do
stub_licensed_features(insights: true)
end
it { expect(entity).not_to be_insights_available }
context 'when the feature flag is disabled globally' do
before do
stub_feature_flags(insights: false)
end
it { expect(entity).not_to be_insights_available }
end
context 'when the feature flag is enabled globally' do
before do
stub_feature_flags(insights: true)
end
it { expect(entity).to be_insights_available }
end
context 'when the feature flag is enabled for the entity' do
before do
stub_feature_flags(insights: { enabled: true, thing: entity })
end
it { expect(entity).to be_insights_available }
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