diff options
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/groups_finder.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb new file mode 100644 index 00000000000..a3a8cd541de --- /dev/null +++ b/app/finders/groups_finder.rb @@ -0,0 +1,31 @@ +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 + [current_user.authorized_groups, public_and_internal_groups] + else + [Group.public_only] + end + end + + def public_groups + Group.unscoped.public_only + end + + def public_and_internal_groups + Group.unscoped.public_and_internal_only + end +end |