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

34 lines
763 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module Banzai
module ReferenceParser
2020-01-01 13:55:28 +05:30
class MentionedGroupParser < BaseParser
2019-12-21 20:55:43 +05:30
GROUP_ATTR = 'data-group'
self.reference_type = :user
def self.data_attribute
@data_attribute ||= GROUP_ATTR
end
def references_relation
Group
end
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
def can_read_group_reference?(node, user, groups)
node_group = groups[node]
node_group && can?(user, :read_group, node_group)
end
end
end
end