Fix error 500 when sorting issues by milestone due date and filtering by labels
This commit is contained in:
parent
f9bb9151b5
commit
30e61ed79c
4 changed files with 30 additions and 3 deletions
|
@ -10,6 +10,7 @@ v 8.9.0 (unreleased)
|
|||
- Changed the Slack build message to use the singular duration if necessary (Aran Koning)
|
||||
- Fix issues filter when ordering by milestone
|
||||
- Todos will display target state if issuable target is 'Closed' or 'Merged'
|
||||
- Fix bug when sorting issues by milestone due date and filtering by two or more labels
|
||||
- Remove 'main language' feature
|
||||
- Measure queue duration between gitlab-workhorse and Rails
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ class IssuableFinder
|
|||
if filter_by_no_label?
|
||||
items = items.without_label
|
||||
else
|
||||
items = items.with_label(label_names)
|
||||
items = items.with_label(label_names, params[:sort])
|
||||
if projects
|
||||
items = items.where(labels: { project_id: projects })
|
||||
end
|
||||
|
|
|
@ -126,13 +126,30 @@ module Issuable
|
|||
joins(join_clause).group(issuable_table[:id]).reorder("COUNT(notes.id) DESC")
|
||||
end
|
||||
|
||||
def with_label(title)
|
||||
def with_label(title, sort = nil)
|
||||
if title.is_a?(Array) && title.size > 1
|
||||
joins(:labels).where(labels: { title: title }).group(arel_table[:id]).having("COUNT(DISTINCT labels.title) = #{title.size}")
|
||||
joins(:labels).where(labels: { title: title }).group(*get_grouping_columns(sort)).having("COUNT(DISTINCT labels.title) = #{title.size}")
|
||||
else
|
||||
joins(:labels).where(labels: { title: title })
|
||||
end
|
||||
end
|
||||
|
||||
# Includes table keys in group by clause when sorting
|
||||
# preventing errors in postgres
|
||||
#
|
||||
# Returns an array of arel columns
|
||||
|
||||
def get_grouping_columns(sort)
|
||||
default_columns = [arel_table[:id]]
|
||||
|
||||
if ["milestone_due_desc", "milestone_due_asc"].include?(sort)
|
||||
milestone_table = Milestone.arel_table
|
||||
default_columns << milestone_table[:id]
|
||||
default_columns << milestone_table[:due_date]
|
||||
end
|
||||
|
||||
default_columns
|
||||
end
|
||||
end
|
||||
|
||||
def today?
|
||||
|
|
|
@ -131,6 +131,15 @@ describe 'Projects > Merge requests > User lists merge requests', feature: true
|
|||
expect(first_merge_request).to include('fix')
|
||||
expect(count_merge_requests).to eq(1)
|
||||
end
|
||||
|
||||
it 'sorts by recently due milestone' do
|
||||
visit namespace_project_merge_requests_path(project.namespace, project,
|
||||
label_name: [label.name, label2.name],
|
||||
assignee_id: user.id,
|
||||
sort: sort_value_milestone_soon)
|
||||
|
||||
expect(first_merge_request).to include('fix')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue