2016-03-01 15:22:29 +00:00
|
|
|
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
|
2016-03-17 22:42:46 +00:00
|
|
|
user_groups(current_user)
|
2016-03-01 15:22:29 +00:00
|
|
|
else
|
2016-03-02 22:13:50 +00:00
|
|
|
[Group.unscoped.public_only]
|
2016-03-01 15:22:29 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-17 22:42:46 +00:00
|
|
|
|
|
|
|
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
|
2016-03-01 15:22:29 +00:00
|
|
|
end
|