Commit 35de313a authored by Sean McGivern's avatar Sean McGivern

Merge branch 'issue_40654-ee' into 'master'

Fix board filter when milestone is  predefined

Closes gitlab-ce#40654

See merge request gitlab-org/gitlab-ee!3605
parents 309a5f15 5c7cd4f2
...@@ -88,6 +88,13 @@ class Milestone < ActiveRecord::Base ...@@ -88,6 +88,13 @@ class Milestone < ActiveRecord::Base
else milestones.active else milestones.active
end end
end end
def predefined?(milestone)
milestone == Any ||
milestone == None ||
milestone == Upcoming ||
milestone == Started
end
end end
def self.reference_prefix def self.reference_prefix
......
...@@ -55,14 +55,11 @@ module Boards ...@@ -55,14 +55,11 @@ module Boards
def without_board_labels(issues) def without_board_labels(issues)
return issues unless board_label_ids.any? return issues unless board_label_ids.any?
label_links = LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id") issues.where.not(issues_label_links.limit(1).arel.exists)
.where(label_id: board_label_ids) end
if board.milestone.present?
label_links = label_links.where("issues.milestone_id = ?", board.milestone_id)
end
issues.where.not(label_links.limit(1).arel.exists) def issues_label_links
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id").where(label_id: board_label_ids)
end end
def with_list_label(issues) def with_list_label(issues)
......
---
title: Fix board filter for predefined milestones
merge_request:
author:
type: fixed
...@@ -9,6 +9,24 @@ module EE ...@@ -9,6 +9,24 @@ module EE
super super
end end
end end
def issues_label_links
if has_valid_milestone?
super.where("issues.milestone_id = ?", board.milestone_id)
else
super
end
end
private
# Prevent filtering by milestone stubs
# like Milestone::Upcoming, Milestone::Started etc
def has_valid_milestone?
return false unless board.milestone
!::Milestone.predefined?(board.milestone)
end
end end
end end
end end
......
...@@ -71,6 +71,34 @@ describe Boards::Issues::ListService, services: true do ...@@ -71,6 +71,34 @@ describe Boards::Issues::ListService, services: true do
expect(issues).to match_array([opened_issue2, list1_issue2, reopened_issue1, opened_issue1]) expect(issues).to match_array([opened_issue2, list1_issue2, reopened_issue1, opened_issue1])
end end
context 'when milestone is predefined' do
let(:params) { { board_id: board.id, id: backlog.id } }
context 'as upcoming' do
before do
board.update(milestone_id: Milestone::Upcoming.id)
end
it 'returns open issue for backlog without board label' do
issues = described_class.new(group, user, params).execute
expect(issues).to match_array([opened_issue2, reopened_issue1, opened_issue1])
end
end
context 'as started' do
before do
board.update(milestone_id: Milestone::Started.id)
end
it 'returns open issue for backlog without board label' do
issues = described_class.new(group, user, params).execute
expect(issues).to match_array([opened_issue2, reopened_issue1, opened_issue1])
end
end
end
end end
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