BigW Consortium Gitlab

groups_finder.rb 594 Bytes
Newer Older
1
class GroupsFinder < UnionFinder
2 3 4 5
  def initialize(current_user = nil, params = {})
    @current_user = current_user
    @params = params
  end
6

7 8 9
  def execute
    groups = find_union(all_groups, Group).with_route.order_id_desc
    by_parent(groups)
10 11 12 13
  end

  private

14 15 16
  attr_reader :current_user, :params

  def all_groups
17 18 19 20
    groups = []

    groups << current_user.authorized_groups if current_user
    groups << Group.unscoped.public_to_user(current_user)
Felipe Artur committed
21

22
    groups
Felipe Artur committed
23
  end
24 25 26 27 28 29

  def by_parent(groups)
    return groups unless params[:parent]

    groups.where(parent: params[:parent])
  end
30
end