Commit e0cee830 authored by Thong Kuah's avatar Thong Kuah

Merge branch '38278-rename-approved-to-allowed' into 'master'

Rename `approved` to `allowed`

See merge request gitlab-org/gitlab!21282
parents 64b2b165 8bb13507
......@@ -5,7 +5,9 @@
# For use in the License Management feature.
class SoftwareLicensePolicy < ApplicationRecord
include Presentable
APPROVAL_STATUS = {
# Mapping from old classification names to new names
LEGACY_CLASSIFICATION_STATUS = {
'approved' => 'allowed',
'blacklisted' => 'denied'
}.freeze
......@@ -18,7 +20,7 @@ class SoftwareLicensePolicy < ApplicationRecord
enum classification: {
denied: 0,
approved: 1
allowed: 1
}
# Software license is mandatory, it contains the license informations.
......@@ -48,7 +50,7 @@ class SoftwareLicensePolicy < ApplicationRecord
delegate :name, :spdx_identifier, to: :software_license
def approval_status
APPROVAL_STATUS.key(classification) || classification
LEGACY_CLASSIFICATION_STATUS.key(classification) || classification
end
def self.workaround_cache_key
......@@ -56,6 +58,6 @@ class SoftwareLicensePolicy < ApplicationRecord
end
def self.to_classification(approval_status)
APPROVAL_STATUS.fetch(approval_status, approval_status)
LEGACY_CLASSIFICATION_STATUS.fetch(approval_status, approval_status)
end
end
......@@ -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
......
......@@ -48,4 +48,34 @@ describe SoftwareLicensePolicy do
describe "#name" do
specify { expect(subject.name).to eql(subject.software_license.name) }
end
describe "#approval_status" do
where(:classification, :approval_status) do
[
%w[allowed approved],
%w[denied blacklisted]
]
end
with_them do
subject { build(:software_license_policy, classification: classification) }
it { expect(subject.approval_status).to eql(approval_status) }
end
end
describe ".to_classification" do
where(:approval_status, :classification) do
[
%w[approved allowed],
%w[blacklisted denied]
]
end
with_them do
subject { described_class.to_classification(approval_status) }
it { expect(subject).to eql(classification) }
end
end
end
......@@ -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
......
......@@ -33,7 +33,8 @@ describe SoftwareLicensePolicies::CreateService do
context 'when valid parameters are specified' do
where(:approval_status, :expected_classification) do
[
%w[approved approved],
%w[allowed allowed],
%w[approved allowed],
%w[denied denied],
%w[blacklisted denied]
]
......
......@@ -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