Commit 655279d6 authored by mo khan's avatar mo khan Committed by Ash McKenzie

Apply maintainer feedback

parent 0c6a47c6
...@@ -47,7 +47,15 @@ class SoftwareLicensePolicy < ApplicationRecord ...@@ -47,7 +47,15 @@ class SoftwareLicensePolicy < ApplicationRecord
delegate :name, :spdx_identifier, to: :software_license delegate :name, :spdx_identifier, to: :software_license
def approval_status
APPROVAL_STATUS.key(classification) || classification
end
def self.workaround_cache_key def self.workaround_cache_key
pluck(:id, :classification).flatten pluck(:id, :classification).flatten
end end
def self.to_classification(approval_status)
APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end end
...@@ -10,7 +10,7 @@ class LicenseScanningReportLicenseEntity < Grape::Entity ...@@ -10,7 +10,7 @@ class LicenseScanningReportLicenseEntity < Grape::Entity
expose :url expose :url
def classification def classification
default = { id: nil, name: value_for(:name), classification: 'unclassified' } default = { id: nil, name: value_for(:name), approval_status: 'unclassified' }
found = SoftwareLicensePoliciesFinder.new(request&.current_user, request&.project, name: value_for(:name)).find found = SoftwareLicensePoliciesFinder.new(request&.current_user, request&.project, name: value_for(:name)).find
ManagedLicenseEntity.represent(found || default) ManagedLicenseEntity.represent(found || default)
end end
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
class ManagedLicenseEntity < Grape::Entity class ManagedLicenseEntity < Grape::Entity
expose :id expose :id
expose :classification, as: :approval_status do |policy| expose :approval_status
classification = policy[:classification]
SoftwareLicensePolicy::APPROVAL_STATUS.key(classification) || classification
end
expose :software_license, merge: true do expose :software_license, merge: true do
expose :name expose :name
end end
......
...@@ -24,14 +24,10 @@ module SoftwareLicensePolicies ...@@ -24,14 +24,10 @@ module SoftwareLicensePolicies
policy = SoftwareLicense.create_policy_for!( policy = SoftwareLicense.create_policy_for!(
project: project, project: project,
name: params[:name], name: params[:name],
classification: map_from(params[:approval_status]) classification: SoftwareLicensePolicy.to_classification(params[:approval_status])
) )
RefreshLicenseComplianceChecksWorker.perform_async(project.id) RefreshLicenseComplianceChecksWorker.perform_async(project.id)
policy policy
end end
def map_from(approval_status)
SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end end
end end
...@@ -11,17 +11,11 @@ module SoftwareLicensePolicies ...@@ -11,17 +11,11 @@ module SoftwareLicensePolicies
return error("", 403) unless can?(@current_user, :admin_software_license_policy, @project) return error("", 403) unless can?(@current_user, :admin_software_license_policy, @project)
return success(software_license_policy: software_license_policy) unless params[:approval_status].present? return success(software_license_policy: software_license_policy) unless params[:approval_status].present?
software_license_policy.update(classification: map_from(params[:approval_status])) software_license_policy.update(classification: SoftwareLicensePolicy.to_classification(params[:approval_status]))
RefreshLicenseComplianceChecksWorker.perform_async(project.id) RefreshLicenseComplianceChecksWorker.perform_async(project.id)
success(software_license_policy: software_license_policy) success(software_license_policy: software_license_policy)
rescue ArgumentError => ex rescue ArgumentError => ex
error(ex.message, 400) error(ex.message, 400)
end end
private
def map_from(approval_status)
SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end end
end end
...@@ -861,10 +861,7 @@ module EE ...@@ -861,10 +861,7 @@ module EE
class ManagedLicense < Grape::Entity class ManagedLicense < Grape::Entity
expose :id, :name expose :id, :name
expose :classification, as: :approval_status do |policy| expose :approval_status
SoftwareLicensePolicy::APPROVAL_STATUS.key(policy.classification) ||
policy.classification
end
end end
class ProjectAlias < Grape::Entity class ProjectAlias < Grape::Entity
......
...@@ -19,6 +19,10 @@ describe LicenseScanningReportLicenseEntity do ...@@ -19,6 +19,10 @@ describe LicenseScanningReportLicenseEntity do
describe '#as_json' do describe '#as_json' do
subject { entity.as_json } subject { entity.as_json }
it 'emits the correct approval_status' do
expect(subject[:classification][:approval_status]).to eq('unclassified')
end
it 'contains the correct dependencies' do it 'contains the correct dependencies' do
expect(subject[:dependencies].count).to eq(2) expect(subject[:dependencies].count).to eq(2)
expect(subject[:dependencies][0][:name]).to eq('Dependency1') expect(subject[:dependencies][0][:name]).to eq('Dependency1')
......
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