Commit dcce63fc authored by mo khan's avatar mo khan Committed by Ash McKenzie

Extract hash to map to legacy values

parent 0146f8ef
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
# For use in the License Management feature. # For use in the License Management feature.
class SoftwareLicensePolicy < ApplicationRecord class SoftwareLicensePolicy < ApplicationRecord
include Presentable include Presentable
APPROVAL_STATUS = {
'blacklisted' => 'denied'
}.freeze
# Only allows modification of the approval status # Only allows modification of the approval status
FORM_EDITABLE = %i[approval_status].freeze FORM_EDITABLE = %i[approval_status].freeze
......
...@@ -21,22 +21,15 @@ module SoftwareLicensePolicies ...@@ -21,22 +21,15 @@ module SoftwareLicensePolicies
private private
def create_software_license_policy def create_software_license_policy
approval_status = params[:approval_status]
classification = SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
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: classification
) )
RefreshLicenseComplianceChecksWorker.perform_async(project.id) RefreshLicenseComplianceChecksWorker.perform_async(project.id)
policy policy
end end
def map_from(approval_status)
case approval_status
when 'blacklisted'
'denied'
else
approval_status
end
end
end end
end end
...@@ -12,7 +12,9 @@ module SoftwareLicensePolicies ...@@ -12,7 +12,9 @@ module SoftwareLicensePolicies
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?
begin begin
software_license_policy.update(classification: map_from(params[:approval_status])) approval_status = params[:approval_status]
classification = SoftwareLicensePolicy::APPROVAL_STATUS.fetch(approval_status, approval_status)
software_license_policy.update(classification: classification)
RefreshLicenseComplianceChecksWorker.perform_async(project.id) RefreshLicenseComplianceChecksWorker.perform_async(project.id)
rescue ArgumentError => ex rescue ArgumentError => ex
return error(ex.message, 400) return error(ex.message, 400)
...@@ -20,16 +22,5 @@ module SoftwareLicensePolicies ...@@ -20,16 +22,5 @@ module SoftwareLicensePolicies
success(software_license_policy: software_license_policy) success(software_license_policy: software_license_policy)
end end
private
def map_from(approval_status)
case approval_status
when 'blacklisted'
'denied'
else
approval_status
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