Commit 0ceea035 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'issue_220310_expose_blocked_attribute' into 'master'

Expose 'blocked' attribute on epic issues endpoint

See merge request gitlab-org/gitlab!73308
parents 8918cc05 036e9852
......@@ -12,11 +12,16 @@ module IssuableLinks
end
def execute
serializer.new(current_user: current_user, issuable: issuable).represent(child_issuables)
serializer.new(current_user: current_user, issuable: issuable)
.represent(child_issuables, serializer_options)
end
private
def serializer_options
{}
end
def serializer
raise NotImplementedError
end
......
......@@ -15,6 +15,12 @@ class LinkedEpicIssueEntity < LinkedIssueEntity
expose :epic_issue_id
with_options if: -> (_, options) { options[:blocked_issues_ids] } do
expose :blocked do |issue, options|
options[:blocked_issues_ids].include?(issue.id)
end
end
private
def can_admin_issue_link?(issue)
......
......@@ -3,18 +3,30 @@
module EpicIssues
class ListService < IssuableLinks::ListService
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
def child_issuables
return [] unless issuable&.group&.feature_available?(:epics)
strong_memoize(:child_issuables) do
next [] unless issuable&.group&.feature_available?(:epics)
issuable.issues_readable_by(current_user, preload: preload_for_collection)
issuable.issues_readable_by(current_user, preload: preload_for_collection)
end
end
override :serializer
def serializer
LinkedEpicIssueSerializer
end
override :serializer_options
def serializer_options
child_issues_ids = child_issuables.map(&:id)
blocked_issues_ids = ::IssueLink.blocked_issue_ids(child_issues_ids)
super.merge(blocked_issues_ids: blocked_issues_ids)
end
end
end
......@@ -36,6 +36,10 @@ RSpec.describe EpicIssues::ListService do
stub_licensed_features(epics: true)
end
before_all do
create(:issue_link, source: create(:issue), target: issue1, link_type: IssueLink::TYPE_BLOCKS)
end
it 'does not have N+1 queries', :use_clean_rails_memory_store_caching, :request_store do
# The control query is made with the worst case scenario:
# * Two different issues from two different projects that belong to two different groups
......@@ -61,6 +65,7 @@ RSpec.describe EpicIssues::ListService do
milestone3 = create(:milestone, project: new_project)
new_issue4 = create(:issue, project: new_project, milestone: milestone3)
create(:epic_issue, issue: new_issue4, epic: epic, relative_position: 6)
create(:issue_link, source: create(:issue), target: issue2, link_type: IssueLink::TYPE_BLOCKS)
expect { list_service.execute }.not_to exceed_query_limit(control_count)
end
......@@ -86,7 +91,8 @@ RSpec.describe EpicIssues::ListService do
epic_issue_id: epic_issue2.id,
due_date: nil,
created_at: issue2.created_at,
closed_at: issue2.closed_at
closed_at: issue2.closed_at,
blocked: false
},
{
id: issue1.id,
......@@ -102,7 +108,8 @@ RSpec.describe EpicIssues::ListService do
epic_issue_id: epic_issue1.id,
due_date: nil,
created_at: issue1.created_at,
closed_at: issue1.closed_at
closed_at: issue1.closed_at,
blocked: true
},
{
id: issue3.id,
......@@ -118,7 +125,8 @@ RSpec.describe EpicIssues::ListService do
epic_issue_id: epic_issue3.id,
due_date: nil,
created_at: issue3.created_at,
closed_at: issue3.closed_at
closed_at: issue3.closed_at,
blocked: false
}
]
......@@ -147,7 +155,8 @@ RSpec.describe EpicIssues::ListService do
epic_issue_id: epic_issue2.id,
due_date: nil,
created_at: issue2.created_at,
closed_at: issue2.closed_at
closed_at: issue2.closed_at,
blocked: false
},
{
id: issue1.id,
......@@ -163,7 +172,8 @@ RSpec.describe EpicIssues::ListService do
epic_issue_id: epic_issue1.id,
due_date: nil,
created_at: issue1.created_at,
closed_at: issue1.closed_at
closed_at: issue1.closed_at,
blocked: true
}
]
......
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