Class: Banzai::ReferenceParser::MentionedGroupParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/banzai/reference_parser/mentioned_group_parser.rb

Constant Summary collapse

GROUP_ATTR =
'data-group'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseParser

#can?, #collection_cache_key, #collection_objects_for_ids, #find_projects_for_hash_keys, #gather_attributes_per_project, #gather_references, #grouped_objects_for_nodes, #initialize, #nodes_user_can_reference, #process, #project_for_node, #projects_for_nodes, #referenced_by, #unique_attribute_values

Constructor Details

This class inherits a constructor from Banzai::ReferenceParser::BaseParser

Class Method Details

.data_attributeObject


10
11
12
# File 'lib/banzai/reference_parser/mentioned_group_parser.rb', line 10

def self.data_attribute
  @data_attribute ||= GROUP_ATTR
end

Instance Method Details

#can_read_group_reference?(node, user, groups) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
29
30
# File 'lib/banzai/reference_parser/mentioned_group_parser.rb', line 26

def can_read_group_reference?(node, user, groups)
  node_group = groups[node]

  node_group && can?(user, :read_group, node_group)
end

#nodes_visible_to_user(user, nodes) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/banzai/reference_parser/mentioned_group_parser.rb', line 18

def nodes_visible_to_user(user, nodes)
  groups = lazy { grouped_objects_for_nodes(nodes, Group, GROUP_ATTR) }

  nodes.select do |node|
    node.has_attribute?(GROUP_ATTR) && can_read_group_reference?(node, user, groups)
  end
end

#references_relationObject


14
15
16
# File 'lib/banzai/reference_parser/mentioned_group_parser.rb', line 14

def references_relation
  Group
end