ace833b31d
Example: for issues that are closed, the links will now show '[closed]' following the issue number. This is done as post-process after the markdown has been loaded from the cache as the status of the issue may change between the cache being populated and the content being displayed. In order to avoid N+1 queries problem when rendering notes ObjectRenderer populates the cache of referenced issuables for all notes at once, before the post processing phase. As a part of this change, the Banzai BaseParser#grouped_objects_for_nodes method has been refactored to return a Hash utilising the node itself as the key, since this was a common pattern of usage for this method.
49 lines
1.3 KiB
Ruby
49 lines
1.3 KiB
Ruby
module Banzai
|
|
module ReferenceParser
|
|
class IssueParser < BaseParser
|
|
self.reference_type = :issue
|
|
|
|
def nodes_visible_to_user(user, nodes)
|
|
# It is not possible to check access rights for external issue trackers
|
|
return nodes if project && project.external_issue_tracker
|
|
|
|
issues = issues_for_nodes(nodes)
|
|
|
|
readable_issues = Ability.
|
|
issues_readable_by_user(issues.values, user).to_set
|
|
|
|
nodes.select do |node|
|
|
readable_issues.include?(issues[node])
|
|
end
|
|
end
|
|
|
|
def referenced_by(nodes)
|
|
issues = issues_for_nodes(nodes)
|
|
|
|
nodes.map { |node| issues[node] }.compact.uniq
|
|
end
|
|
|
|
def issues_for_nodes(nodes)
|
|
@issues_for_nodes ||= grouped_objects_for_nodes(
|
|
nodes,
|
|
Issue.all.includes(
|
|
:author,
|
|
:assignee,
|
|
{
|
|
# These associations are primarily used for checking permissions.
|
|
# Eager loading these ensures we don't end up running dozens of
|
|
# queries in this process.
|
|
project: [
|
|
{ namespace: :owner },
|
|
{ group: [:owners, :group_members] },
|
|
:invited_groups,
|
|
:project_members
|
|
]
|
|
}
|
|
),
|
|
self.class.data_attribute
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|