Commit 2d4f9496 authored by Thong Kuah's avatar Thong Kuah

Merge branch '10442-add-enum-suffix-to-feedback-type' into 'master'

Resolve "Add enum suffix to Feedback type"

Closes #10442

See merge request gitlab-org/gitlab-ee!13966
parents a81b322e 6237d305
...@@ -14,15 +14,15 @@ module Vulnerabilities ...@@ -14,15 +14,15 @@ module Vulnerabilities
attr_accessor :vulnerability_data attr_accessor :vulnerability_data
enum feedback_type: { dismissal: 0, issue: 1, merge_request: 2 } enum feedback_type: { dismissal: 0, issue: 1, merge_request: 2 }, _prefix: :for
enum category: { sast: 0, dependency_scanning: 1, container_scanning: 2, dast: 3 } enum category: { sast: 0, dependency_scanning: 1, container_scanning: 2, dast: 3 }
validates :project, presence: true validates :project, presence: true
validates :author, presence: true validates :author, presence: true
validates :comment_timestamp, :comment_author, presence: true, if: :comment? validates :comment_timestamp, :comment_author, presence: true, if: :comment?
validates :issue, presence: true, if: :issue? validates :issue, presence: true, if: :for_issue?
validates :merge_request, presence: true, if: :merge_request? validates :merge_request, presence: true, if: :for_merge_request?
validates :vulnerability_data, presence: true, unless: :dismissal? validates :vulnerability_data, presence: true, unless: :for_dismissal?
validates :feedback_type, presence: true validates :feedback_type, presence: true
validates :category, presence: true validates :category, presence: true
validates :project_fingerprint, presence: true, uniqueness: { scope: [:project_id, :category, :feedback_type] } validates :project_fingerprint, presence: true, uniqueness: { scope: [:project_id, :category, :feedback_type] }
......
...@@ -4,9 +4,9 @@ module Vulnerabilities ...@@ -4,9 +4,9 @@ module Vulnerabilities
class FeedbackPolicy < BasePolicy class FeedbackPolicy < BasePolicy
delegate { @subject.project } delegate { @subject.project }
condition(:issue) { @subject.issue? } condition(:issue) { @subject.for_issue? }
condition(:merge_request) { @subject.merge_request? } condition(:merge_request) { @subject.for_merge_request? }
condition(:dismissal) { @subject.dismissal? } condition(:dismissal) { @subject.for_dismissal? }
rule { issue & ~can?(:create_issue) }.prevent :create_vulnerability_feedback rule { issue & ~can?(:create_issue) }.prevent :create_vulnerability_feedback
......
...@@ -7,11 +7,11 @@ module VulnerabilityFeedback ...@@ -7,11 +7,11 @@ module VulnerabilityFeedback
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :create_vulnerability_feedback, vulnerability_feedback) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :create_vulnerability_feedback, vulnerability_feedback)
if vulnerability_feedback.issue? && if vulnerability_feedback.for_issue? &&
!vulnerability_feedback.vulnerability_data.blank? !vulnerability_feedback.vulnerability_data.blank?
create_issue_for(vulnerability_feedback) create_issue_for(vulnerability_feedback)
elsif vulnerability_feedback.merge_request? && elsif vulnerability_feedback.for_merge_request? &&
!vulnerability_feedback.vulnerability_data.blank? !vulnerability_feedback.vulnerability_data.blank?
create_merge_request_for(vulnerability_feedback) create_merge_request_for(vulnerability_feedback)
......
...@@ -3,7 +3,13 @@ ...@@ -3,7 +3,13 @@
require 'spec_helper' require 'spec_helper'
describe Vulnerabilities::Feedback do describe Vulnerabilities::Feedback do
it { is_expected.to define_enum_for(:feedback_type) } it {
is_expected.to(
define_enum_for(:feedback_type)
.with_values(dismissal: 0, issue: 1, merge_request: 2)
.with_prefix(:for)
)
}
it { is_expected.to define_enum_for(:category) } it { is_expected.to define_enum_for(:category) }
describe 'associations' do describe 'associations' do
......
...@@ -50,10 +50,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do ...@@ -50,10 +50,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do
expect(feedback.pipeline_id).to eq(pipeline.id) expect(feedback.pipeline_id).to eq(pipeline.id)
expect(feedback.category).to eq('sast') expect(feedback.category).to eq('sast')
expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8') expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8')
expect(feedback.dismissal?).to eq(true) expect(feedback.for_dismissal?).to eq(true)
expect(feedback.issue?).to eq(false) expect(feedback.for_issue?).to eq(false)
expect(feedback.issue).to be_nil expect(feedback.issue).to be_nil
expect(feedback.merge_request?).to eq(false) expect(feedback.for_merge_request?).to eq(false)
expect(feedback.merge_request).to be_nil expect(feedback.merge_request).to be_nil
end end
...@@ -101,10 +101,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do ...@@ -101,10 +101,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do
expect(feedback.pipeline_id).to eq(pipeline.id) expect(feedback.pipeline_id).to eq(pipeline.id)
expect(feedback.category).to eq('sast') expect(feedback.category).to eq('sast')
expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8') expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8')
expect(feedback.dismissal?).to eq(false) expect(feedback.for_dismissal?).to eq(false)
expect(feedback.issue?).to eq(true) expect(feedback.for_issue?).to eq(true)
expect(feedback.issue).to be_an(Issue) expect(feedback.issue).to be_an(Issue)
expect(feedback.merge_request?).to eq(false) expect(feedback.for_merge_request?).to eq(false)
expect(feedback.merge_request).to be_nil expect(feedback.merge_request).to be_nil
end end
...@@ -176,10 +176,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do ...@@ -176,10 +176,10 @@ describe VulnerabilityFeedback::CreateService, '#execute' do
expect(feedback.pipeline_id).to eq(pipeline.id) expect(feedback.pipeline_id).to eq(pipeline.id)
expect(feedback.category).to eq('dependency_scanning') expect(feedback.category).to eq('dependency_scanning')
expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8') expect(feedback.project_fingerprint).to eq('418291a26024a1445b23fe64de9380cdcdfd1fa8')
expect(feedback.dismissal?).to eq(false) expect(feedback.for_dismissal?).to eq(false)
expect(feedback.issue?).to eq(false) expect(feedback.for_issue?).to eq(false)
expect(feedback.issue).to be_nil expect(feedback.issue).to be_nil
expect(feedback.merge_request?).to eq(true) expect(feedback.for_merge_request?).to eq(true)
expect(feedback.merge_request).to be_an(MergeRequest) expect(feedback.merge_request).to be_an(MergeRequest)
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