Commit 9d341f0d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '216160-fix-label-any-with-custom-sorting' into 'master'

Fix any label filter with custom sorting

Closes #216160

See merge request gitlab-org/gitlab!31729
parents 051c4be4 e53304b4
......@@ -451,7 +451,7 @@ class IssuableFinder
if params.filter_by_no_label?
items.without_label
elsif params.filter_by_any_label?
items.any_label
items.any_label(params[:sort])
else
items.with_label(params.label_names, params[:sort])
end
......
......@@ -139,7 +139,6 @@ module Issuable
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :with_label_ids, ->(label_ids) { joins(:label_links).where(label_links: { label_id: label_ids }) }
scope :any_label, -> { joins(:label_links).distinct }
scope :join_project, -> { joins(:project) }
scope :inc_notes_with_associations, -> { includes(notes: [:project, :author, :award_emoji]) }
scope :references_project, -> { references(:project) }
......@@ -316,6 +315,14 @@ module Issuable
end
end
def any_label(sort = nil)
if sort
joins(:label_links).group(*grouping_columns(sort))
else
joins(:label_links).distinct
end
end
# Includes table keys in group by clause when sorting
# preventing errors in postgres
#
......
---
title: Fix issuable listings with any label filter
merge_request: 31729
author:
type: fixed
......@@ -64,6 +64,16 @@ describe API::Analytics::CodeReviewAnalytics do
expect(json_response.map { |mr| mr['id'] }).to match_array([merge_request_1.id])
end
end
context 'with any label filter present' do
let(:query_params) { super().merge(label_name: ['Any']) }
it 'applies filter' do
api_call
expect(json_response.map { |mr| mr['id'] }).to match_array([merge_request_2.id, merge_request_3.id])
end
end
end
context 'when user has no authorization' do
......
......@@ -102,6 +102,22 @@ describe Issuable do
end
end
describe '.any_label' do
let_it_be(:issue_with_label) { create(:labeled_issue, labels: [create(:label)]) }
let_it_be(:issue_with_multiple_labels) { create(:labeled_issue, labels: [create(:label), create(:label)]) }
let_it_be(:issue_without_label) { create(:issue) }
it 'returns an issuable with at least one label' do
expect(issuable_class.any_label).to match_array([issue_with_label, issue_with_multiple_labels])
end
context 'for custom sorting' do
it 'returns an issuable with at least one label' do
expect(issuable_class.any_label('created_at')).to eq([issue_with_label, issue_with_multiple_labels])
end
end
end
describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable awesome issue") }
let!(:searchable_issue2) { create(:issue, title: 'Aw') }
......
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