Commit b35fa8a7 authored by Brian Williams's avatar Brian Williams

Rename PoliciesController#show to PoliciesController#index

This changes the PoliciesController list view to be more consistent with
other list views in GitLab.
- Rename the action from #show to #index
- Change the route from security/policy to security/policies
parent 60f2892d
...@@ -15,8 +15,8 @@ module Projects ...@@ -15,8 +15,8 @@ module Projects
feature_category :security_orchestration feature_category :security_orchestration
def show def index
render :show, locals: { project: project } render :index, locals: { project: project }
end end
def edit def edit
...@@ -42,8 +42,8 @@ module Projects ...@@ -42,8 +42,8 @@ module Projects
if result[:status] == :error if result[:status] == :error
case result[:invalid_component] case result[:invalid_component]
when :policy_configuration when :policy_configuration, :parameter
redirect_to project_security_policy_path(project), alert: result[:message] redirect_to project_security_policies_path(project), alert: result[:message]
when :policy_project when :policy_project
redirect_to project_path(policy_configuration.security_policy_management_project) redirect_to project_path(policy_configuration.security_policy_management_project)
when :policy_yaml when :policy_yaml
...@@ -52,12 +52,7 @@ module Projects ...@@ -52,12 +52,7 @@ module Projects
redirect_to project_blob_path(policy_management_project, policy_path), alert: result[:message] redirect_to project_blob_path(policy_management_project, policy_path), alert: result[:message]
else else
# We should redirect to security policies list view once it is implemented. redirect_to project_security_policies_path(project), alert: result[:message]
# For now, we will render_404
# This case also covers `when :parameter`
# redirect_to project_security_policies_path(project), alert: result[:message]
render_404
end end
end end
end end
......
- add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policy_path(@project) - add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policies_path(@project)
- breadcrumb_title s_("SecurityOrchestration|Edit policy") - breadcrumb_title s_("SecurityOrchestration|Edit policy")
- page_title s_("SecurityOrchestration|Edit policy") - page_title s_("SecurityOrchestration|Edit policy")
......
- add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policy_path(@project) - add_to_breadcrumbs s_("SecurityOrchestration|Policies"), project_security_policies_path(@project)
- breadcrumb_title s_("SecurityOrchestration|New policy") - breadcrumb_title s_("SecurityOrchestration|New policy")
- page_title s_("SecurityOrchestration|Policy editor") - page_title s_("SecurityOrchestration|Policy editor")
- policy_details = policy_details(@project) - policy_details = policy_details(@project)
......
...@@ -59,10 +59,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -59,10 +59,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :dashboard, only: [:index], controller: :dashboard resources :dashboard, only: [:index], controller: :dashboard
resources :vulnerability_report, only: [:index], controller: :vulnerability_report resources :vulnerability_report, only: [:index], controller: :vulnerability_report
resources :policies, only: [:index, :new, :edit], constraints: { id: %r{[^/]+} }
resource :policy, only: [:show]
resources :policies, only: [:new, :edit], controller: :policies, constraints: { id: %r{[^/]+} }
resource :configuration, only: [], controller: :configuration do resource :configuration, only: [], controller: :configuration do
post :auto_fix, on: :collection post :auto_fix, on: :collection
......
...@@ -150,7 +150,7 @@ module EE ...@@ -150,7 +150,7 @@ module EE
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
title: _('Policies'), title: _('Policies'),
link: project_security_policy_path(context.project), link: project_security_policies_path(context.project),
active_routes: { controller: ['projects/security/policies'] }, active_routes: { controller: ['projects/security/policies'] },
item_id: :scan_policies item_id: :scan_policies
) )
......
...@@ -21,7 +21,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -21,7 +21,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
end end
let_it_be(:type) { 'scan_execution_policy' } let_it_be(:type) { 'scan_execution_policy' }
let_it_be(:show) { project_security_policy_url(project) } let_it_be(:index) { project_security_policies_url(project) }
let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) } let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) }
let_it_be(:new) { new_project_security_policy_url(project) } let_it_be(:new) { new_project_security_policy_url(project) }
...@@ -55,10 +55,20 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -55,10 +55,20 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
context 'when type is missing' do context 'when type is missing' do
let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name]) } let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name]) }
it 'returns 404' do it 'redirects to #index' do
get edit get edit
expect(response).to have_gitlab_http_status(:not_found) expect(response).to redirect_to(project_security_policies_path(project))
end
end
context 'when type is invalid' do
let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: 'invalid') }
it 'redirects to #index' do
get edit
expect(response).to redirect_to(project_security_policies_path(project))
end end
end end
...@@ -77,10 +87,10 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -77,10 +87,10 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
let_it_be(:policy_configuration) { nil } let_it_be(:policy_configuration) { nil }
let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) } let_it_be(:edit) { edit_project_security_policy_url(project, id: policy[:name], type: type) }
it 'redirects to policy configuration page' do it 'redirects to #index' do
get edit get edit
expect(response).to redirect_to(project_security_policy_path(project)) expect(response).to redirect_to(project_security_policies_path(project))
end end
end end
...@@ -182,7 +192,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -182,7 +192,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
end end
end end
describe 'GET #show' do describe 'GET #index' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:feature_flag, :license, :status) do where(:feature_flag, :license, :status) do
...@@ -192,7 +202,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do ...@@ -192,7 +202,7 @@ RSpec.describe Projects::Security::PoliciesController, type: :request do
true | false | :not_found true | false | :not_found
end end
subject(:request) { get show, params: { namespace_id: project.namespace, project_id: project } } subject(:request) { get index, params: { namespace_id: project.namespace, project_id: project } }
with_them do with_them do
before do before do
......
...@@ -74,8 +74,8 @@ RSpec.describe 'EE-specific project routing' do ...@@ -74,8 +74,8 @@ RSpec.describe 'EE-specific project routing' do
expect(get("/gitlab/gitlabhq/-/security/policies/new")).to route_to('projects/security/policies#new', namespace_id: 'gitlab', project_id: 'gitlabhq') expect(get("/gitlab/gitlabhq/-/security/policies/new")).to route_to('projects/security/policies#new', namespace_id: 'gitlab', project_id: 'gitlabhq')
end end
it 'to #show' do it 'to #index' do
expect(get('/gitlab/gitlabhq/-/security/policy')).to route_to('projects/security/policies#show', namespace_id: 'gitlab', project_id: 'gitlabhq') expect(get('/gitlab/gitlabhq/-/security/policies')).to route_to('projects/security/policies#index', namespace_id: 'gitlab', project_id: 'gitlabhq')
end end
with_them do with_them do
......
...@@ -204,7 +204,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -204,7 +204,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
it 'policies link is visible' do it 'policies link is visible' do
expect(rendered).to have_link('Policies', href: project_security_policy_path(project)) expect(rendered).to have_link('Policies', href: project_security_policies_path(project))
end end
it 'security configuration link is visible' do it 'security configuration link is visible' do
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe "projects/security/policies/show", type: :view do RSpec.describe "projects/security/policies/index", type: :view do
let(:user) { project.owner } let(:user) { project.owner }
let(:project) { create(:project) } let(:project) { create(:project) }
before do before do
stub_feature_flags(security_orchestration_policies_configuration: true) stub_feature_flags(security_orchestration_policies_configuration: true)
sign_in(user) sign_in(user)
render template: 'projects/security/policies/show', locals: { project: project } render template: 'projects/security/policies/index', locals: { project: project }
end end
it 'renders Vue app root' do it 'renders Vue app root' do
......
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