2016-05-26 11:16:43 +00:00
|
|
|
module Banzai
|
|
|
|
module ReferenceParser
|
|
|
|
class MergeRequestParser < BaseParser
|
|
|
|
self.reference_type = :merge_request
|
|
|
|
|
2017-04-07 12:40:11 +00:00
|
|
|
def nodes_visible_to_user(user, nodes)
|
|
|
|
merge_requests = merge_requests_for_nodes(nodes)
|
|
|
|
|
|
|
|
nodes.select do |node|
|
|
|
|
merge_request = merge_requests[node]
|
|
|
|
|
|
|
|
merge_request && can?(user, :read_merge_request, merge_request.project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def referenced_by(nodes)
|
|
|
|
merge_requests = merge_requests_for_nodes(nodes)
|
|
|
|
|
|
|
|
nodes.map { |node| merge_requests[node] }.compact.uniq
|
|
|
|
end
|
|
|
|
|
2016-08-24 17:11:48 +00:00
|
|
|
def merge_requests_for_nodes(nodes)
|
|
|
|
@merge_requests_for_nodes ||= grouped_objects_for_nodes(
|
|
|
|
nodes,
|
2017-04-07 12:40:11 +00:00
|
|
|
MergeRequest.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.
|
|
|
|
target_project: [
|
|
|
|
{ namespace: :owner },
|
|
|
|
{ group: [:owners, :group_members] },
|
|
|
|
:invited_groups,
|
2017-05-02 16:29:45 +00:00
|
|
|
:project_members,
|
|
|
|
:project_feature
|
2017-04-07 12:40:11 +00:00
|
|
|
]
|
|
|
|
}),
|
2016-08-24 17:11:48 +00:00
|
|
|
self.class.data_attribute
|
|
|
|
)
|
|
|
|
end
|
2017-06-08 16:56:39 +00:00
|
|
|
|
|
|
|
def can_read_reference?(user, ref_project, node)
|
|
|
|
can?(user, :read_merge_request, ref_project)
|
|
|
|
end
|
2016-05-26 11:16:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|