2018-10-06 19:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-26 07:16:43 -04:00
|
|
|
module Banzai
|
|
|
|
module ReferenceParser
|
|
|
|
class SnippetParser < BaseParser
|
|
|
|
self.reference_type = :snippet
|
|
|
|
|
|
|
|
def references_relation
|
|
|
|
Snippet
|
|
|
|
end
|
2016-11-01 16:18:51 -04:00
|
|
|
|
2020-07-21 08:09:30 -04:00
|
|
|
# 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-01 16:18:51 -04:00
|
|
|
private
|
|
|
|
|
2020-07-21 08:09:30 -04:00
|
|
|
def can_read_reference?(user, snippet)
|
|
|
|
can?(user, :read_snippet, snippet)
|
2016-11-01 16:18:51 -04:00
|
|
|
end
|
2016-05-26 07:16:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|