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
delegate :name, :spdx_identifier, to: :software_license
def approval_status
APPROVAL_STATUS.key(classification) || classification
end
def self.workaround_cache_key
pluck(:id, :classification).flatten
end
def self.to_classification(approval_status)
APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end
......@@ -10,7 +10,7 @@ class LicenseScanningReportLicenseEntity < Grape::Entity
expose :url
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
ManagedLicenseEntity.represent(found || default)
end
......
......@@ -2,10 +2,7 @@
class ManagedLicenseEntity < Grape::Entity
expose :id
expose :classification, as: :approval_status do |policy|
classification = policy[:classification]
SoftwareLicensePolicy::APPROVAL_STATUS.key(classification) || classification
end
expose :approval_status
expose :software_license, merge: true do
expose :name
end
......
......@@ -24,14 +24,10 @@ module SoftwareLicensePolicies
policy = SoftwareLicense.create_policy_for!(
project: project,
name: params[:name],
classification: map_from(params[:approval_status])
classification: SoftwareLicensePolicy.to_classification(params[:approval_status])
)
RefreshLicenseComplianceChecksWorker.perform_async(project.id)
policy
end
def map_from(approval_status)
SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end
end
......@@ -11,17 +11,11 @@ module SoftwareLicensePolicies
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?
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)
success(software_license_policy: software_license_policy)
rescue ArgumentError => ex
error(ex.message, 400)
end
private
def map_from(approval_status)
SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
end
end
end
......@@ -861,10 +861,7 @@ module EE
class ManagedLicense < Grape::Entity
expose :id, :name
expose :classification, as: :approval_status do |policy|
SoftwareLicensePolicy::APPROVAL_STATUS.key(policy.classification) ||
policy.classification
end
expose :approval_status
end
class ProjectAlias < Grape::Entity
......
......@@ -19,6 +19,10 @@ describe LicenseScanningReportLicenseEntity do
describe '#as_json' do
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
expect(subject[:dependencies].count).to eq(2)
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