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 ...@@ -14,10 +14,18 @@ module EE
end end
def licenses def licenses
if pipeline.expose_license_management_data? report_exists = pipeline.expose_license_management_data?
render_show
else respond_to do |format|
redirect_to pipeline_path(pipeline) 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
end end
......
...@@ -3,4 +3,11 @@ ...@@ -3,4 +3,11 @@
class LicenseManagementReportLicenseEntity < Grape::Entity class LicenseManagementReportLicenseEntity < Grape::Entity
expose :name expose :name
expose :dependencies, using: LicenseManagementReportDependencyEntity 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 end
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
- sast_container_endpoint = pipeline.downloadable_path_for_report_type(:container_scanning) - sast_container_endpoint = pipeline.downloadable_path_for_report_type(:container_scanning)
- blob_path = project_blob_path(project, pipeline.sha) - 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 - 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? - if pipeline.expose_security_dashboard?
#js-tab-security.build-security.tab-pane #js-tab-security.build-security.tab-pane
...@@ -32,4 +33,5 @@ ...@@ -32,4 +33,5 @@
#js-licenses-app{ data: { license_head_path: pipeline.downloadable_path_for_report_type(:license_management), #js-licenses-app{ data: { license_head_path: pipeline.downloadable_path_for_report_type(:license_management),
api_url: license_management_api_url(project), api_url: license_management_api_url(project),
license_management_settings_path: license_management_settings_path, 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 } } 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 ...@@ -19,7 +19,6 @@ describe Projects::PipelinesController do
set(:source_of_source_pipeline) { create_pipeline(source_project) } set(:source_of_source_pipeline) { create_pipeline(source_project) }
set(:target_pipeline) { create_pipeline(target_project) } set(:target_pipeline) { create_pipeline(target_project) }
set(:target_of_target_pipeline) { create_pipeline(target_project) } set(:target_of_target_pipeline) { create_pipeline(target_project) }
before do before do
create_link(source_of_source_pipeline, source_pipeline) create_link(source_of_source_pipeline, source_pipeline)
create_link(source_pipeline, root_pipeline) create_link(source_pipeline, root_pipeline)
...@@ -253,6 +252,10 @@ describe Projects::PipelinesController do ...@@ -253,6 +252,10 @@ describe Projects::PipelinesController do
end end
describe 'GET licenses' do 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 context 'with a license management artifact' do
before do before do
build = create(:ci_build, pipeline: pipeline) build = create(:ci_build, pipeline: pipeline)
...@@ -262,8 +265,7 @@ describe Projects::PipelinesController do ...@@ -262,8 +265,7 @@ describe Projects::PipelinesController do
context 'with feature enabled' do context 'with feature enabled' do
before do before do
stub_licensed_features(license_management: true) stub_licensed_features(license_management: true)
licenses_with_html
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
end end
it do it do
...@@ -272,23 +274,43 @@ describe Projects::PipelinesController do ...@@ -272,23 +274,43 @@ describe Projects::PipelinesController do
end end
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 context 'with feature disabled' do
before do before do
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline } licenses_with_html
end end
it do it do
expect(response).to redirect_to(pipeline_path(pipeline)) expect(response).to redirect_to(pipeline_path(pipeline))
end end
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 end
context 'without license management artifact' do context 'without license management artifact' do
context 'with feature enabled' do context 'with feature enabled' do
before do before do
stub_licensed_features(license_management: true) stub_licensed_features(license_management: true)
licenses_with_html
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline }
end end
it do it do
...@@ -296,15 +318,36 @@ describe Projects::PipelinesController do ...@@ -296,15 +318,36 @@ describe Projects::PipelinesController do
end end
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 context 'with feature disabled' do
before do before do
get :licenses, params: { namespace_id: project.namespace, project_id: project, id: pipeline } licenses_with_html
end end
it do it do
expect(response).to redirect_to(pipeline_path(pipeline)) expect(response).to redirect_to(pipeline_path(pipeline))
end end
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 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