diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-28 21:10:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-28 21:10:13 +0000 |
commit | 8f016fe5fb42704dd949e77859888fcd898fd985 (patch) | |
tree | 32c3c311c5fb330769601b2cf684aebe6f102196 /lib/banzai | |
parent | e4632f4c63eae7ec36243d11b23d69b4fd880830 (diff) | |
download | gitlab-ce-8f016fe5fb42704dd949e77859888fcd898fd985.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/reference_extractor.rb | 4 | ||||
-rw-r--r-- | lib/banzai/reference_parser/base_parser.rb | 12 | ||||
-rw-r--r-- | lib/banzai/reference_parser/commit_parser.rb | 2 | ||||
-rw-r--r-- | lib/banzai/reference_parser/commit_range_parser.rb | 2 | ||||
-rw-r--r-- | lib/banzai/reference_parser/external_issue_parser.rb | 2 | ||||
-rw-r--r-- | lib/banzai/reference_parser/issuable_parser.rb | 2 | ||||
-rw-r--r-- | lib/banzai/reference_parser/user_parser.rb | 2 |
7 files changed, 14 insertions, 12 deletions
diff --git a/lib/banzai/reference_extractor.rb b/lib/banzai/reference_extractor.rb index 3fc3ae02088..af0dcad107e 100644 --- a/lib/banzai/reference_extractor.rb +++ b/lib/banzai/reference_extractor.rb @@ -11,11 +11,11 @@ module Banzai @texts_and_contexts << { text: text, context: context } end - def references(type, project, current_user = nil) + def references(type, project, current_user, ids_only: false) context = RenderContext.new(project, current_user) processor = Banzai::ReferenceParser[type].new(context) - processor.process(html_documents) + processor.process(html_documents, ids_only: ids_only) end def reset_memoized_values diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index 3dfea8ee895..0c015ba00c7 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -76,9 +76,11 @@ module Banzai end # Returns an Array of objects referenced by any of the given HTML nodes. - def referenced_by(nodes) + def referenced_by(nodes, options = {}) ids = unique_attribute_values(nodes, self.class.data_attribute) + return ids if options.fetch(:ids_only, false) + if ids.empty? references_relation.none else @@ -194,7 +196,7 @@ module Banzai # Processes the list of HTML documents and returns an Array containing all # the references. - def process(documents) + def process(documents, ids_only: false) type = self.class.reference_type reference_options = self.class.reference_options @@ -202,17 +204,17 @@ module Banzai Querying.css(document, "a[data-reference-type='#{type}'].gfm", reference_options).to_a end - gather_references(nodes) + gather_references(nodes, ids_only: ids_only) end # Gathers the references for the given HTML nodes. Returns visible # references and a list of nodes which are not visible to the user - def gather_references(nodes) + def gather_references(nodes, ids_only: false) nodes = nodes_user_can_reference(current_user, nodes) visible = nodes_visible_to_user(current_user, nodes) not_visible = nodes - visible - { visible: referenced_by(visible), not_visible: not_visible } + { visible: referenced_by(visible, ids_only: ids_only), not_visible: not_visible } end # Returns a Hash containing the projects for a given list of HTML nodes. diff --git a/lib/banzai/reference_parser/commit_parser.rb b/lib/banzai/reference_parser/commit_parser.rb index 0bfb6a92020..88896970bc6 100644 --- a/lib/banzai/reference_parser/commit_parser.rb +++ b/lib/banzai/reference_parser/commit_parser.rb @@ -5,7 +5,7 @@ module Banzai class CommitParser < BaseParser self.reference_type = :commit - def referenced_by(nodes) + def referenced_by(nodes, options = {}) commit_ids = commit_ids_per_project(nodes) projects = find_projects_for_hash_keys(commit_ids) diff --git a/lib/banzai/reference_parser/commit_range_parser.rb b/lib/banzai/reference_parser/commit_range_parser.rb index 480eefd5c4d..fb4a392105f 100644 --- a/lib/banzai/reference_parser/commit_range_parser.rb +++ b/lib/banzai/reference_parser/commit_range_parser.rb @@ -5,7 +5,7 @@ module Banzai class CommitRangeParser < BaseParser self.reference_type = :commit_range - def referenced_by(nodes) + def referenced_by(nodes, options = {}) range_ids = commit_range_ids_per_project(nodes) projects = find_projects_for_hash_keys(range_ids) diff --git a/lib/banzai/reference_parser/external_issue_parser.rb b/lib/banzai/reference_parser/external_issue_parser.rb index 029b09dcd25..e8ee337064a 100644 --- a/lib/banzai/reference_parser/external_issue_parser.rb +++ b/lib/banzai/reference_parser/external_issue_parser.rb @@ -5,7 +5,7 @@ module Banzai class ExternalIssueParser < BaseParser self.reference_type = :external_issue - def referenced_by(nodes) + def referenced_by(nodes, options = {}) issue_ids = issue_ids_per_project(nodes) projects = find_projects_for_hash_keys(issue_ids) issues = [] diff --git a/lib/banzai/reference_parser/issuable_parser.rb b/lib/banzai/reference_parser/issuable_parser.rb index f8c26288017..efcaa6664b6 100644 --- a/lib/banzai/reference_parser/issuable_parser.rb +++ b/lib/banzai/reference_parser/issuable_parser.rb @@ -13,7 +13,7 @@ module Banzai end end - def referenced_by(nodes) + def referenced_by(nodes, options = {}) records = records_for_nodes(nodes) nodes.map { |node| records[node] }.compact.uniq diff --git a/lib/banzai/reference_parser/user_parser.rb b/lib/banzai/reference_parser/user_parser.rb index 36c41c6615f..c40ca9dc7cd 100644 --- a/lib/banzai/reference_parser/user_parser.rb +++ b/lib/banzai/reference_parser/user_parser.rb @@ -5,7 +5,7 @@ module Banzai class UserParser < BaseParser self.reference_type = :user - def referenced_by(nodes) + def referenced_by(nodes, options = {}) group_ids = [] user_ids = [] project_ids = [] |