Commit 9f3995a0 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Find all children matching a query

parent 56318aa0fe6f
......@@ -41,25 +41,52 @@ def children
@children ||= subgroups + projects
end
def base_groups
GroupsFinder.new(current_user,
parent: parent_group,
all_available: true).execute
end
def all_subgroups
Gitlab::GroupHierarchy.new(Group.where(id: parent_group)).all_groups
end
def subgroups_matching_filter
all_subgroups.search(params[:filter])
end
def subgroups
return Group.none unless Group.supports_nested_groups?
return Group.none unless can?(current_user, :read_group, parent_group)
groups = GroupsFinder.new(current_user,
parent: parent_group,
all_available: true).execute
groups = groups.search(params[:filter]) if params[:filter].present?
groups = if params[:filter]
subgroups_matching_filter
else
base_groups
end
groups = groups.includes(:route).includes(:children)
groups.sort(params[:sort])
end
def base_projects
GroupProjectsFinder.new(group: parent_group, params: params, current_user: current_user).execute
end
def projects_matching_filter
ProjectsFinder.new(current_user: current_user).execute
.search(params[:filter])
.where(namespace: all_subgroups)
end
def projects
return Project.none unless can?(current_user, :read_group, parent_group)
projects = GroupProjectsFinder.new(group: parent_group, params: params, current_user: current_user).execute
projects = if params[:filter]
projects_matching_filter
else
base_projects
end
projects = projects.includes(:route)
projects = projects.search(params[:filter]) if params[:filter].present?
projects.sort(params[:sort])
end
end
......@@ -47,6 +47,20 @@
expect(finder.execute).to contain_exactly(matching_subgroup, matching_project)
end
context 'with matching children' do
it 'includes a group that has a subgroup matching the query' do
matching_subgroup = create(:group, name: 'testgroup', parent: subgroup)
expect(finder.execute).to contain_exactly(matching_subgroup)
end
it 'includes a group that has a project matching the query' do
matching_project = create(:project, namespace: subgroup, name: 'Testproject')
expect(finder.execute).to contain_exactly(matching_project)
end
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment