Commit fe7f0a8a authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'remove-blocked-by-code' into 'master'

Remove blocked_by code

See merge request gitlab-org/gitlab!52675
parents 8632edaa 7e96d71f
......@@ -17,9 +17,11 @@ class IssueLink < ApplicationRecord
TYPE_RELATES_TO = 'relates_to'
TYPE_BLOCKS = 'blocks'
# we don't store is_blocked_by in the db but need it for displaying the relation
# from the target (used in IssueLink.inverse_link_type)
TYPE_IS_BLOCKED_BY = 'is_blocked_by'
enum link_type: { TYPE_RELATES_TO => 0, TYPE_BLOCKS => 1, TYPE_IS_BLOCKED_BY => 2 }
enum link_type: { TYPE_RELATES_TO => 0, TYPE_BLOCKS => 1 }
def self.inverse_link_type(type)
type
......
......@@ -11,14 +11,9 @@ module EE
class_methods do
def inverse_link_type(type)
case type
when ::IssueLink::TYPE_BLOCKS
::IssueLink::TYPE_IS_BLOCKED_BY
when ::IssueLink::TYPE_IS_BLOCKED_BY
::IssueLink::TYPE_BLOCKS
else
type
end
return ::IssueLink::TYPE_IS_BLOCKED_BY if type == ::IssueLink::TYPE_BLOCKS
type
end
def blocked_issue_ids(issue_ids)
......
......@@ -16,19 +16,17 @@ module EE
def set_link_type(link)
return unless params[:link_type].present?
link.link_type = params[:link_type]
# `blocked_by` links are treated as `blocks` links where
# source and target is swapped. This is the first step toward
# removing `blocked_by` link type
# https://gitlab.com/gitlab-org/gitlab/-/issues/225919
if link.is_blocked_by?
# `blocked_by` links are treated as `blocks` links where source and target is swapped.
if params[:link_type] == ::IssueLink::TYPE_IS_BLOCKED_BY
link.source, link.target = link.target, link.source
link.link_type = ::IssueLink::TYPE_BLOCKS
else
link.link_type = params[:link_type]
end
end
def link_type_available?
# `blocked_by` is allowed as a param and handled in set_link_type
return true unless [::IssueLink::TYPE_BLOCKS, ::IssueLink::TYPE_IS_BLOCKED_BY].include?(params[:link_type])
issuable.resource_parent.feature_available?(:blocked_issues)
......
......@@ -10,7 +10,7 @@ RSpec.describe Projects::IssueLinksController do
let_it_be(:issue2) { create(:issue, project: project) }
describe 'GET #index' do
let_it_be(:issue_link) { create(:issue_link, source: issue1, target: issue2, link_type: 'is_blocked_by') }
let_it_be(:issue_link) { create(:issue_link, source: issue1, target: issue2, link_type: 'blocks') }
def get_link(user, issue)
sign_in(user)
......@@ -35,7 +35,7 @@ RSpec.describe Projects::IssueLinksController do
link = json_response.first
expect(link['id']).to eq(issue2.id)
expect(link['link_type']).to eq('is_blocked_by')
expect(link['link_type']).to eq('blocks')
end
end
......
......@@ -81,7 +81,6 @@ RSpec.describe IssueLink do
it 'returns reverse type of link' do
expect(described_class.inverse_link_type('relates_to')).to eq 'relates_to'
expect(described_class.inverse_link_type('blocks')).to eq 'is_blocked_by'
expect(described_class.inverse_link_type('is_blocked_by')).to eq 'blocks'
end
end
......
......@@ -696,9 +696,8 @@ RSpec.describe Issue do
where(:id, :issue_link_source_id, :issue_link_type_value, :expected) do
1 | 1 | 0 | 'relates_to'
1 | 1 | 1 | 'blocks'
1 | 2 | 3 | 'relates_to'
1 | 2 | 2 | 'relates_to'
1 | 2 | 1 | 'is_blocked_by'
1 | 2 | 2 | 'blocks'
end
with_them do
......
......@@ -9,7 +9,7 @@ RSpec.describe IssueLink do
end
describe 'link_type' do
it { is_expected.to define_enum_for(:link_type).with_values(relates_to: 0, blocks: 1, is_blocked_by: 2) }
it { is_expected.to define_enum_for(:link_type).with_values(relates_to: 0, blocks: 1) }
it 'provides the "related" as default link_type' do
expect(create(:issue_link).link_type).to eq 'relates_to'
......
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