Commit 8642dd89 authored by Kamil Trzciński's avatar Kamil Trzciński

Refactor `license_management:` to use new `reports:` syntax

parent 04d83aec
......@@ -30,9 +30,10 @@ module EE
end
def license_management_artifact_url(pipeline)
raw_project_build_artifacts_url(pipeline.project,
pipeline.license_management_artifact,
path: Ci::Build::LICENSE_MANAGEMENT_FILE)
return unless pipeline
pipeline.present(current_user: current_user)
.downloadable_path_for_report_type(:license_management)
end
def license_management_api_url(project)
......
......@@ -33,11 +33,6 @@ module EE
::Gitlab::Database::LoadBalancing::Sticking.stick(:build, id)
end
def has_license_management_json?
name_in?('license_management') &&
has_artifact?(LICENSE_MANAGEMENT_FILE)
end
def log_geo_deleted_event
# It is not needed to generate a Geo deleted event
# since Legacy Artifacts are migrated to multi-build artifacts
......
......@@ -59,6 +59,10 @@ module EE
performance: {
names: %w(performance deploy),
files: %w(performance.json)
},
license_management: {
names: %w(license_management),
files: %w(gl-license-management-report.json)
}
}.freeze
......@@ -101,17 +105,8 @@ module EE
nil
end
def license_management_artifact
@license_management_artifact ||= artifacts_with_files.find(&:has_license_management_json?)
end
def has_license_management_data?
license_management_artifact&.success?
end
def expose_license_management_data?
project.feature_available?(:license_management) &&
has_license_management_data?
any_report_artifact_for_type(:license_management)
end
def has_security_reports?
......
......@@ -16,12 +16,8 @@ module EE
validate :validate_approvals_before_merge, unless: :importing?
delegate :license_management_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :license_management_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :sha, to: :head_pipeline, prefix: :head_pipeline, allow_nil: true
delegate :sha, to: :base_pipeline, prefix: :base_pipeline, allow_nil: true
delegate :has_license_management_data?, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :expose_license_management_data?, to: :head_pipeline, allow_nil: true
delegate :merge_requests_author_approval?, to: :target_project, allow_nil: true
participant :participant_approvers
......
......@@ -56,17 +56,13 @@ module EE
end
end
expose :license_management, if: -> (mr, _) { mr.expose_license_management_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_license_management_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_license_management_artifact,
path: Ci::Build::LICENSE_MANAGEMENT_FILE)
expose :license_management, if: -> (mr, _) { head_pipeline_downloadable_path_for_report_type(:license_management) } do
expose :head_path do |merge_request|
head_pipeline_downloadable_path_for_report_type(:license_management)
end
expose :base_path, if: -> (mr, _) { mr.base_has_license_management_data? && can?(current_user, :read_build, mr.base_license_management_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_license_management_artifact,
path: Ci::Build::LICENSE_MANAGEMENT_FILE)
expose :base_path do |merge_request|
base_pipeline_downloadable_path_for_report_type(:license_management)
end
expose :managed_licenses_path do |merge_request|
......@@ -77,7 +73,7 @@ module EE
can?(current_user, :admin_software_license_policy, merge_request)
end
expose :license_management_settings_path, if: -> (mr, _) {can?(current_user, :admin_software_license_policy, mr.target_project)} do |merge_request|
expose :license_management_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
......
......@@ -27,7 +27,7 @@
- if pipeline.expose_license_management_data?
#js-tab-licenses.tab-pane
#js-licenses-app{ data: { license_head_path: pipeline.expose_license_management_data? ? license_management_artifact_url(pipeline) : nil,
#js-licenses-app{ data: { license_management_artifact_url(pipeline),
api_url: license_management_api_url(project),
license_management_settings_path: license_management_settings_path,
can_manage_licenses: can?(current_user, :admin_software_license_policy, project).to_s } }
......@@ -83,18 +83,8 @@ describe Projects::PipelinesController do
context 'with a license management artifact' do
before do
create(
:ci_build,
:success,
:artifacts,
name: 'license_management',
pipeline: pipeline,
options: {
artifacts: {
paths: [Ci::Build::LICENSE_MANAGEMENT_FILE]
}
}
)
build = create(:ci_build, pipeline: pipeline)
create(:ee_ci_job_artifact, :license_management, build: build)
end
context 'with feature enabled' do
......
......@@ -21,5 +21,23 @@ FactoryBot.define do
Rails.root.join('ee/spec/fixtures/reports/security/sast_with_corrupted_data.json'), 'application/json')
end
end
trait :performance do
file_format :raw
file_type :performance
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/trace/sample_trace'), 'text/plain')
end
end
trait :license_management do
file_format :raw
file_type :license_management
after(:build) do |artifact, _|
artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/trace/sample_trace'), 'text/plain')
end
end
......@@ -115,71 +115,6 @@ describe Ci::Build do
end
end
build_artifacts_methods = {
has_license_management_json?: {
filename: Ci::Build::LICENSE_MANAGEMENT_FILE,
job_names: %w[license_management]
}
}
build_artifacts_methods.each do |method, requirements|
filename = requirements[:filename]
job_names = requirements[:job_names]
describe "##{method}" do
job_names.each do |job_name|
context "with a job named #{job_name} and a file named #{filename}" do
let(:build) do
create(
:ci_build,
:artifacts,
name: job_name,
pipeline: pipeline,
options: {
artifacts: {
paths: [filename, 'some-other-artifact.txt']
}
}
)
end
it { expect(build.send(method)).to be_truthy }
end
end
context 'with an invalid filename' do
let(:build) do
create(
:ci_build,
:artifacts,
name: job_names.first,
pipeline: pipeline,
options: {}
)
end
it { expect(build.send(method)).to be_falsey }
end
context 'with an invalid job name' do
let(:build) do
create(
:ci_build,
:artifacts,
pipeline: pipeline,
options: {
artifacts: {
paths: [filename, 'some-other-artifact.txt']
}
}
)
end
it { expect(build.send(method)).to be_falsey }
end
end
end
describe '.with_security_reports' do
subject { described_class.with_security_reports }
......
......@@ -20,70 +20,6 @@ describe Ci::Pipeline do
end
end
PIPELINE_ARTIFACTS_METHODS = [
{ method: :license_management_artifact, options: [Ci::Build::LICENSE_MANAGEMENT_FILE, 'license_management'] }
].freeze
PIPELINE_ARTIFACTS_METHODS.each do |method_test|
method, options = method_test.values_at(:method, :options)
describe method.to_s do
context 'has corresponding job' do
let!(:build) do
filename, name = options
create(
:ci_build,
:artifacts,
name: name,
pipeline: pipeline,
options: {
artifacts: {
paths: [filename]
}
}
)
end
it { expect(pipeline.send(method)).to eq(build) }
end
context 'no corresponding job' do
before do
create(:ci_build, pipeline: pipeline)
end
it { expect(pipeline.send(method)).to be_nil }
end
end
end
%w(performance license_management).each do |type|
method = "has_#{type}_data?"
describe "##{method}" do
let(:artifact) { double(success?: true) }
before do
allow(pipeline).to receive(:"#{type}_artifact").and_return(artifact)
end
it { expect(pipeline.send(method.to_sym)).to be_truthy }
end
end
%w(performance license_management).each do |type|
method = "expose_#{type}_data?"
describe "##{method}" do
before do
allow(pipeline).to receive(:"has_#{type}_data?").and_return(true)
allow(pipeline.project).to receive(:feature_available?).and_return(true)
end
it { expect(pipeline.send(method.to_sym)).to be_truthy }
end
end
describe '#with_legacy_security_reports scope' do
let(:pipeline_1) { create(:ci_pipeline_without_jobs, project: project) }
let(:pipeline_2) { create(:ci_pipeline_without_jobs, project: project) }
......
......@@ -40,37 +40,4 @@ describe MergeRequest do
it { expect(subject.base_pipeline).to eq(pipeline) }
end
describe '#base_license_management_artifact' do
before do
allow(subject.base_pipeline).to receive(:license_management_artifact)
.and_return(1)
end
it 'delegates to merge request diff' do
expect(subject.base_license_management_artifact).to eq(1)
end
end
describe '#head_license_management_artifact' do
before do
allow(subject.head_pipeline).to receive(:license_management_artifact)
.and_return(1)
end
it 'delegates to merge request diff' do
expect(subject.head_license_management_artifact).to eq(1)
end
end
describe '#expose_license_management_data?' do
before do
allow(subject.head_pipeline).to receive(:expose_license_management_data?)
.and_return(1)
end
it 'delegates to merge request diff' do
expect(subject.expose_license_management_data?).to eq(1)
end
end
end
......@@ -76,16 +76,8 @@ describe MergeRequestWidgetEntity do
describe '#license_management' do
before do
build = create(:ci_build, name: 'license_management', pipeline: pipeline)
allow(merge_request).to receive_messages(
expose_license_management_data?: true,
base_has_license_management_data?: true,
base_license_management_artifact: build,
head_license_management_artifact: build,
head_pipeline: pipeline,
target_project: project
)
build = create(:ci_build, pipeline: pipeline)
create(:ee_ci_job_artifact, :license_management, build: build)
end
it 'should not be included, if license management features are off' 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