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

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

34 lines
777 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)
2021-01-03 14:25:43 +05:30
groups = lazy { grouped_objects_for_nodes(nodes, references_relation, GROUP_ATTR) }
2019-12-21 20:55:43 +05:30
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