Commit 345bddd1 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '249245-fix-sorting-vulnerabilities-by-report-type' into 'master'

Fix problem with sorting in GraphQL by case expression

See merge request gitlab-org/gitlab!44132
parents 8d2ba695 5a4ac5f6
...@@ -103,8 +103,8 @@ module EE ...@@ -103,8 +103,8 @@ module EE
scope :order_title_desc, -> { reorder(title: :desc, id: :desc) } scope :order_title_desc, -> { reorder(title: :desc, id: :desc) }
scope :order_created_at_asc, -> { reorder(created_at: :asc, id: :desc) } scope :order_created_at_asc, -> { reorder(created_at: :asc, id: :desc) }
scope :order_created_at_desc, -> { reorder(created_at: :desc, id: :desc) } scope :order_created_at_desc, -> { reorder(created_at: :desc, id: :desc) }
scope :order_report_type_asc, -> { reorder(report_type_order.asc, id: :desc) } scope :order_report_type_asc, -> { select(*arel.projections, report_type_order.as('case_order_value')).reorder(report_type_order.asc, id: :desc) }
scope :order_report_type_desc, -> { reorder(report_type_order.desc, id: :desc) } scope :order_report_type_desc, -> { select(*arel.projections, report_type_order.as('case_order_value')).reorder(report_type_order.desc, id: :desc) }
scope :order_id_desc, -> { reorder(id: :desc) } scope :order_id_desc, -> { reorder(id: :desc) }
scope :with_limit, -> (maximum) { limit(maximum) } scope :with_limit, -> (maximum) { limit(maximum) }
......
...@@ -95,7 +95,7 @@ module Gitlab ...@@ -95,7 +95,7 @@ module Gitlab
elsif ordering_by_similarity?(order_value) elsif ordering_by_similarity?(order_value)
['similarity', order_value.direction, order_value.expr] ['similarity', order_value.direction, order_value.expr]
elsif ordering_by_case?(order_value) elsif ordering_by_case?(order_value)
[order_value.expr.case.name.to_s, order_value.direction, order_value.expr] ['case_order_value', order_value.direction, order_value.expr]
else else
[order_value.expr.name, order_value.direction, nil] [order_value.expr.name, order_value.direction, nil]
end end
......
...@@ -69,7 +69,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do ...@@ -69,7 +69,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do
it 'assigns the right attribute name, named function, and direction' do it 'assigns the right attribute name, named function, and direction' do
expect(order_list.count).to eq 1 expect(order_list.count).to eq 1
expect(order_list.first.attribute_name).to eq 'pending_delete' expect(order_list.first.attribute_name).to eq 'case_order_value'
expect(order_list.first.named_function).to be_kind_of(Arel::Nodes::Case) expect(order_list.first.named_function).to be_kind_of(Arel::Nodes::Case)
expect(order_list.first.sort_direction).to eq :asc expect(order_list.first.sort_direction).to eq :asc
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