diff --git a/doc/user/analytics/analytics_dashboards.md b/doc/user/analytics/analytics_dashboards.md index 9d2c91b6bc87f741429eeec2ea9ee763b367b044..7fcae5019823f13d31d502f8ef201f8cc2320c09 100644 --- a/doc/user/analytics/analytics_dashboards.md +++ b/doc/user/analytics/analytics_dashboards.md @@ -69,6 +69,10 @@ You can use the dashboard designer to: ## View project dashboards +Prerequisite: + +- You must have at least the Developer role for the project. + To view a list of dashboards (both built-in and custom) for a project: 1. On the left sidebar, at the top, select **Search GitLab** (**{search}**) to find your project. diff --git a/ee/app/controllers/projects/analytics/dashboards_controller.rb b/ee/app/controllers/projects/analytics/dashboards_controller.rb index ccf68f1b03d8dde9e089f76272414fdb9f8fc6d6..8792db91af9e3cd9ebd66e096e7c827ec1e74c80 100644 --- a/ee/app/controllers/projects/analytics/dashboards_controller.rb +++ b/ee/app/controllers/projects/analytics/dashboards_controller.rb @@ -8,6 +8,7 @@ class DashboardsController < Projects::ApplicationController feature_category :product_analytics before_action :dashboards_enabled!, only: [:index] + before_action :authorize_read_product_analytics! before_action :authorize_read_combined_project_analytics_dashboards! before_action do push_frontend_feature_flag(:combined_analytics_dashboards_editor, project) diff --git a/ee/lib/ee/sidebars/projects/menus/analytics_menu.rb b/ee/lib/ee/sidebars/projects/menus/analytics_menu.rb index 99979dc2e091b7a1e72db3b05c6d0e6f7d19bc90..b4503eb2c860a56edd802cebf10d9da76654ed24 100644 --- a/ee/lib/ee/sidebars/projects/menus/analytics_menu.rb +++ b/ee/lib/ee/sidebars/projects/menus/analytics_menu.rb @@ -92,7 +92,8 @@ def merge_request_analytics_menu_item def dashboards_analytics_menu_item unless ::Feature.enabled?(:combined_analytics_dashboards, context.project) && 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) return ::Sidebars::NilMenuItem.new(item_id: :dashboards_analytics) end diff --git a/ee/spec/features/projects/analytics/dashboards_spec.rb b/ee/spec/features/projects/analytics/dashboards_spec.rb index 672b81e40c408368109816bf7520cd8b197bcaf8..857a4eeb29b0b3c8c59029f4d61f43d0bdf0399e 100644 --- a/ee/spec/features/projects/analytics/dashboards_spec.rb +++ b/ee/spec/features/projects/analytics/dashboards_spec.rb @@ -15,82 +15,15 @@ subject(:visit_page) { visit project_analytics_dashboards_path(project) } - shared_examples 'renders not found' do - before do - visit_page - end - - it do - expect(page).to have_content(s_('404|Page Not Found')) - end - end - - context 'with the combined dashboards feature flag disabled' do - before do - stub_feature_flags(combined_analytics_dashboards: false) - end - - it_behaves_like 'renders not found' - end - - context 'with the combined dashboards feature flag enabled' do - before do - stub_feature_flags(combined_analytics_dashboards: true) - end - - context 'with the licensed feature disabled' do - before do - stub_licensed_features(combined_project_analytics_dashboards: false) - end - - it_behaves_like 'renders not found' - end - - context 'with the licensed feature enabled' do - before do - stub_licensed_features(combined_project_analytics_dashboards: true) - end - - context 'without access to the project' do - it_behaves_like 'renders not found' - end - - context 'with access to the project' do - before do - project.add_guest(user) - end - - context 'when loading the default page' do - before do - visit_page - end - - it 'renders the dashboards list' do - expect(page).to have_content('Analytics dashboards') - end - - it 'has the dashboards list breadcrumb' do - page.within(find('[data-testid="breadcrumb-links"]')) do - expect(page).to have_link( - s_('Analytics|Analytics dashboards'), - href: "#{project_analytics_dashboards_path(project)}/" - ) - end - end - end - - it_behaves_like 'product analytics dashboards' do - let(:project_settings) { { product_analytics_instrumentation_key: 456 } } - let(:application_settings) do - { - product_analytics_configurator_connection_string: 'https://configurator.example.com', - product_analytics_data_collector_host: 'https://collector.example.com', - cube_api_base_url: 'https://cube.example.com', - cube_api_key: '123' - } - end - end - end + it_behaves_like 'product analytics dashboards' do + let(:project_settings) { { product_analytics_instrumentation_key: 456 } } + let(:application_settings) do + { + product_analytics_configurator_connection_string: 'https://configurator.example.com', + product_analytics_data_collector_host: 'https://collector.example.com', + cube_api_base_url: 'https://cube.example.com', + cube_api_key: '123' + } end end end diff --git a/ee/spec/features/projects/product_analytics/dashboards_shared_examples.rb b/ee/spec/features/projects/product_analytics/dashboards_shared_examples.rb index 9d90afec18507522675fbed2626d72a3900975d6..1bbb0b968b322b0d12046124ec073d85dae8b51c 100644 --- a/ee/spec/features/projects/product_analytics/dashboards_shared_examples.rb +++ b/ee/spec/features/projects/product_analytics/dashboards_shared_examples.rb @@ -117,6 +117,10 @@ end context 'without the correct user permissions' do + before do + project.add_reporter(user) + end + it_behaves_like 'does not render the product analytics list item' end diff --git a/ee/spec/lib/ee/sidebars/projects/menus/analytics_menu_spec.rb b/ee/spec/lib/ee/sidebars/projects/menus/analytics_menu_spec.rb index 1014e86f6cff732bf992eff99013a78de3965c35..8f1c612fdcaf7c0d556bbcba2e5179f8e4dfe08d 100644 --- a/ee/spec/lib/ee/sidebars/projects/menus/analytics_menu_spec.rb +++ b/ee/spec/lib/ee/sidebars/projects/menus/analytics_menu_spec.rb @@ -116,7 +116,7 @@ context 'with different user access levels' do where(:access_level, :has_menu_item) do nil | false - :reporter | true + :reporter | false :developer | true :maintainer | true end diff --git a/ee/spec/requests/projects/analytics/dashboards_controller_spec.rb b/ee/spec/requests/projects/analytics/dashboards_controller_spec.rb index d358a2f2cc4afa455e546f94dffc0e984dca3481..742b861461180a94f8fa32ee35566625b7b55091 100644 --- a/ee/spec/requests/projects/analytics/dashboards_controller_spec.rb +++ b/ee/spec/requests/projects/analytics/dashboards_controller_spec.rb @@ -79,7 +79,7 @@ context 'with the licensed feature' do where(:access_level, :example_to_run) do nil | 'returns not found' - :reporter | 'returns success' + :reporter | 'returns not found' :developer | 'returns success' :maintainer | 'returns success' end