Commit 3bf0267a authored by Mark Florian's avatar Mark Florian Committed by Michael Kozono

Add nav link for Instance Security Dashboard

This adds a nav link for the [Instance Security Dashboard MVC][1], which
is behind the `security_dashboard` feature flag.

This also refactors slightly how the visibility of the Operations and
Environments dashboard links is handled. One result of this is that they
are now consistently visible/hidden between the dashboards dropdown on
larger screens, and the "More" dropdown on smaller screens.

Finally, the partials have been renamed, since they're no longer
specific to operations.

[1]: https://gitlab.com/gitlab-org/gitlab/issues/6953
parent 2b0a4131
......@@ -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
......
......@@ -37,6 +37,15 @@ module EE
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
......
- 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'
- 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')
- if Feature.enabled?('environments_dashboard')
= link_to operations_environments_path, class: 'dropdown-item' do
= _('Environments')
= link_to operations_path, class: 'dropdown-item' do
= _('Operations')
......@@ -7,29 +7,69 @@ describe DashboardHelper, type: :helper do
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
......
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