2015-12-15 14:51:16 +00:00
|
|
|
module Banzai
|
|
|
|
module Filter
|
2015-04-14 22:34:01 +00:00
|
|
|
# HTML filter that replaces issue references with links. References to
|
|
|
|
# issues that do not exist are ignored.
|
2015-04-03 00:46:43 +00:00
|
|
|
#
|
|
|
|
# This filter supports cross-project references.
|
2016-10-06 22:05:27 +00:00
|
|
|
#
|
|
|
|
# When external issues tracker like Jira is activated we should not
|
|
|
|
# use issue reference pattern, but we should still be able
|
|
|
|
# to reference issues from other GitLab projects.
|
2015-11-16 20:56:28 +00:00
|
|
|
class IssueReferenceFilter < AbstractReferenceFilter
|
2016-05-26 11:16:43 +00:00
|
|
|
self.reference_type = :issue
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def self.object_class
|
|
|
|
Issue
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2016-10-06 22:05:27 +00:00
|
|
|
def uses_reference_pattern?
|
|
|
|
context[:project].default_issues_tracker?
|
|
|
|
end
|
|
|
|
|
2016-06-01 15:39:12 +00:00
|
|
|
def find_object(project, iid)
|
|
|
|
issues_per_project[project][iid]
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def url_for_object(issue, project)
|
|
|
|
IssuesHelper.url_for_issue(issue.iid, project, only_path: context[:only_path])
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
2016-06-01 15:39:12 +00:00
|
|
|
|
|
|
|
def project_from_ref(ref)
|
|
|
|
projects_per_reference[ref || current_project_path]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a Hash containing the issues per Project instance.
|
|
|
|
def issues_per_project
|
|
|
|
@issues_per_project ||= begin
|
|
|
|
hash = Hash.new { |h, k| h[k] = {} }
|
|
|
|
|
|
|
|
projects_per_reference.each do |path, project|
|
|
|
|
issue_ids = references_per_project[path]
|
|
|
|
|
2017-02-22 01:02:23 +00:00
|
|
|
issues = if project.default_issues_tracker?
|
|
|
|
project.issues.where(iid: issue_ids.to_a)
|
2016-06-20 09:53:08 +00:00
|
|
|
else
|
2017-02-22 01:02:23 +00:00
|
|
|
issue_ids.map { |id| ExternalIssue.new(id, project) }
|
2016-06-20 09:53:08 +00:00
|
|
|
end
|
2016-06-01 15:39:12 +00:00
|
|
|
|
2016-06-20 09:53:08 +00:00
|
|
|
issues.each do |issue|
|
|
|
|
hash[project][issue.iid.to_i] = issue
|
2016-06-01 15:39:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-28 15:50:17 +00:00
|
|
|
def object_link_title(object)
|
|
|
|
if object.is_a?(ExternalIssue)
|
|
|
|
"Issue in #{object.project.external_issue_tracker.title}"
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-16 20:27:05 +00:00
|
|
|
def data_attributes_for(text, project, object, link: false)
|
2016-06-28 15:50:17 +00:00
|
|
|
if object.is_a?(ExternalIssue)
|
|
|
|
data_attribute(
|
|
|
|
project: project.id,
|
|
|
|
external_issue: object.id,
|
|
|
|
reference_type: ExternalIssueReferenceFilter.reference_type
|
|
|
|
)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-27 15:13:08 +00:00
|
|
|
def projects_relation_for_paths(paths)
|
2016-06-01 15:39:12 +00:00
|
|
|
super(paths).includes(:gitlab_issue_tracker_service)
|
|
|
|
end
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|