Commit d43d00da authored by Tetiana Chupryna's avatar Tetiana Chupryna Committed by Peter Leitzen

Add license_scanning report key

We'll drop license_management when FE is done
parent be1edb93
......@@ -177,7 +177,8 @@ module EE
container_scanning: report_type_enabled?(:container_scanning),
dast: report_type_enabled?(:dast),
dependency_scanning: report_type_enabled?(:dependency_scanning),
license_management: report_type_enabled?(:license_scanning)
license_management: report_type_enabled?(:license_scanning),
license_scanning: report_type_enabled?(:license_scanning)
}
end
......
......@@ -40,6 +40,7 @@ module EE
merge_request.enabled_reports
end
# TODO: remove after https://gitlab.com/gitlab-org/gitlab/issues/205304 is done
expose :license_management, if: -> (mr, _) { head_pipeline_downloadable_path_for_report_type(:license_management) } do
expose :managed_licenses_path do |merge_request|
expose_path(api_v4_projects_managed_licenses_path(id: merge_request.target_project.id))
......@@ -58,6 +59,24 @@ module EE
end
end
expose :license_scanning, if: -> (mr, _) { head_pipeline_downloadable_path_for_report_type(:license_scanning) } do
expose :managed_licenses_path do |merge_request|
expose_path(api_v4_projects_managed_licenses_path(id: merge_request.target_project.id))
end
expose :can_manage_licenses do |merge_request|
can?(current_user, :admin_software_license_policy, merge_request)
end
expose :settings_path, if: -> (mr, _) { can?(current_user, :admin_software_license_policy, mr.target_project) } do |merge_request|
license_management_settings_path(merge_request.target_project)
end
expose :full_report_path, if: -> (mr, _) { mr.head_pipeline } do |merge_request|
licenses_project_pipeline_path(merge_request.target_project, merge_request.head_pipeline)
end
end
expose :metrics_reports_path, if: -> (mr, _) { mr.has_metrics_reports? } do |merge_request|
metrics_reports_project_merge_request_path(merge_request.project, merge_request, format: :json)
end
......
......@@ -128,6 +128,7 @@ describe MergeRequest do
:dependency_scanning | :with_dependency_scanning_reports | :dependency_scanning
:license_management | :with_license_management_reports | :license_management
:license_management | :with_license_scanning_reports | :license_management
:license_scanning | :with_license_scanning_reports | :license_management
end
with_them do
......
......@@ -59,37 +59,6 @@ describe MergeRequestWidgetEntity do
expect { serializer.represent(merge_request) }.not_to exceed_query_limit(control)
end
describe 'enabled_reports' do
it 'marks all reports as disabled by default' do
expect(subject.as_json).to include(:enabled_reports)
expect(subject.as_json[:enabled_reports]).to eq({
sast: false,
container_scanning: false,
dast: false,
dependency_scanning: false,
license_management: false
})
end
it 'marks reports as enabled if artifacts exist' do
allow(merge_request).to receive(:enabled_reports).and_return({
sast: true,
container_scanning: true,
dast: true,
dependency_scanning: true,
license_management: true
})
expect(subject.as_json).to include(:enabled_reports)
expect(subject.as_json[:enabled_reports]).to eq({
sast: true,
container_scanning: true,
dast: true,
dependency_scanning: true,
license_management: true
})
end
end
describe 'test report artifacts', :request_store do
using RSpec::Parameterized::TableSyntax
......@@ -206,6 +175,79 @@ describe MergeRequestWidgetEntity do
end
end
describe '#license_scanning', :request_store do
before do
allow(merge_request).to receive_messages(head_pipeline: pipeline, target_project: project)
stub_licensed_features(license_management: true)
end
it 'is not included, if missing artifacts' do
expect(subject.as_json).not_to include(:license_scanning)
end
context 'when report artifact is defined' do
before do
create(:ee_ci_build, :license_scanning, pipeline: pipeline)
end
it 'is included' do
expect(subject.as_json[:license_scanning]).to include(:can_manage_licenses)
expect(subject.as_json[:license_scanning]).to include(:full_report_path)
end
it '#settings_path should not be included for developers' do
expect(subject.as_json[:license_scanning]).not_to include(:settings_path)
end
context 'when feature is not licensed' do
before do
stub_licensed_features(license_management: false)
end
it 'is not included' do
expect(subject.as_json).not_to include(:license_scanning)
end
end
context 'when user is maintainer' do
before do
project.add_maintainer(user)
end
it '#settings_path should be included for maintainers' do
expect(subject.as_json[:license_scanning]).to include(:settings_path)
end
end
end
describe '#managed_licenses_path' do
let(:managed_licenses_path) { expose_path(api_v4_projects_managed_licenses_path(id: project.id)) }
before do
create(:ee_ci_build, :license_scanning, pipeline: pipeline)
end
it 'is a path for target project' do
expect(subject.as_json[:license_scanning][:managed_licenses_path]).to eq(managed_licenses_path)
end
context 'with fork' do
let(:source_project) { fork_project(project, user, repository: true) }
let(:fork_merge_request) { create(:merge_request, source_project: source_project, target_project: project) }
let(:subject_json) { described_class.new(fork_merge_request, current_user: user, request: request).as_json }
before do
allow(fork_merge_request).to receive_messages(head_pipeline: pipeline)
stub_licensed_features(license_management: true)
end
it 'is a path for target project' do
expect(subject_json[:license_scanning][:managed_licenses_path]).to eq(managed_licenses_path)
end
end
end
end
it 'has vulnerability feedback paths' do
expect(subject.as_json[:vulnerability_feedback_path]).to eq(
"/#{merge_request.project.full_path}/-/vulnerability_feedback"
......
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