Commit 834471fc authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'config_page' into 'master'

Provide information to configuration page to enable SAST job

See merge request gitlab-org/gitlab!36225
parents fc95a86c 7f17a6da
......@@ -22,4 +22,8 @@ module AutoDevopsHelper
s_('CICD|instance enabled')
end
end
def auto_devops_settings_path(project)
project_settings_ci_cd_path(project, anchor: 'autodevops-settings')
end
end
......@@ -18,7 +18,9 @@ module Projects
end
def show
@configuration = ConfigurationPresenter.new(project, auto_fix_permission: auto_fix_authorized?)
@configuration = ConfigurationPresenter.new(project,
auto_fix_permission: auto_fix_authorized?,
current_user: current_user)
end
def auto_fix
......
......@@ -4,6 +4,7 @@ module Projects
module Security
class ConfigurationPresenter < Gitlab::View::Presenter::Delegated
include Gitlab::Utils::StrongMemoize
include AutoDevopsHelper
presents :project
......@@ -49,6 +50,8 @@ module Projects
auto_devops_enabled: auto_devops_source?,
auto_devops_help_page_path: help_page_path('topics/autodevops/index'),
create_sast_merge_request_path: project_security_configuration_sast_path(project),
auto_devops_path: auto_devops_settings_path(project),
can_enable_auto_devops: can_enable_auto_devops?,
features: features.to_json,
help_page_path: help_page_path('user/application_security/index'),
latest_pipeline_path: latest_pipeline_path,
......@@ -57,12 +60,23 @@ module Projects
container_scanning: project_settings.auto_fix_container_scanning
}.to_json,
can_toggle_auto_fix_settings: auto_fix_permission,
gitlab_ci_present: gitlab_ci_present?,
auto_fix_user_path: '/' # TODO: real link will be updated with https://gitlab.com/gitlab-org/gitlab/-/issues/215669
}
end
private
def can_enable_auto_devops?
feature_available?(:builds, current_user) &&
can?(current_user, :admin_project, self) &&
!archived?
end
def gitlab_ci_present?
latest_pipeline_for_ref.try(:config_path) == Gitlab::FileDetector::PATTERNS[:gitlab_ci]
end
def features
scans = scan_types.map do |scan_type|
if auto_devops_source?
......
---
title: Provide CI data to the security configuration page to enable SAST job
merge_request: 36225
author:
type: changed
......@@ -6,6 +6,7 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
include Gitlab::Routing.url_helpers
let(:project) { create(:project, :repository) }
let(:current_user) { create(:user) }
it 'presents the given project' do
presenter = described_class.new(project)
......@@ -13,8 +14,12 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
expect(presenter.id).to be(project.id)
end
before do
project.add_maintainer(current_user)
end
describe '#to_h' do
subject { described_class.new(project, auto_fix_permission: true).to_h }
subject { described_class.new(project, auto_fix_permission: true, current_user: current_user).to_h }
it 'includes links to auto devops and secure product docs' do
expect(subject[:auto_devops_help_page_path]).to eq(help_page_path('topics/autodevops/index'))
......@@ -163,6 +168,48 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
it 'includes a link to the latest pipeline' do
expect(subject[:latest_pipeline_path]).to eq(project_pipeline_path(project, pipeline))
end
context "while retrieving information about gitlab ci file" do
it 'expects the gitlab_ci_presence to be true if the file is present' do
expect(subject[:gitlab_ci_present]).to eq(true)
end
it 'expects the gitlab_ci_presence to be false if the file is absent' do
allow_any_instance_of(described_class).to receive(:latest_pipeline_for_ref).and_return(nil)
expect(subject[:gitlab_ci_present]).to eq(false)
end
end
it 'includes the auto_devops_path' do
expect(subject[:auto_devops_path]).to eq(project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end
context "while retrieving information about user's ability to enable auto_devops" do
using RSpec::Parameterized::TableSyntax
where(:is_admin, :archived, :feature_available, :result) do
true | true | true | false
false | true | true | false
true | false | true | true
false | false | true | false
true | true | false | false
false | true | false | false
true | false | false | false
false | false | false | false
end
with_them do
before do
allow_any_instance_of(described_class).to receive(:can?).and_return(is_admin)
allow_any_instance_of(described_class).to receive(:archived?).and_return(archived)
allow_any_instance_of(described_class).to receive(:feature_available?).and_return(feature_available)
end
it 'includes can_enable_auto_devops' do
expect(subject[:can_enable_auto_devops]).to eq(result)
end
end
end
end
end
......
......@@ -93,6 +93,12 @@ RSpec.describe AutoDevopsHelper do
end
end
describe '#auto_devops_settings_path' do
it 'returns auto devops settings path' do
expect(helper.auto_devops_settings_path(project)).to eql(project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end
end
describe '#badge_for_auto_devops_scope' do
subject { helper.badge_for_auto_devops_scope(receiver) }
......
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