diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index 7b0824ae2af4269f2318ab33ca0334c0b5a00234..4b83239dfbde71bc02aeb37efe4c05d5391dbd41 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -59,7 +59,7 @@ = render_if_exists 'layouts/nav/sidebar/analytics_more_link' %li.dropdown.d-lg-none - = render_if_exists 'dashboard/operations/nav_link_list' + = render_if_exists 'dashboard/nav_link_list' - if can?(current_user, :read_instance_statistics) = nav_link(controller: [:conversational_development_index, :cohorts], html_options: { class: 'd-lg-none' }) do = link_to instance_statistics_root_path do @@ -86,7 +86,7 @@ = _('Web IDE') %li.dropdown{ class: 'd-none d-lg-block' } - = render_if_exists 'dashboard/operations/nav_link' + = render_if_exists 'dashboard/nav_link' - if can?(current_user, :read_instance_statistics) = nav_link(controller: [:conversational_development_index, :cohorts], html_options: { class: "d-none d-lg-block d-xl-block"}) do = link_to instance_statistics_root_path, title: _('Instance Statistics'), aria: { label: _('Instance Statistics') }, data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do diff --git a/ee/app/helpers/ee/dashboard_helper.rb b/ee/app/helpers/ee/dashboard_helper.rb index 0474888585347d8fcfa10c30abce02629aa6b143..3fa2970abe54bcb57b3896d988cb45a595c28059 100644 --- a/ee/app/helpers/ee/dashboard_helper.rb +++ b/ee/app/helpers/ee/dashboard_helper.rb @@ -37,6 +37,15 @@ def has_start_trial? def get_dashboard_nav_links super.tap do |links| links << :analytics if ::Gitlab::Analytics.any_features_enabled? + + if can?(current_user, :read_operations_dashboard) + links << :environments if ::Feature.enabled?(:environments_dashboard) + links << :operations + end + + if ::Feature.enabled?(:security_dashboard) && can?(current_user, :read_security_dashboard) + links << :security + end end end end diff --git a/ee/app/views/dashboard/operations/_nav_link.html.haml b/ee/app/views/dashboard/_nav_link.html.haml similarity index 55% rename from ee/app/views/dashboard/operations/_nav_link.html.haml rename to ee/app/views/dashboard/_nav_link.html.haml index 2e2249a0a0d90d938a0c9ed090f107fb4177447b..f75462b418ee250c7901cc2d27194868422a05c8 100644 --- a/ee/app/views/dashboard/operations/_nav_link.html.haml +++ b/ee/app/views/dashboard/_nav_link.html.haml @@ -1,8 +1,8 @@ -- if can?(current_user, :read_operations_dashboard) - %button#js-dashboards-menu.btn-link{ type: 'button', data: { toggle: 'dropdown' }, 'aria-label': _('Operations Dashboard'), 'aria-haspopup': true, 'aria-expanded': false } +- if any_dashboard_nav_link?([:environments, :operations, :security]) + %button#js-dashboards-menu.btn-link{ type: 'button', data: { toggle: 'dropdown' }, 'aria-label': _('Dashboards'), 'aria-haspopup': true, 'aria-expanded': false } = sprite_icon('dashboard', size: 18) = sprite_icon('angle-down', css_class: 'caret-down') .dropdown-menu{ 'aria-labelledby': "js-dashboards-menu" } .dropdown-bold-header = _('Dashboards') - = render_if_exists 'dashboard/operations/nav_link_list' + = render_if_exists 'dashboard/nav_link_list' diff --git a/ee/app/views/dashboard/_nav_link_list.html.haml b/ee/app/views/dashboard/_nav_link_list.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..f9bf02a9d2470a6fc1381344beab896406acf46b --- /dev/null +++ b/ee/app/views/dashboard/_nav_link_list.html.haml @@ -0,0 +1,9 @@ +- if dashboard_nav_link?(:environments) + = link_to operations_environments_path, class: 'dropdown-item' do + = _('Environments') +- if dashboard_nav_link?(:operations) + = link_to operations_path, class: 'dropdown-item' do + = _('Operations') +- if dashboard_nav_link?(:security) + = link_to security_path, class: 'dropdown-item' do + = _('Security') diff --git a/ee/app/views/dashboard/operations/_nav_link_list.html.haml b/ee/app/views/dashboard/operations/_nav_link_list.html.haml deleted file mode 100644 index 3d9cd252a957e834375212ee32f5d6edf7eebcb2..0000000000000000000000000000000000000000 --- a/ee/app/views/dashboard/operations/_nav_link_list.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -- if Feature.enabled?('environments_dashboard') - = link_to operations_environments_path, class: 'dropdown-item' do - = _('Environments') -= link_to operations_path, class: 'dropdown-item' do - = _('Operations') diff --git a/ee/spec/helpers/ee/dashboard_helper_spec.rb b/ee/spec/helpers/ee/dashboard_helper_spec.rb index 5980454d0dfddd98da5cbe2e8ace731df817b1ef..95b9aff5e7f020739c064444bc02c9cdf35cca4c 100644 --- a/ee/spec/helpers/ee/dashboard_helper_spec.rb +++ b/ee/spec/helpers/ee/dashboard_helper_spec.rb @@ -7,29 +7,69 @@ let(:user) { build(:user) } - before do - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:can?) { true } - end - describe '#dashboard_nav_links' do - context 'when at least one analytics feature is enabled' do + before do + allow(helper).to receive(:current_user).and_return(user) + end + + describe 'analytics' do before do - enable_only_one_analytics_feature_flag + allow(helper).to receive(:can?) { true } end - it 'includes analytics' do - expect(helper.dashboard_nav_links).to include(:analytics) + context 'when at least one analytics feature is enabled' do + before do + enable_only_one_analytics_feature_flag + end + + it 'includes analytics' do + expect(helper.dashboard_nav_links).to include(:analytics) + end + end + + context 'when all analytics features are disabled' do + before do + disable_all_analytics_feature_flags + end + + it 'does not include analytics' do + expect(helper.dashboard_nav_links).not_to include(:analytics) + end end end - context 'when all analytics features are disabled' do - before do - disable_all_analytics_feature_flags + describe 'operations, environments and security' do + using RSpec::Parameterized::TableSyntax + + where(:ability, :feature_flag, :nav_link) do + :read_operations_dashboard | nil | :operations + :read_operations_dashboard | :environments_dashboard | :environments + :read_security_dashboard | :security_dashboard | :security end - it 'does not include analytics' do - expect(helper.dashboard_nav_links).not_to include(:analytics) + with_them do + describe 'when the feature is enabled' do + before do + stub_feature_flags(feature_flag => true) unless feature_flag.nil? + allow(helper).to receive(:can?).and_return(false) + allow(helper).to receive(:can?).with(user, ability).and_return(true) + end + + it 'includes the nav link' do + expect(helper.dashboard_nav_links).to include(nav_link) + end + end + + describe 'when the feature is disabled' do + before do + stub_feature_flags(feature_flag => false) unless feature_flag.nil? + allow(helper).to receive(:can?).and_return(false) + end + + it 'does not include the nav link' do + expect(helper.dashboard_nav_links).not_to include(nav_link) + end + end end end end