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

Find all children matching a query

parent 28c44004
...@@ -41,25 +41,52 @@ class GroupChildrenFinder ...@@ -41,25 +41,52 @@ class GroupChildrenFinder
@children ||= subgroups + projects @children ||= subgroups + projects
end 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 def subgroups
return Group.none unless Group.supports_nested_groups? return Group.none unless Group.supports_nested_groups?
return Group.none unless can?(current_user, :read_group, parent_group) return Group.none unless can?(current_user, :read_group, parent_group)
groups = GroupsFinder.new(current_user, groups = if params[:filter]
parent: parent_group, subgroups_matching_filter
all_available: true).execute else
base_groups
groups = groups.search(params[:filter]) if params[:filter].present? end
groups = groups.includes(:route).includes(:children) groups = groups.includes(:route).includes(:children)
groups.sort(params[:sort]) groups.sort(params[:sort])
end 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 def projects
return Project.none unless can?(current_user, :read_group, parent_group) 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.includes(:route)
projects = projects.search(params[:filter]) if params[:filter].present?
projects.sort(params[:sort]) projects.sort(params[:sort])
end end
end end
...@@ -47,6 +47,20 @@ describe GroupChildrenFinder do ...@@ -47,6 +47,20 @@ describe GroupChildrenFinder do
expect(finder.execute).to contain_exactly(matching_subgroup, matching_project) expect(finder.execute).to contain_exactly(matching_subgroup, matching_project)
end 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
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