Commit d8e1cfcf authored by Nick Thomas's avatar Nick Thomas

Merge branch '207087-blocked-status-issue' into 'master'

Fix displaying blocked issues on the board

See merge request gitlab-org/gitlab!25817
parents b191b3aa 415dbc24
---
title: Don't show issue as blocked on the issue board if blocking issue is closed
merge_request: 25817
author:
type: fixed
...@@ -33,13 +33,28 @@ class IssueLink < ApplicationRecord ...@@ -33,13 +33,28 @@ class IssueLink < ApplicationRecord
def self.blocked_issue_ids(issue_ids) def self.blocked_issue_ids(issue_ids)
from_union([ from_union([
IssueLink.select('target_id as issue_id').where(link_type: IssueLink::TYPE_BLOCKS).where(target_id: issue_ids), blocked_issues(issue_ids, IssueLink::TYPE_BLOCKS),
IssueLink.select('source_id as issue_id').where(link_type: IssueLink::TYPE_IS_BLOCKED_BY).where(source_id: issue_ids) blocked_issues(issue_ids, IssueLink::TYPE_IS_BLOCKED_BY)
]).pluck(:issue_id) ]).pluck(:issue_id)
end end
private private
def self.blocked_issues(issue_ids, link_type)
if link_type == IssueLink::TYPE_BLOCKS
blocked_key = :target_id
blocking_key = :source_id
else
blocked_key = :source_id
blocking_key = :target_id
end
select("#{blocked_key} as issue_id")
.where(link_type: link_type).where(blocked_key => issue_ids)
.joins("INNER JOIN issues ON issues.id = issue_links.#{blocking_key}")
.where('issues.state_id' => Issuable::STATE_ID_MAP[:opened])
end
def check_self_relation def check_self_relation
return unless source && target return unless source && target
......
...@@ -50,21 +50,26 @@ describe Boards::IssuesController do ...@@ -50,21 +50,26 @@ describe Boards::IssuesController do
expect(development.issues.map(&:relative_position)).not_to include(nil) expect(development.issues.map(&:relative_position)).not_to include(nil)
end end
it 'returns blocked status for each issue' do it 'returns blocked status for each issue where the blocking issue is still opened' do
issue1 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 1) issue1 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 1)
issue2 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 2) issue2 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 2)
issue3 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 3) issue3 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 3)
issue4 = create(:labeled_issue, project: project_1, labels: [development], relative_position: 4)
closed_issue = create(:issue, :closed, project: project_1)
create(:issue_link, source: issue1, target: issue2, link_type: IssueLink::TYPE_IS_BLOCKED_BY) create(:issue_link, source: issue1, target: issue2, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
create(:issue_link, source: issue2, target: issue3, link_type: IssueLink::TYPE_BLOCKS) create(:issue_link, source: issue2, target: issue3, link_type: IssueLink::TYPE_BLOCKS)
create(:issue_link, source: issue4, target: closed_issue, link_type: IssueLink::TYPE_IS_BLOCKED_BY)
list_issues user: user, board: board, list: list2 list_issues user: user, board: board, list: list2
expect(response).to match_response_schema('entities/issue_boards') expect(response).to match_response_schema('entities/issue_boards')
issues = json_response['issues'] issues = json_response['issues']
expect(issues.length).to eq 3 expect(issues.length).to eq 4
expect(issues[0]['blocked']).to be_truthy expect(issues[0]['blocked']).to be_truthy
expect(issues[1]['blocked']).to be_falsey expect(issues[1]['blocked']).to be_falsey
expect(issues[2]['blocked']).to be_truthy expect(issues[2]['blocked']).to be_truthy
expect(issues[3]['blocked']).to be_falsey
end end
context 'with search param' do context 'with search param' do
......
...@@ -56,8 +56,9 @@ describe IssueLink do ...@@ -56,8 +56,9 @@ describe IssueLink do
link1 = create(:issue_link, link_type: described_class::TYPE_BLOCKS) link1 = create(:issue_link, link_type: described_class::TYPE_BLOCKS)
link2 = create(:issue_link, link_type: described_class::TYPE_IS_BLOCKED_BY) link2 = create(:issue_link, link_type: described_class::TYPE_IS_BLOCKED_BY)
link3 = create(:issue_link, link_type: described_class::TYPE_RELATES_TO) link3 = create(:issue_link, link_type: described_class::TYPE_RELATES_TO)
link4 = create(:issue_link, source: create(:issue, :closed), link_type: described_class::TYPE_BLOCKS)
expect(described_class.blocked_issue_ids([link1.target_id, link2.source_id, link3.source_id])) expect(described_class.blocked_issue_ids([link1.target_id, link2.source_id, link3.source_id, link4.target_id]))
.to match_array([link1.target_id, link2.source_id]) .to match_array([link1.target_id, link2.source_id])
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