From bbec73e53afa6c81fe4b49dc79ba645888b8fb7e Mon Sep 17 00:00:00 2001
From: David Pisek <dpisek@gitlab.com>
Date: Wed, 24 Jul 2019 11:30:31 +0000
Subject: [PATCH] Add partials and logic for security sidebar item

This commit adds the partials and logic needed for rendering the new
top-level navigation item within the project's sidebar.
---
 .../layouts/nav/sidebar/_project.html.haml    |  6 ++---
 ee/app/helpers/ee/projects_helper.rb          | 13 +++++++++--
 .../sidebar/_project_security_link.html.haml  | 23 +++++++++++++++++++
 .../projects/sidebar/_dependencies.html.haml  |  4 ----
 .../sidebar/_security_dashboard.html.haml     |  4 ----
 ...security-navigation-section-project-ee.yml |  5 ++++
 locale/gitlab.pot                             |  3 +++
 7 files changed, 44 insertions(+), 14 deletions(-)
 create mode 100644 ee/app/views/layouts/nav/sidebar/_project_security_link.html.haml
 delete mode 100644 ee/app/views/projects/sidebar/_dependencies.html.haml
 delete mode 100644 ee/app/views/projects/sidebar/_security_dashboard.html.haml
 create mode 100644 ee/changelogs/unreleased/12250-mvc-security-navigation-section-project-ee.yml

diff --git a/app/views/layouts/nav/sidebar/_project.html.haml b/app/views/layouts/nav/sidebar/_project.html.haml
index 8caae5eed83..d1634eb62c0 100644
--- a/app/views/layouts/nav/sidebar/_project.html.haml
+++ b/app/views/layouts/nav/sidebar/_project.html.haml
@@ -34,10 +34,6 @@
               = link_to project_releases_path(@project), title: _('Releases'), class: 'shortcuts-project-releases' do
                 %span= _('Releases')
 
-          = render_if_exists 'projects/sidebar/security_dashboard'
-
-          = render_if_exists 'projects/sidebar/dependencies'
-
           - if can?(current_user, :read_cycle_analytics, @project)
             = nav_link(path: 'cycle_analytics#show') do
               = link_to project_cycle_analytics_path(@project), title: _('Cycle Analytics'), class: 'shortcuts-project-cycle-analytics' do
@@ -203,6 +199,8 @@
                   %span
                     = _('Charts')
 
+      = render_if_exists 'layouts/nav/sidebar/project_security_link' # EE-specific
+
       - if project_nav_tab? :operations
         = nav_link(controller: sidebar_operations_paths) do
           = link_to sidebar_operations_link_path, class: 'shortcuts-operations qa-link-operations' do
diff --git a/ee/app/helpers/ee/projects_helper.rb b/ee/app/helpers/ee/projects_helper.rb
index 312d57956b7..572238b07d2 100644
--- a/ee/app/helpers/ee/projects_helper.rb
+++ b/ee/app/helpers/ee/projects_helper.rb
@@ -7,8 +7,6 @@ module EE
     override :sidebar_projects_paths
     def sidebar_projects_paths
       super + %w[
-        projects/dependencies#show
-        projects/security/dashboard#show
         projects/insights#show
       ]
     end
@@ -38,6 +36,10 @@ module EE
     def get_project_nav_tabs(project, current_user)
       nav_tabs = super
 
+      if can?(current_user, :read_project_security_dashboard, @project)
+        nav_tabs << :security
+      end
+
       if ::Gitlab.config.packages.enabled &&
           project.feature_available?(:packages) &&
           can?(current_user, :read_package, project)
@@ -128,6 +130,13 @@ module EE
       @project.feature_available?(:merge_trains)
     end
 
+    def sidebar_security_paths
+      %w[
+        projects/security/dashboard#show
+        projects/dependencies#show
+      ]
+    end
+
     def size_limit_message(project)
       show_lfs = project.lfs_enabled? ? 'including files in LFS' : ''
 
diff --git a/ee/app/views/layouts/nav/sidebar/_project_security_link.html.haml b/ee/app/views/layouts/nav/sidebar/_project_security_link.html.haml
new file mode 100644
index 00000000000..b7fb0703c8f
--- /dev/null
+++ b/ee/app/views/layouts/nav/sidebar/_project_security_link.html.haml
@@ -0,0 +1,23 @@
+- if project_nav_tab?(:security)
+  = nav_link(path: sidebar_security_paths) do
+    = link_to project_security_dashboard_path(@project), title: _('Security Dashboard') do
+      .nav-icon-container
+        = sprite_icon('shield')
+      %span.nav-item-name
+        = _('Security & Compliance')
+
+    %ul.sidebar-sub-level-items
+      = nav_link(path: sidebar_security_paths, html_options: { class: "fly-out-top-item" } ) do
+        = link_to project_security_dashboard_path(@project) do
+          %strong.fly-out-top-item-name
+            = _('Security & Compliance')
+      %li.divider.fly-out-top-item
+
+      = nav_link(path: 'projects/security/dashboard#show') do
+        = link_to project_security_dashboard_path(@project), title: _('Security Dashboard') do
+          %span= _('Security Dashboard')
+
+      - if @project.feature_available?(:dependency_list)
+        = nav_link(path: 'projects/dependencies#show') do
+          = link_to project_dependencies_path(@project), title: _('Dependency List') do
+            %span= _('Dependency List')
diff --git a/ee/app/views/projects/sidebar/_dependencies.html.haml b/ee/app/views/projects/sidebar/_dependencies.html.haml
deleted file mode 100644
index 4eb1724bf75..00000000000
--- a/ee/app/views/projects/sidebar/_dependencies.html.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-- if @project.feature_available?(:dependency_list)
-  = nav_link(path: 'projects/dependencies#show') do
-    = link_to project_dependencies_path(@project), title: _('Dependency List'), class: 'shortcuts-project-dependencies' do
-      %span= _('Dependency List')
diff --git a/ee/app/views/projects/sidebar/_security_dashboard.html.haml b/ee/app/views/projects/sidebar/_security_dashboard.html.haml
deleted file mode 100644
index 27e83eb1a7c..00000000000
--- a/ee/app/views/projects/sidebar/_security_dashboard.html.haml
+++ /dev/null
@@ -1,4 +0,0 @@
-- if can?(current_user, :read_project_security_dashboard, @project)
-  = nav_link(path: 'projects/security/dashboard#show') do
-    = link_to project_security_dashboard_path(@project), title: _('Security Dashboard'), class: 'shortcuts-project-security-dashboard' do
-      %span= _('Security Dashboard')
diff --git a/ee/changelogs/unreleased/12250-mvc-security-navigation-section-project-ee.yml b/ee/changelogs/unreleased/12250-mvc-security-navigation-section-project-ee.yml
new file mode 100644
index 00000000000..0d755707404
--- /dev/null
+++ b/ee/changelogs/unreleased/12250-mvc-security-navigation-section-project-ee.yml
@@ -0,0 +1,5 @@
+---
+title: Add 'Security & Compliance' as top-level navigation item to the project-sidebar
+merge_request: 14628
+author:
+type: changed
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index ac43d3f6544..b83b29b28c0 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -12232,6 +12232,9 @@ msgstr ""
 msgid "Security"
 msgstr ""
 
+msgid "Security & Compliance"
+msgstr ""
+
 msgid "Security Dashboard"
 msgstr ""
 
-- 
2.30.9