Commit 6c2de364 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Split up adding ancestors for projects

parent 8a685ca8
...@@ -61,14 +61,19 @@ class GroupDescendantsFinder ...@@ -61,14 +61,19 @@ class GroupDescendantsFinder
paginated_projects = paginate_projects_after_groups(subgroups_with_counts) paginated_projects = paginate_projects_after_groups(subgroups_with_counts)
if params[:filter] subgroups_with_counts = add_project_ancestors_when_searching(subgroups_with_counts, paginated_projects)
ancestors_for_project_search = ancestors_for_groups(Group.where(id: paginated_projects.select(:namespace_id)))
subgroups_with_counts = ancestors_for_project_search.with_route.select(GROUP_SELECTS) | subgroups_with_counts
end
@children = subgroups_with_counts + paginated_projects @children = subgroups_with_counts + paginated_projects
end end
def add_project_ancestors_when_searching(groups, projects)
return groups unless params[:filter]
project_ancestors = ancestors_for_projects(projects)
.with_route.select(GROUP_SELECTS)
groups | project_ancestors
end
def paginate_projects_after_groups(loaded_subgroups) def paginate_projects_after_groups(loaded_subgroups)
# We adjust the pagination for projects for the combination with groups: # We adjust the pagination for projects for the combination with groups:
# - We limit the first page (page 0) where we show projects: # - We limit the first page (page 0) where we show projects:
...@@ -138,6 +143,10 @@ class GroupDescendantsFinder ...@@ -138,6 +143,10 @@ class GroupDescendantsFinder
.base_and_ancestors.where.not(id: ancestors_for_parent) .base_and_ancestors.where.not(id: ancestors_for_parent)
end end
def ancestors_for_projects(projects)
ancestors_for_groups(Group.where(id: projects.select(:namespace_id)))
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)
......
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