Welcome to mirror list, hosted at ThFree Co, Russian Federation.

groups_finder.rb « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb4ab6eacc1ad847b0f1ecca524538dd18a81a55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class GroupsFinder < UnionFinder
  def initialize(current_user = nil, params = {})
    @current_user = current_user
    @params = params
  end

  def execute
    groups = find_union(all_groups, Group).with_route.order_id_desc
    by_parent(groups)
  end

  private

  attr_reader :current_user, :params

  def all_groups
    groups = []

    if current_user
      groups_for_ancestors = find_union([current_user.authorized_groups, authorized_project_groups], Group)
      groups_for_descendants = current_user.authorized_groups
      groups << Gitlab::GroupHierarchy.new(groups_for_ancestors, groups_for_descendants).all_groups
    end
    groups << Group.unscoped.public_to_user(current_user)

    groups
  end

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

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