2016-06-16 23:09:34 +05:30
|
|
|
module Banzai
|
|
|
|
module ReferenceParser
|
|
|
|
class IssueParser < BaseParser
|
|
|
|
self.reference_type = :issue
|
|
|
|
|
|
|
|
def nodes_visible_to_user(user, nodes)
|
|
|
|
issues = issues_for_nodes(nodes)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
readable_issues = Ability
|
|
|
|
.issues_readable_by_user(issues.values, user).to_set
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
nodes.select do |node|
|
2017-08-17 22:00:37 +05:30
|
|
|
readable_issues.include?(issues[node])
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def referenced_by(nodes)
|
|
|
|
issues = issues_for_nodes(nodes)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
nodes.map { |node| issues[node] }.compact.uniq
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def issues_for_nodes(nodes)
|
|
|
|
@issues_for_nodes ||= grouped_objects_for_nodes(
|
|
|
|
nodes,
|
|
|
|
Issue.all.includes(
|
|
|
|
:author,
|
2017-08-17 22:00:37 +05:30
|
|
|
:assignees,
|
2016-06-16 23:09:34 +05:30
|
|
|
{
|
|
|
|
# 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
|