debian-mirror-gitlab/lib/banzai/reference_parser/snippet_parser.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
768 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Banzai
module ReferenceParser
class SnippetParser < BaseParser
self.reference_type = :snippet
def references_relation
Snippet
end
2016-11-24 13:41:30 +05:30
2020-10-24 23:57:45 +05:30
# 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
2016-11-24 13:41:30 +05:30
private
2020-10-24 23:57:45 +05:30
def can_read_reference?(user, snippet)
can?(user, :read_snippet, snippet)
2016-11-24 13:41:30 +05:30
end
end
end
end