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: 30698f802316c318a13a065bd5b8f6e9760768e0 (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
class GroupsFinder
  def execute(current_user = nil)
    segments = all_groups(current_user)

    if segments.length > 1
      union = Gitlab::SQL::Union.new(segments.map { |s| s.select(:id) })
      Group.where("namespaces.id IN (#{union.to_sql})").order_id_desc
    else
      segments.first
    end
  end

  private

  def all_groups(current_user)
    if current_user
      user_groups(current_user)
    else
      [Group.unscoped.public_only]
    end
  end

  def user_groups(current_user)
    if current_user.external?
      [current_user.authorized_groups, Group.unscoped.public_only]
    else
      [current_user.authorized_groups, Group.unscoped.public_and_internal_only]
    end
  end
end