Skip to content
代码片段 群组 项目
未验证 提交 6f5d7f6b 编辑于 作者: Jan Provaznik's avatar Jan Provaznik 提交者: GitLab
浏览文件

Merge branch 'mc_rocha-remove-unused-software-license-code' into 'master'

Remove unused code related to software license

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/144684



Merged-by: default avatarJan Provaznik <jprovaznik@gitlab.com>
Approved-by: default avatarAndy Soiron <asoiron@gitlab.com>
Approved-by: default avatarJan Provaznik <jprovaznik@gitlab.com>
Co-authored-by: default avatarmc_rocha <mrocha@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -42,7 +42,6 @@ class SoftwareLicensePolicy < ApplicationRecord ...@@ -42,7 +42,6 @@ class SoftwareLicensePolicy < ApplicationRecord
scope :including_scan_result_policy_read, -> { includes(:scan_result_policy_read) } scope :including_scan_result_policy_read, -> { includes(:scan_result_policy_read) }
scope :unreachable_limit, -> { limit(1_000) } scope :unreachable_limit, -> { limit(1_000) }
scope :with_scan_result_policy_read, -> { where.not(scan_result_policy_id: nil) } scope :with_scan_result_policy_read, -> { where.not(scan_result_policy_id: nil) }
scope :count_for_software_license, ->(software_license_id) { where(software_license_id: software_license_id).count }
scope :exclusion_allowed, -> do scope :exclusion_allowed, -> do
joins(:scan_result_policy_read) joins(:scan_result_policy_read)
......
# frozen_string_literal: true
module SoftwareLicensePolicies
class DeleteService < ::BaseService
def execute(software_license_policy)
SoftwareLicensePolicy.transaction do
software_license = SoftwareLicense.find(software_license_policy.software_license_id)
software_license_policy.destroy!
if software_license.spdx_identifier.nil? &&
SoftwareLicensePolicy.count_for_software_license(software_license.id) == 0
software_license.destroy!
end
end
end
end
end
...@@ -45,14 +45,6 @@ ...@@ -45,14 +45,6 @@
it { expect(described_class.by_spdx(SecureRandom.uuid)).to be_empty } it { expect(described_class.by_spdx(SecureRandom.uuid)).to be_empty }
end end
describe '.count_for_software_license' do
let!(:mit) { create(:software_license, :mit) }
let!(:mit_policy1) { create(:software_license_policy, software_license: mit) }
let!(:mit_policy2) { create(:software_license_policy, software_license: mit) }
it { expect(described_class.count_for_software_license(mit.id)).to eq(2) }
end
describe '.exclusion_allowed' do describe '.exclusion_allowed' do
let_it_be(:mit) { create(:software_license, :mit) } let_it_be(:mit) { create(:software_license, :mit) }
let_it_be(:scan_result_policy_read_with_inclusion) { create(:scan_result_policy_read, match_on_inclusion_license: true) } let_it_be(:scan_result_policy_read_with_inclusion) { create(:scan_result_policy_read, match_on_inclusion_license: true) }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe SoftwareLicensePolicies::DeleteService, feature_category: :security_policy_management do
subject(:service) { described_class.new(project, user) }
let_it_be(:project) { create(:project) }
let(:user) do
create(:user).tap do |u|
project.add_maintainer(u)
end
end
let(:software_license) { create(:software_license) }
let(:software_license_policy) { create(:software_license_policy, :denied, software_license: software_license) }
describe '#execute' do
context 'when software_license has one software_license_policy' do
it 'deletes software_license_policy and software_license' do
service.execute(software_license_policy)
expect { software_license_policy.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { software_license.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'when software_license has spdx_identifier' do
let(:software_license) { create(:software_license, :mit) }
it 'deletes software_license_policy only' do
service.execute(software_license_policy)
expect { software_license_policy.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { software_license.reload }.not_to raise_error
end
end
context 'when software_license has multiple software_license_policies' do
before do
create(:software_license_policy, software_license: software_license)
end
it 'deletes software_license_policy only' do
service.execute(software_license_policy)
expect { software_license_policy.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { software_license.reload }.not_to raise_error
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册