2016-03-20 20:03:53 +00:00
|
|
|
class GroupsFinder < UnionFinder
|
2017-05-03 23:51:25 +00:00
|
|
|
def initialize(current_user = nil, params = {})
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
2016-03-01 15:22:29 +00:00
|
|
|
|
2017-05-03 23:51:25 +00:00
|
|
|
def execute
|
|
|
|
groups = find_union(all_groups, Group).with_route.order_id_desc
|
|
|
|
by_parent(groups)
|
2016-03-01 15:22:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-05-03 23:51:25 +00:00
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def all_groups
|
2016-03-20 20:03:53 +00:00
|
|
|
groups = []
|
|
|
|
|
2017-06-13 07:11:33 +00:00
|
|
|
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
|
2016-03-20 20:03:53 +00:00
|
|
|
groups << Group.unscoped.public_to_user(current_user)
|
2016-03-17 22:42:46 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
groups
|
2016-03-17 22:42:46 +00:00
|
|
|
end
|
2017-05-03 23:51:25 +00:00
|
|
|
|
|
|
|
def by_parent(groups)
|
|
|
|
return groups unless params[:parent]
|
|
|
|
|
|
|
|
groups.where(parent: params[:parent])
|
|
|
|
end
|
2016-03-01 15:22:29 +00:00
|
|
|
end
|