Commit 11fdd444 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Remove dismissal info fallback methods from the `Vulnerability` model

parent 50ea91ee
......@@ -139,19 +139,6 @@ module EE
findings.first
end
# TODO: Remove this attribute reader overrides with #262112
def dismissed_at
return unless dismissed?
super || fallback_dismissal_feedback&.created_at
end
def dismissed_by_id
return unless dismissed?
super || fallback_dismissal_feedback&.author_id
end
def resource_parent
project
end
......@@ -179,15 +166,6 @@ module EE
def user_notes_count_service
@user_notes_count_service ||= ::Vulnerabilities::UserNotesCountService.new(self) # rubocop: disable CodeReuse/ServiceClass
end
# TODO: Remove this with #262112
def fallback_dismissal_feedback
strong_memoize(:fallback_dismissal_feedback) do
::Gitlab::AppJsonLogger.warn(message: 'Fallback dismissal_feedback has been called!', vulnerability_id: id)
finding&.dismissal_feedback
end
end
end
class_methods do
......
......@@ -674,138 +674,6 @@ RSpec.describe Vulnerability do
end
end
describe '#dismissed_at' do
let_it_be(:project) { create(:project) }
let_it_be(:finding) do
create(
:vulnerabilities_finding,
report_type: :dependency_scanning,
project: project
)
end
let(:vulnerability) { create(:vulnerability, findings: [finding]) }
let(:feedback_created_at) { -2.days.from_now }
let!(:dismissal_feedback) do
create(
:vulnerability_feedback,
:dependency_scanning,
:dismissal,
project: project,
project_fingerprint: finding.project_fingerprint,
created_at: feedback_created_at
)
end
subject(:dismissed_at) { vulnerability.dismissed_at }
around do |example|
freeze_time { example.run }
end
context 'when the vulnerability is not dismissed' do
before do
vulnerability.update_attribute(:dismissed_at, Time.current)
end
it { is_expected.to be_nil }
end
context 'when the vulnerability is dismissed' do
before do
vulnerability.dismissed!
end
context 'when the `dismissed_at` exists' do
let(:vulnerability_dismissed_at) { -1.day.from_now }
before do
vulnerability.update_attribute(:dismissed_at, vulnerability_dismissed_at)
end
it { is_expected.to eq(vulnerability_dismissed_at) }
end
context 'when the `dismissed_at` does not exist' do
before do
allow(::Gitlab::AppJsonLogger).to receive(:warn)
end
it { is_expected.to eq(feedback_created_at) }
it 'puts a warning log' do
dismissed_at
expect(::Gitlab::AppJsonLogger).to have_received(:warn)
end
end
end
end
describe '#dismissed_by_id' do
let_it_be(:user_1) { create(:user) }
let_it_be(:user_2) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:occurrence) do
create(
:vulnerabilities_finding,
report_type: :dependency_scanning,
project: project
)
end
let_it_be(:dismissal_feedback) do
create(
:vulnerability_feedback,
:dependency_scanning,
:dismissal,
project: project,
project_fingerprint: occurrence.project_fingerprint,
author: user_1
)
end
let(:vulnerability) { create(:vulnerability, findings: [occurrence]) }
subject(:dismissed_by_id) { vulnerability.dismissed_by_id }
context 'when the vulnerability is not dismissed' do
before do
vulnerability.update_attribute(:dismissed_by_id, user_1.id)
end
it { is_expected.to be_nil }
end
context 'when the vulnerability is dismissed' do
before do
vulnerability.dismissed!
end
context 'when the `dismissed_by_id` exists' do
before do
vulnerability.update_attribute(:dismissed_by_id, user_2.id)
end
it { is_expected.to eq(user_2.id) }
end
context 'when the `dismissed_by_id` does not exist' do
before do
allow(::Gitlab::AppJsonLogger).to receive(:warn)
end
it { is_expected.to eq(user_1.id) }
it 'puts a warning log' do
dismissed_by_id
expect(::Gitlab::AppJsonLogger).to have_received(:warn)
end
end
end
end
describe '#user_notes_count' do
let_it_be(:vulnerability) { create(:vulnerability) }
......
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