diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-06 15:28:07 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:46:49 +0200 |
commit | 9f3995a0ca3d56fd8d219a2b01c3e6555fd91f27 (patch) | |
tree | cd09cb13db43b06b11be915f98a271f549288358 /app/finders | |
parent | 28c440045ed001ab6029131ab7c842b390f4e186 (diff) | |
download | gitlab-ce-9f3995a0ca3d56fd8d219a2b01c3e6555fd91f27.tar.gz |
Find all children matching a query
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/group_children_finder.rb | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/app/finders/group_children_finder.rb b/app/finders/group_children_finder.rb index 71bef7b0ce2..31b122e10f6 100644 --- a/app/finders/group_children_finder.rb +++ b/app/finders/group_children_finder.rb @@ -41,25 +41,52 @@ class GroupChildrenFinder @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 |