Commit 7f22df98 authored by mo khan's avatar mo khan

Rename approved to allowed

* Rename `approved` enum value to `allowed`.
* Update tests to refer to the new value in new code.
* Ensure old value is used in old API endpoints.
parent af69fb12
......@@ -6,6 +6,7 @@
class SoftwareLicensePolicy < ApplicationRecord
include Presentable
APPROVAL_STATUS = {
'approved' => 'allowed',
'blacklisted' => 'denied'
}.freeze
......@@ -18,7 +19,7 @@ class SoftwareLicensePolicy < ApplicationRecord
enum classification: {
denied: 0,
approved: 1
allowed: 1
}
# Software license is mandatory, it contains the license informations.
......
......@@ -20,7 +20,7 @@ module Projects
if denied_classification?
policy.denied!
else
policy.approved!
policy.allowed!
end
RefreshLicenseComplianceChecksWorker.perform_async(project.id)
......
......@@ -159,7 +159,7 @@ describe Projects::Security::LicensesController do
project_id: project,
software_license_policy: {
software_license_id: mit_license.id,
classification: 'approved'
classification: 'allowed'
}
}
end
......@@ -229,7 +229,7 @@ describe Projects::Security::LicensesController do
post :create, xhr: true, params: default_params.merge({
software_license_policy: {
spdx_identifier: mit_license.spdx_identifier,
classification: 'approved'
classification: 'allowed'
}
})
end
......@@ -237,14 +237,14 @@ describe Projects::Security::LicensesController do
it { expect(response).to have_http_status(:created) }
it 'creates a new policy' do
expect(project.reload.software_license_policies.approved.count).to be(1)
expect(project.reload.software_license_policies.approved.last.software_license).to eq(mit_license)
expect(project.reload.software_license_policies.allowed.count).to be(1)
expect(project.reload.software_license_policies.allowed.last.software_license).to eq(mit_license)
end
it 'returns the proper JSON response' do
expect(json[:id]).to be_present
expect(json[:spdx_identifier]).to eq(mit_license.spdx_identifier)
expect(json[:classification]).to eq('approved')
expect(json[:classification]).to eq('allowed')
expect(json[:name]).to eq(mit_license.name)
expect(json[:url]).to be_nil
expect(json[:components]).to be_empty
......@@ -256,7 +256,7 @@ describe Projects::Security::LicensesController do
post :create, xhr: true, params: default_params.merge({
software_license_policy: {
spdx_identifier: nil,
classification: 'approved'
classification: 'allowed'
}
})
end
......@@ -278,7 +278,7 @@ describe Projects::Security::LicensesController do
namespace_id: project.namespace,
project_id: project,
id: software_license_policy.id,
software_license_policy: { classification: "approved" }
software_license_policy: { classification: "allowed" }
}
end
......
......@@ -2,12 +2,12 @@
FactoryBot.define do
factory :software_license_policy, class: SoftwareLicensePolicy do
classification { :approved }
classification { :allowed }
project
software_license
trait :allowed do
classification { :approved }
classification { :allowed }
end
trait :denied do
......
......@@ -108,7 +108,7 @@ RSpec.describe SCA::LicenseCompliance do
expect(subject.policies[2].id).to eq(other_license_policy.id)
expect(subject.policies[2].name).to eq(other_license.name)
expect(subject.policies[2].url).to be_blank
expect(subject.policies[2].classification).to eq("approved")
expect(subject.policies[2].classification).to eq("allowed")
expect(subject.policies[2].spdx_identifier).to eq(other_license.spdx_identifier)
expect(subject.policies[3].id).to be_nil
......@@ -151,7 +151,7 @@ RSpec.describe SCA::LicenseCompliance do
expect(subject.policies[2].id).to eq(other_license_policy.id)
expect(subject.policies[2].name).to eq(other_license.name)
expect(subject.policies[2].url).to be_blank
expect(subject.policies[2].classification).to eq("approved")
expect(subject.policies[2].classification).to eq("allowed")
expect(subject.policies[2].spdx_identifier).to eq(other_license.spdx_identifier)
expect(subject.policies[3].id).to be_nil
......
......@@ -74,7 +74,7 @@ RSpec.describe SCA::LicensePolicy do
context "when a allowed software_policy is provided" do
let(:policy) { build(:software_license_policy, :allowed, software_license: software_license) }
it { expect(subject.classification).to eq("approved") }
it { expect(subject.classification).to eq("allowed") }
end
context "when a denied software_policy is provided" do
......
......@@ -19,10 +19,10 @@ describe SoftwareLicense do
context 'when a software license with a given name has already been created' do
let(:mit_license) { create(:software_license, :mit) }
let(:result) { subject.create_policy_for!(project: project, name: mit_license.name, classification: :approved) }
let(:result) { subject.create_policy_for!(project: project, name: mit_license.name, classification: :allowed) }
specify { expect(result).to be_persisted }
specify { expect(result).to be_approved }
specify { expect(result).to be_allowed }
specify { expect(result.software_license).to eql(mit_license) }
end
......
......@@ -16,7 +16,7 @@ describe ManagedLicenseEntity do
describe "#approval_status" do
where(:classification, :approval_status) do
[
%w[approved approved],
%w[allowed approved],
%w[denied blacklisted]
]
end
......
......@@ -19,7 +19,7 @@ describe Projects::Licenses::CreatePolicyService do
let(:params) do
{
software_license_id: mit_license.id,
classification: 'approved'
classification: 'allowed'
}
end
......@@ -30,7 +30,7 @@ describe Projects::Licenses::CreatePolicyService do
expect(result[:software_license_policy]).to be_present
expect(result[:software_license_policy].id).to be_present
expect(result[:software_license_policy].spdx_identifier).to eq(mit_license.spdx_identifier)
expect(result[:software_license_policy].classification).to eq('approved')
expect(result[:software_license_policy].classification).to eq('allowed')
expect(result[:software_license_policy].name).to eq(mit_license.name)
expect(result[:software_license_policy].url).to be_nil
expect(result[:software_license_policy].dependencies).to be_empty
......
......@@ -20,14 +20,14 @@ describe Projects::Licenses::UpdatePolicyService do
end
context "when updating a policy" do
let(:params) { { classification: "approved" } }
let(:params) { { classification: "allowed" } }
it "updates the policy" do
result = subject.execute(policy.id)
expect(result[:status]).to eq(:success)
expect(result[:software_license_policy]).to be_present
expect(result[:software_license_policy].classification).to eq('approved')
expect(result[:software_license_policy].classification).to eq('allowed')
expect(RefreshLicenseComplianceChecksWorker).to have_received(:perform_async).with(project.id)
end
end
......
......@@ -46,7 +46,7 @@ describe SoftwareLicensePolicies::UpdateService do
update_software_license_policy(opts)
expect(software_license_policy).to be_valid
expect(software_license_policy.classification).to eq(opts[:approval_status])
expect(software_license_policy).to be_allowed
expect(RefreshLicenseComplianceChecksWorker).to have_received(:perform_async).with(project.id)
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