Commit aa840cc8 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '249245-add-sorting-vulnerabilities-by-title' into 'master'

Add ability to sort vulnerabilities by title

See merge request gitlab-org/gitlab!42953
parents acd51e80 9ea6756c
......@@ -19478,6 +19478,16 @@ enum VulnerabilitySort {
Severity in descending order
"""
severity_desc
"""
Title in ascending order
"""
title_asc
"""
Title in descending order
"""
title_desc
}
"""
......
......@@ -56960,6 +56960,18 @@
"description": "Severity in ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "title_desc",
"description": "Title in descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "title_asc",
"description": "Title in ascending order",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
......@@ -3592,6 +3592,8 @@ Vulnerability sort values.
| ----- | ----------- |
| `severity_asc` | Severity in ascending order |
| `severity_desc` | Severity in descending order |
| `title_asc` | Title in ascending order |
| `title_desc` | Title in descending order |
### VulnerabilityState
......
......@@ -7,5 +7,7 @@ module Types
value 'severity_desc', 'Severity in descending order'
value 'severity_asc', 'Severity in ascending order'
value 'title_desc', 'Title in descending order'
value 'title_asc', 'Title in ascending order'
end
end
......@@ -88,6 +88,8 @@ module EE
scope :order_severity_asc, -> { reorder(severity: :asc, id: :desc) }
scope :order_severity_desc, -> { reorder(severity: :desc, id: :desc) }
scope :order_title_asc, -> { reorder(title: :asc, id: :desc) }
scope :order_title_desc, -> { reorder(title: :desc, id: :desc) }
delegate :scanner_name, :scanner_external_id, :metadata, :message, :cve, :description,
to: :finding, prefix: true, allow_nil: true
......@@ -190,6 +192,8 @@ module EE
case method.to_s
when 'severity_desc' then order_severity_desc
when 'severity_asc' then order_severity_asc
when 'title_desc' then order_title_desc
when 'title_asc' then order_title_asc
else
order_severity_desc
end
......
---
title: Add ability to sort vulnerabilities by title in GraphQL
merge_request: 42953
author:
type: added
......@@ -6,6 +6,6 @@ RSpec.describe GitlabSchema.types['VulnerabilitySort'] do
it { expect(described_class.graphql_name).to eq('VulnerabilitySort') }
it 'exposes all the existing Vulnerability sort orders' do
expect(described_class.values.keys).to include(*%w[severity_desc severity_asc])
expect(described_class.values.keys).to include(*%w[severity_desc severity_asc title_desc title_asc])
end
end
......@@ -181,6 +181,28 @@ RSpec.describe Vulnerability do
end
end
describe '.order_title_' do
let_it_be(:vulnerability_b) { create(:vulnerability, title: 'B Vulnerability') }
let_it_be(:vulnerability_a) { create(:vulnerability, title: 'A Vulnerability') }
let_it_be(:vulnerability_c) { create(:vulnerability, title: 'C Vulnerability') }
describe 'asc' do
subject { described_class.order_title_asc }
it 'returns vulnerabilities ordered by title' do
is_expected.to eq([vulnerability_a, vulnerability_b, vulnerability_c])
end
end
describe 'desc' do
subject { described_class.order_title_desc }
it 'returns vulnerabilities ordered by title' do
is_expected.to eq([vulnerability_c, vulnerability_b, vulnerability_a])
end
end
end
describe '.with_resolution' do
let_it_be(:vulnerability_with_resolution) { create(:vulnerability, resolved_on_default_branch: true) }
let_it_be(:vulnerability_without_resolution) { create(:vulnerability, resolved_on_default_branch: false) }
......
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