debian-mirror-gitlab/lib/banzai/filter/issue_reference_filter.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
module Banzai
module Filter
# HTML filter that replaces issue references with links. References to
# issues that do not exist are ignored.
#
# This filter supports cross-project references.
2016-11-03 12:29:30 +05:30
#
# 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.
2018-03-17 18:26:18 +05:30
class IssueReferenceFilter < IssuableReferenceFilter
self.reference_type = :issue
2015-12-23 02:04:40 +05:30
def self.object_class
Issue
end
def url_for_object(issue, project)
2020-06-23 00:09:42 +05:30
return issue_path(issue, project) if only_path?
issue_url(issue, project)
2015-12-23 02:04:40 +05:30
end
2016-06-22 15:30:34 +05:30
2018-03-17 18:26:18 +05:30
def parent_records(parent, ids)
parent.issues.where(iid: ids.to_a)
end
2020-05-24 23:13:21 +05:30
def object_link_text_extras(issue, matches)
super + design_link_extras(issue, matches.named_captures['path'])
end
private
2020-06-23 00:09:42 +05:30
def issue_path(issue, project)
Gitlab::Routing.url_helpers.namespace_project_issue_path(namespace_id: project.namespace, project_id: project, id: issue.iid)
end
def issue_url(issue, project)
Gitlab::Routing.url_helpers.namespace_project_issue_url(namespace_id: project.namespace, project_id: project, id: issue.iid)
end
2020-05-24 23:13:21 +05:30
def design_link_extras(issue, path)
if path == '/designs' && read_designs?(issue)
['designs']
else
[]
end
end
def read_designs?(issue)
2020-06-23 00:09:42 +05:30
issue.project.design_management_enabled?
2020-05-24 23:13:21 +05:30
end
2015-12-23 02:04:40 +05:30
end
end
end