2016-06-02 11:05:42 +05:30
|
|
|
class GroupsFinder < UnionFinder
|
2017-08-17 22:00:37 +05:30
|
|
|
def initialize(current_user = nil, params = {})
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def execute
|
2017-09-10 17:25:29 +05:30
|
|
|
items = all_groups.map do |item|
|
|
|
|
by_parent(item)
|
|
|
|
end
|
|
|
|
find_union(items, Group).with_route.order_id_desc
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def all_groups
|
2016-06-02 11:05:42 +05:30
|
|
|
groups = []
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if current_user
|
2017-09-10 17:25:29 +05:30
|
|
|
groups << Gitlab::GroupHierarchy.new(groups_for_ancestors, groups_for_descendants).all_groups
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
groups << Group.unscoped.public_to_user(current_user)
|
|
|
|
|
|
|
|
groups
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def groups_for_ancestors
|
|
|
|
current_user.authorized_groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def groups_for_descendants
|
|
|
|
current_user.groups
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def by_parent(groups)
|
|
|
|
return groups unless params[:parent]
|
|
|
|
|
|
|
|
groups.where(parent: params[:parent])
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|