Rearrange 'Security & Compliance' menu items

In this commit we're rearranging the Audit Events
menu item in the 'Security & Compliance menu', in order
to match the link set in the main menu.

Changelog: changed
EE: true
parent 0c81941b
...@@ -19,22 +19,12 @@ module EE ...@@ -19,22 +19,12 @@ module EE
add_item(license_compliance_menu_item) add_item(license_compliance_menu_item)
add_item(threat_monitoring_menu_item) add_item(threat_monitoring_menu_item)
add_item(scan_policies_menu_item) add_item(scan_policies_menu_item)
add_item(configuration_menu_item)
add_item(audit_events_menu_item) add_item(audit_events_menu_item)
add_item(configuration_menu_item)
true true
end end
override :link
def link
return discover_project_security_menu_item.link if discover_project_security_menu_item.render?
return security_dashboard_menu_item.link if security_dashboard_menu_item.render?
return audit_events_menu_item.link if audit_events_menu_item.render?
return dependencies_menu_item.link if dependencies_menu_item.render?
renderable_items.first&.link
end
private private
override :configuration_menu_item_paths override :configuration_menu_item_paths
...@@ -58,9 +48,8 @@ module EE ...@@ -58,9 +48,8 @@ module EE
end end
def discover_project_security_menu_item def discover_project_security_menu_item
strong_memoize(:discover_project_security_menu_item) do
unless context.show_discover_project_security unless context.show_discover_project_security
next ::Sidebars::NilMenuItem.new(item_id: :discover_project_security) return ::Sidebars::NilMenuItem.new(item_id: :discover_project_security)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -70,12 +59,10 @@ module EE ...@@ -70,12 +59,10 @@ module EE
item_id: :discover_project_security item_id: :discover_project_security
) )
end end
end
def security_dashboard_menu_item def security_dashboard_menu_item
strong_memoize(:security_dashboard_menu_item) do
unless can?(context.current_user, :read_project_security_dashboard, context.project) unless can?(context.current_user, :read_project_security_dashboard, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :dashboard) return ::Sidebars::NilMenuItem.new(item_id: :dashboard)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -85,12 +72,10 @@ module EE ...@@ -85,12 +72,10 @@ module EE
item_id: :dashboard item_id: :dashboard
) )
end end
end
def vulnerability_report_menu_item def vulnerability_report_menu_item
strong_memoize(:vulnerability_report_menu_item) do
unless can?(context.current_user, :read_project_security_dashboard, context.project) unless can?(context.current_user, :read_project_security_dashboard, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :vulnerability_report) return ::Sidebars::NilMenuItem.new(item_id: :vulnerability_report)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -100,12 +85,10 @@ module EE ...@@ -100,12 +85,10 @@ module EE
item_id: :vulnerability_report item_id: :vulnerability_report
) )
end end
end
def on_demand_scans_menu_item def on_demand_scans_menu_item
strong_memoize(:on_demand_scans_menu_item) do
unless can?(context.current_user, :read_on_demand_scans, context.project) unless can?(context.current_user, :read_on_demand_scans, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :on_demand_scans) return ::Sidebars::NilMenuItem.new(item_id: :on_demand_scans)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -119,12 +102,10 @@ module EE ...@@ -119,12 +102,10 @@ module EE
] } ] }
) )
end end
end
def dependencies_menu_item def dependencies_menu_item
strong_memoize(:dependencies_menu_item) do
unless can?(context.current_user, :read_dependencies, context.project) unless can?(context.current_user, :read_dependencies, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :dependency_list) return ::Sidebars::NilMenuItem.new(item_id: :dependency_list)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -134,12 +115,10 @@ module EE ...@@ -134,12 +115,10 @@ module EE
item_id: :dependency_list item_id: :dependency_list
) )
end end
end
def license_compliance_menu_item def license_compliance_menu_item
strong_memoize(:license_compliance_menu_item) do
unless can?(context.current_user, :read_licenses, context.project) unless can?(context.current_user, :read_licenses, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :license_compliance) return ::Sidebars::NilMenuItem.new(item_id: :license_compliance)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -149,12 +128,10 @@ module EE ...@@ -149,12 +128,10 @@ module EE
item_id: :license_compliance item_id: :license_compliance
) )
end end
end
def threat_monitoring_menu_item def threat_monitoring_menu_item
strong_memoize(:threat_monitoring_menu_item) do
unless can?(context.current_user, :read_threat_monitoring, context.project) unless can?(context.current_user, :read_threat_monitoring, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :threat_monitoring) return ::Sidebars::NilMenuItem.new(item_id: :threat_monitoring)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -164,13 +141,11 @@ module EE ...@@ -164,13 +141,11 @@ module EE
item_id: :threat_monitoring item_id: :threat_monitoring
) )
end end
end
def scan_policies_menu_item def scan_policies_menu_item
strong_memoize(:scan_policies_menu_item) do
if ::Feature.disabled?(:security_orchestration_policies_configuration, context.project) || if ::Feature.disabled?(:security_orchestration_policies_configuration, context.project) ||
!can?(context.current_user, :security_orchestration_policies, context.project) !can?(context.current_user, :security_orchestration_policies, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :scan_policies) return ::Sidebars::NilMenuItem.new(item_id: :scan_policies)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -180,12 +155,10 @@ module EE ...@@ -180,12 +155,10 @@ module EE
item_id: :scan_policies item_id: :scan_policies
) )
end end
end
def audit_events_menu_item def audit_events_menu_item
strong_memoize(:audit_events_menu_item) do
unless show_audit_events? unless show_audit_events?
next ::Sidebars::NilMenuItem.new(item_id: :audit_events) return ::Sidebars::NilMenuItem.new(item_id: :audit_events)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -195,7 +168,6 @@ module EE ...@@ -195,7 +168,6 @@ module EE
item_id: :audit_events item_id: :audit_events
) )
end end
end
def show_audit_events? def show_audit_events?
can?(context.current_user, :read_project_audit_events, context.project) && can?(context.current_user, :read_project_audit_events, context.project) &&
......
...@@ -65,8 +65,8 @@ RSpec.describe 'Project navbar' do ...@@ -65,8 +65,8 @@ RSpec.describe 'Project navbar' do
_('Security Dashboard'), _('Security Dashboard'),
_('Vulnerability Report'), _('Vulnerability Report'),
s_('OnDemandScans|On-demand Scans'), s_('OnDemandScans|On-demand Scans'),
_('Configuration'), _('Audit Events'),
_('Audit Events') _('Configuration')
] ]
} }
end end
......
...@@ -10,44 +10,20 @@ RSpec.describe Sidebars::Projects::Menus::SecurityComplianceMenu do ...@@ -10,44 +10,20 @@ RSpec.describe Sidebars::Projects::Menus::SecurityComplianceMenu do
let(:show_discover_project_security) { true } let(:show_discover_project_security) { true }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, show_promotions: show_promotions, show_discover_project_security: show_discover_project_security) } let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, show_promotions: show_promotions, show_discover_project_security: show_discover_project_security) }
subject(:menu) { described_class.new(context) }
describe 'render?' do
subject { menu.render? }
context 'when user is not authenticated' do
let(:user) { nil }
it { is_expected.to be_falsey }
end
context 'when user is authenticated' do
context 'when the Security & Compliance is disabled' do
before do
allow(Ability).to receive(:allowed?).with(user, :access_security_and_compliance, project).and_return(false)
end
it { is_expected.to be_falsey }
end
context 'when the Security & Compliance is not disabled' do
it { is_expected.to be_truthy }
end
end
end
describe '#link' do describe '#link' do
subject { described_class.new(context) }
let(:show_promotions) { false } let(:show_promotions) { false }
let(:show_discover_project_security) { false } let(:show_discover_project_security) { false }
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:security_dashboard_feature, :audit_events_feature, :dependency_scanning_feature, :show_discover_project_security, :expected_link) do where(:show_discover_project_security, :security_dashboard_feature, :dependency_scanning_feature, :audit_events_feature, :expected_link) do
true | true | true | false | "/-/security/dashboard" true | true | true | true | '/-/security/discover'
false | true | true | false | "/-/audit_events" false | true | true | true | '/-/security/dashboard'
false | false | true | false | "/-/dependencies" false | false | true | true | '/-/dependencies'
false | false | true | true | "/-/security/discover" false | false | false | true | '/-/audit_events'
false | false | false | false | "/-/security/configuration" false | false | false | false | '/-/security/configuration'
end end
with_them do with_them do
......
...@@ -17,7 +17,7 @@ module Sidebars ...@@ -17,7 +17,7 @@ module Sidebars
override :link override :link
def link def link
project_security_configuration_path(context.project) renderable_items.first&.link
end end
override :title override :title
...@@ -33,9 +33,8 @@ module Sidebars ...@@ -33,9 +33,8 @@ module Sidebars
private private
def configuration_menu_item def configuration_menu_item
strong_memoize(:configuration_menu_item) do
unless render_configuration_menu_item? unless render_configuration_menu_item?
next ::Sidebars::NilMenuItem.new(item_id: :configuration) return ::Sidebars::NilMenuItem.new(item_id: :configuration)
end end
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -45,7 +44,6 @@ module Sidebars ...@@ -45,7 +44,6 @@ module Sidebars
item_id: :configuration item_id: :configuration
) )
end end
end
def render_configuration_menu_item? def render_configuration_menu_item?
can?(context.current_user, :read_security_configuration, context.project) can?(context.current_user, :read_security_configuration, context.project)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::SecurityComplianceMenu do
let_it_be(:project) { create(:project) }
let(:user) { project.owner }
let(:show_promotions) { true }
let(:show_discover_project_security) { true }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, show_promotions: show_promotions, show_discover_project_security: show_discover_project_security) }
describe 'render?' do
subject { described_class.new(context).render? }
context 'when user is not authenticated' do
let(:user) { nil }
it { is_expected.to be_falsey }
end
context 'when user is authenticated' do
context 'when the Security & Compliance is disabled' do
before do
allow(Ability).to receive(:allowed?).with(user, :access_security_and_compliance, project).and_return(false)
end
it { is_expected.to be_falsey }
end
context 'when the Security & Compliance is not disabled' do
it { is_expected.to be_truthy }
end
end
end
end
...@@ -18,8 +18,8 @@ RSpec.shared_context 'project navbar structure' do ...@@ -18,8 +18,8 @@ RSpec.shared_context 'project navbar structure' do
{ {
nav_item: _('Security & Compliance'), nav_item: _('Security & Compliance'),
nav_sub_items: [ nav_sub_items: [
_('Configuration'), (_('Audit Events') if Gitlab.ee?),
(_('Audit Events') if Gitlab.ee?) _('Configuration')
] ]
} }
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