Skip to content
代码片段 群组 项目
未验证 提交 33ef3129 编辑于 作者: Surabhi Suman's avatar Surabhi Suman 提交者: GitLab
浏览文件

Hides analytics option for personal namespace projects

This hides product analytics
Option in seetings menu and Analyze menu for
Personal namespace projects
Changelog: fixed
EE: true
上级 c7c4c9ec
No related branches found
No related tags found
无相关合并请求
显示
160 个添加72 个删除
...@@ -23,7 +23,8 @@ def index; end ...@@ -23,7 +23,8 @@ def index; end
def dashboards_enabled! def dashboards_enabled!
render_404 unless ::Feature.enabled?(:combined_analytics_dashboards, project) && render_404 unless ::Feature.enabled?(:combined_analytics_dashboards, project) &&
project.licensed_feature_available?(:combined_project_analytics_dashboards) project.licensed_feature_available?(:combined_project_analytics_dashboards) &&
!project.personal?
end end
def viewing_single_dashboard? def viewing_single_dashboard?
......
...@@ -48,7 +48,7 @@ def permitted_project_params ...@@ -48,7 +48,7 @@ def permitted_project_params
end end
def authorize_analytics_settings! def authorize_analytics_settings!
access_denied! unless Feature.enabled?(:combined_analytics_dashboards, project) access_denied! unless Feature.enabled?(:combined_analytics_dashboards, project) && !project.personal?
end end
end end
end end
......
...@@ -70,7 +70,8 @@ def product_analytics_enabled? ...@@ -70,7 +70,8 @@ def product_analytics_enabled?
Gitlab::CurrentSettings.product_analytics_enabled? && Gitlab::CurrentSettings.product_analytics_enabled? &&
product_analytics_settings.cube_api_base_url.present? && product_analytics_settings.cube_api_base_url.present? &&
product_analytics_settings.cube_api_key.present? && product_analytics_settings.cube_api_key.present? &&
project.product_analytics_enabled? project.product_analytics_enabled? &&
!project.personal?
end end
def has_access? def has_access?
......
...@@ -93,7 +93,7 @@ def dashboards_analytics_menu_item ...@@ -93,7 +93,7 @@ def dashboards_analytics_menu_item
unless ::Feature.enabled?(:combined_analytics_dashboards, context.project) && unless ::Feature.enabled?(:combined_analytics_dashboards, context.project) &&
context.project.licensed_feature_available?(:combined_project_analytics_dashboards) && context.project.licensed_feature_available?(:combined_project_analytics_dashboards) &&
can?(context.current_user, :read_combined_project_analytics_dashboards, context.project) && can?(context.current_user, :read_combined_project_analytics_dashboards, context.project) &&
can?(context.current_user, :read_product_analytics, context.project) can?(context.current_user, :read_product_analytics, context.project) && !context.project.personal?
return ::Sidebars::NilMenuItem.new(item_id: :dashboards_analytics) return ::Sidebars::NilMenuItem.new(item_id: :dashboards_analytics)
end end
......
...@@ -17,7 +17,7 @@ def configure_menu_items ...@@ -17,7 +17,7 @@ def configure_menu_items
end end
def analytics_menu_item def analytics_menu_item
unless ::Feature.enabled?(:combined_analytics_dashboards, context.project) unless ::Feature.enabled?(:combined_analytics_dashboards, context.project) && !context.project.personal?
return ::Sidebars::NilMenuItem.new(item_id: :analytics) return ::Sidebars::NilMenuItem.new(item_id: :analytics)
end end
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
stub_feature_flags(ml_experiment_tracking: false) stub_feature_flags(ml_experiment_tracking: false)
stub_feature_flags(model_registry: false) stub_feature_flags(model_registry: false)
stub_feature_flags(remove_monitor_metrics: false) stub_feature_flags(remove_monitor_metrics: false)
stub_feature_flags(combined_analytics_dashboards: false)
insert_package_nav insert_package_nav
insert_infrastructure_registry_nav(s_('Terraform|Terraform states')) insert_infrastructure_registry_nav(s_('Terraform|Terraform states'))
insert_infrastructure_google_cloud_nav insert_infrastructure_google_cloud_nav
...@@ -212,18 +213,40 @@ ...@@ -212,18 +213,40 @@
context 'when analytics dashboards is available' do context 'when analytics dashboards is available' do
before do before do
stub_feature_flags(combined_analytics_dashboards: true) stub_feature_flags(combined_analytics_dashboards: true)
stub_licensed_features(combined_project_analytics_dashboards: true) stub_licensed_features({ combined_project_analytics_dashboards: true, iterations: false })
insert_before_sub_nav_item(
_('Value stream analytics'),
within: _('Analyze'),
new_sub_nav_item_name: _('Analytics dashboards')
)
visit project_path(project) visit project_path(project)
end end
it_behaves_like 'verified navigation bar' context 'when project is namespaced to a user' do
it_behaves_like 'verified navigation bar'
end
context 'when project is namespaced to a group' do
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:project) { create(:project, :repository, group: group) }
before_all do
project.add_maintainer(user)
end
before do
insert_before_sub_nav_item(
_('Value stream analytics'),
within: _('Analyze'),
new_sub_nav_item_name: _('Analytics dashboards')
)
insert_after_sub_nav_item(
_('Monitor'),
within: _('Settings'),
new_sub_nav_item_name: _('Analytics')
)
visit project_path(project)
end
it_behaves_like 'verified navigation bar'
end
end end
context 'when model experiments is available' do context 'when model experiments is available' do
......
...@@ -111,47 +111,63 @@ ...@@ -111,47 +111,63 @@
stub_licensed_features(combined_project_analytics_dashboards: true) stub_licensed_features(combined_project_analytics_dashboards: true)
end end
specify { is_expected.not_to be_nil } describe 'for personal namespace projects' do
it 'is nil for personal namespace projects' do
is_expected.to be_nil
end
end
context 'with different user access levels' do describe 'for group namespace projects' do
where(:access_level, :has_menu_item) do let_it_be(:user) { create(:user) }
nil | false let_it_be(:group) { create(:group) }
:reporter | false let_it_be_with_reload(:project) { create(:project, group: group) }
:developer | true
:maintainer | true before_all do
project.add_maintainer(user)
end end
with_them do specify { is_expected.not_to be_nil }
let(:user) { create(:user) }
before do context 'with different user access levels' do
project.add_member(user, access_level) where(:access_level, :has_menu_item) do
nil | false
:reporter | false
:developer | true
:maintainer | true
end end
describe "when the user is not allowed to view the menu item", if: !params[:has_menu_item] do with_them do
specify { is_expected.to be_nil } let(:user) { create(:user) }
end
before do
project.add_member(user, access_level)
end
context "when the user is not allowed to view the menu item", if: !params[:has_menu_item] do
specify { is_expected.to be_nil }
end
describe "when the user is allowed to view the menu item", if: params[:has_menu_item] do context "when the user is allowed to view the menu item", if: params[:has_menu_item] do
specify { is_expected.not_to be_nil } specify { is_expected.not_to be_nil }
end
end end
end end
end
describe 'when the license does not support the feature' do describe 'when the license does not support the feature' do
before do before do
stub_licensed_features(combined_project_analytics_dashboards: false) stub_licensed_features(combined_project_analytics_dashboards: false)
end
specify { is_expected.to be_nil }
end end
specify { is_expected.to be_nil } describe 'when the dashboards analytics feature is disabled' do
end before do
stub_feature_flags(combined_analytics_dashboards: false)
end
describe 'when the dashboards analytics feature is disabled' do specify { is_expected.to be_nil }
before do
stub_feature_flags(combined_analytics_dashboards: false)
end end
specify { is_expected.to be_nil }
end end
end end
end end
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { project.first_owner } let(:user) { project.first_owner }
let(:show_promotions) { true } let(:show_promotions) { true }
let(:show_discover_project_security) { true } let(:show_discover_project_security) { true }
let(:context) do let(:context) do
...@@ -29,12 +30,27 @@ ...@@ -29,12 +30,27 @@
describe 'Analytics' do describe 'Analytics' do
let(:item_id) { :analytics } let(:item_id) { :analytics }
it_behaves_like 'access rights checks' context 'for group projects' do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be_with_reload(:project) { create(:project, group: group) }
before_all do
project.add_maintainer(user)
end
it_behaves_like 'access rights checks'
it 'is nil when combined_analytics_dashboards feature flag is disabled' do it 'is nil when combined_analytics_dashboards feature flag is disabled' do
stub_feature_flags(combined_analytics_dashboards: false) stub_feature_flags(combined_analytics_dashboards: false)
expect(subject).to be_nil
end
end
expect(subject).to be_nil context 'for personal projects' do
it 'is nil for personal namespace projects' do
is_expected.to be_nil
end
end end
end end
......
...@@ -41,50 +41,59 @@ ...@@ -41,50 +41,59 @@
end end
end end
context 'with the feature flag disabled' do describe 'for personal namespace projects' do
before do
stub_feature_flags(combined_analytics_dashboards: false)
end
it_behaves_like 'returns not found' it_behaves_like 'returns not found'
end end
context 'with the feature flag enabled' do describe 'for group namespace projects' do
before do let_it_be(:group) { create(:group) }
stub_feature_flags(combined_analytics_dashboards: true) let_it_be_with_reload(:project) { create(:project, :repository, group: group) }
end
context 'without the licensed feature' do context 'with the feature flag disabled' do
before do before do
stub_licensed_features(combined_project_analytics_dashboards: false) stub_feature_flags(combined_analytics_dashboards: false)
end end
it_behaves_like 'returns not found' it_behaves_like 'returns not found'
end end
context 'with the licensed feature' do context 'with the feature flag enabled' do
where(:access_level, :example_to_run) do before do
nil | 'returns not found' stub_feature_flags(combined_analytics_dashboards: true)
:reporter | 'returns not found'
:developer | 'returns success'
:maintainer | 'returns success'
end end
with_them do context 'without the licensed feature' do
let(:user) { create(:user) }
before do before do
stub_licensed_features(combined_project_analytics_dashboards: true) stub_licensed_features(combined_project_analytics_dashboards: false)
project.add_member(user, access_level)
end end
it_behaves_like params[:example_to_run] it_behaves_like 'returns not found'
end end
it 'does not count views for the dashboard listing' do context 'with the licensed feature' do
expect(Gitlab::UsageDataCounters::ProductAnalyticsCounter).not_to receive(:count) where(:access_level, :example_to_run) do
nil | 'returns not found'
:reporter | 'returns not found'
:developer | 'returns success'
:maintainer | 'returns success'
end
with_them do
let(:user) { create(:user) }
before do
stub_licensed_features(combined_project_analytics_dashboards: true)
project.add_member(user, access_level)
end
it_behaves_like params[:example_to_run]
end
it 'does not count views for the dashboard listing' do
expect(Gitlab::UsageDataCounters::ProductAnalyticsCounter).not_to receive(:count)
get project_analytics_dashboards_path(project) get project_analytics_dashboards_path(project)
end
end end
end end
end end
......
...@@ -191,4 +191,27 @@ ...@@ -191,4 +191,27 @@
end end
end end
end end
describe 'for personal namespace projects' do
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { project.first_owner }
before_all do
project.add_maintainer(user)
end
before do
sign_in(user)
end
subject do
get project_settings_analytics_path(project)
end
it 'returns a 404 on rendering analytics settings' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end end
...@@ -97,7 +97,6 @@ ...@@ -97,7 +97,6 @@
_('CI/CD'), _('CI/CD'),
_('Packages and registries'), _('Packages and registries'),
_('Monitor'), _('Monitor'),
(_('Analytics') if Gitlab.ee?),
s_('UsageQuota|Usage Quotas') s_('UsageQuota|Usage Quotas')
] ]
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册