Commit eccf759b authored by Can Eldem's avatar Can Eldem Committed by James Lopez

Present lm reports from backend instead of fe pipelines section

This end point will be exposed in haml
End point exposed in mr controller
parent b23c8449
......@@ -14,10 +14,18 @@ module EE
end
def licenses
if pipeline.expose_license_management_data?
render_show
else
redirect_to pipeline_path(pipeline)
report_exists = pipeline.expose_license_management_data?
respond_to do |format|
if report_exists
format.html { render_show }
format.json do
render json: LicenseManagementReportLicenseEntity.licenses_payload(pipeline.license_management_report), status: :ok
end
else
format.html { redirect_to pipeline_path(pipeline) }
format.json { head :not_found }
end
end
end
......
......@@ -3,4 +3,11 @@
class LicenseManagementReportLicenseEntity < Grape::Entity
expose :name
expose :dependencies, using: LicenseManagementReportDependencyEntity
expose :count do |license|
license.dependencies.size
end
def self.licenses_payload(report)
report.licenses.empty? ? {} : self.represent(report.licenses).as_json
end
end
......@@ -7,6 +7,7 @@
- sast_container_endpoint = pipeline.downloadable_path_for_report_type(:container_scanning)
- blob_path = project_blob_path(project, pipeline.sha)
- license_management_settings_path = can?(current_user, :admin_software_license_policy, project) ? license_management_settings_path(project) : nil
- licenses_api_path = licenses_project_pipeline_path(project, pipeline) if project.feature_available?(:license_management)
- if pipeline.expose_security_dashboard?
#js-tab-security.build-security.tab-pane
......@@ -32,4 +33,5 @@
#js-licenses-app{ data: { license_head_path: pipeline.downloadable_path_for_report_type(:license_management),
api_url: license_management_api_url(project),
license_management_settings_path: license_management_settings_path,
licenses_api_path: licenses_api_path,
can_manage_licenses: can?(current_user, :admin_software_license_policy, project).to_s } }
---
title: Expose licence management report for pipeline
merge_request: 14796
author:
type: changed
......@@ -19,7 +19,6 @@ describe Projects::PipelinesController do
set(:source_of_source_pipeline) { create_pipeline(source_project) }
set(:target_pipeline) { create_pipeline(target_project) }
set(:target_of_target_pipeline) { create_pipeline(target_project) }
before do
create_link(source_of_source_pipeline, source_pipeline)
create_link(source_pipeline, root_pipeline)
......@@ -253,6 +252,10 @@ describe Projects::PipelinesController do
end
describe 'GET licenses' do
let(:licenses_with_html) {get :licenses, format: :html, params: { namespace_id: project.namespace, project_id: project, id: pipeline }}
let(:licenses_with_json) {get :licenses, format: :json, params: { namespace_id: project.namespace, project_id: project, id: pipeline }}
let(:payload) { JSON.parse(licenses_with_json.body) }
context 'with a license management artifact' do
before do
build = create(:ci_build, pipeline: pipeline)
......@@ -262,8 +265,7 @@ describe Projects::PipelinesController do
context 'with feature enabled' do
before do
stub_licensed_features(license_management: true)
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
licenses_with_html
end
it do
......@@ -272,23 +274,43 @@ describe Projects::PipelinesController do
end
end
context 'with feature enabled json' do
before do
stub_licensed_features(license_management: true)
end
it 'will return license management report in json format' do
expect(payload.size).to eq(pipeline.license_management_report.licenses.size)
expect(payload.first.keys).to eq(%w(name dependencies count))
end
end
context 'with feature disabled' do
before do
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
licenses_with_html
end
it do
expect(response).to redirect_to(pipeline_path(pipeline))
end
end
context 'with feature disabled json' do
before do
licenses_with_json
end
it 'will not return report' do
expect(response).to have_gitlab_http_status(404)
end
end
end
context 'without license management artifact' do
context 'with feature enabled' do
before do
stub_licensed_features(license_management: true)
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
licenses_with_html
end
it do
......@@ -296,15 +318,36 @@ describe Projects::PipelinesController do
end
end
context 'with feature enabled json' do
before do
stub_licensed_features(license_management: true)
licenses_with_json
end
it 'will return 404' do
expect(response).to have_gitlab_http_status(404)
end
end
context 'with feature disabled' do
before do
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
licenses_with_html
end
it do
expect(response).to redirect_to(pipeline_path(pipeline))
end
end
context 'with feature disabled json' do
before do
licenses_with_json
end
it 'will return 404' do
expect(response).to have_gitlab_http_status(404)
end
end
end
end
end
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