BigW Consortium Gitlab

joined_groups_finder.rb 548 Bytes
Newer Older
1
class JoinedGroupsFinder < UnionFinder
2
  def initialize(user)
3 4 5 6 7 8
    @user = user
  end

  # Finds the groups of the source user, optionally limited to those visible to
  # the current user.
  def execute(current_user = nil)
9
    segments = all_groups(current_user)
10

11
    find_union(segments, Group).order_id_desc
12 13 14 15
  end

  private

16 17
  def all_groups(current_user)
    groups = []
18

19 20
    groups << @user.authorized_groups.visible_to_user(current_user) if current_user
    groups << @user.authorized_groups.public_to_user(current_user)
21

22
    groups
23 24
  end
end