gitlab-org--gitlab-foss/app/finders/groups_finder.rb

31 lines
594 B
Ruby
Raw Normal View History

2016-03-20 16:03:53 -04:00
class GroupsFinder < UnionFinder
def initialize(current_user = nil, params = {})
@current_user = current_user
@params = params
end
2016-03-01 10:22:29 -05:00
def execute
groups = find_union(all_groups, Group).with_route.order_id_desc
by_parent(groups)
2016-03-01 10:22:29 -05:00
end
private
attr_reader :current_user, :params
def all_groups
2016-03-20 16:03:53 -04:00
groups = []
groups << current_user.authorized_groups if current_user
groups << Group.unscoped.public_to_user(current_user)
2016-03-17 18:42:46 -04:00
2016-03-20 16:03:53 -04:00
groups
2016-03-17 18:42:46 -04:00
end
def by_parent(groups)
return groups unless params[:parent]
groups.where(parent: params[:parent])
end
2016-03-01 10:22:29 -05:00
end