diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /lib/banzai/reference_parser | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/banzai/reference_parser')
-rw-r--r-- | lib/banzai/reference_parser/base_parser.rb | 3 | ||||
-rw-r--r-- | lib/banzai/reference_parser/snippet_parser.rb | 17 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index 9ecbc3ecec2..c4d7e40b46c 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -169,7 +169,8 @@ module Banzai # been queried the object is returned from the cache. def collection_objects_for_ids(collection, ids) if Gitlab::SafeRequestStore.active? - ids = ids.map(&:to_i) + ids = ids.map(&:to_i).uniq + cache = collection_cache[collection_cache_key(collection)] to_query = ids - cache.keys diff --git a/lib/banzai/reference_parser/snippet_parser.rb b/lib/banzai/reference_parser/snippet_parser.rb index b86c259efbd..bd42f6e6ed4 100644 --- a/lib/banzai/reference_parser/snippet_parser.rb +++ b/lib/banzai/reference_parser/snippet_parser.rb @@ -9,10 +9,23 @@ module Banzai Snippet end + # Returns all the nodes that are visible to the given user. + def nodes_visible_to_user(user, nodes) + snippets = lazy { grouped_objects_for_nodes(nodes, references_relation, self.class.data_attribute) } + + nodes.select do |node| + if node.has_attribute?(self.class.data_attribute) + can_read_reference?(user, snippets[node]) + else + true + end + end + end + private - def can_read_reference?(user, ref_project, node) - can?(user, :read_snippet, referenced_by([node]).first) + def can_read_reference?(user, snippet) + can?(user, :read_snippet, snippet) end end end |