From 1b73ca2c0099505e0b036fc08d2bb4b6cd59f7c5 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 18 Jul 2018 15:01:56 +0200 Subject: Limit to subgroups with nested archived projects When loading children of a group with the `archived: 'only'` flag set. We only want to show subgroups that have archived projects somewhere nested within them. --- app/finders/group_descendants_finder.rb | 16 +++++++++++++--- .../unreleased/bvl-children-groups-archived-only.yml | 6 ++++++ spec/finders/group_descendants_finder_spec.rb | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/bvl-children-groups-archived-only.yml diff --git a/app/finders/group_descendants_finder.rb b/app/finders/group_descendants_finder.rb index 051ea108e06..8a08d98b7ed 100644 --- a/app/finders/group_descendants_finder.rb +++ b/app/finders/group_descendants_finder.rb @@ -61,9 +61,19 @@ class GroupDescendantsFinder end def direct_child_groups - GroupsFinder.new(current_user, - parent: parent_group, - all_available: true).execute + groups = GroupsFinder.new(current_user, + parent: parent_group, + all_available: true).execute + + if params[:archived] == 'only' + groups_with_archived_projects = Group.where("EXISTS (?)", Project.where(archived: true).where('projects.namespace_id = namespaces.id').select(1)) + groups_with_nested_archived_projects = Gitlab::GroupHierarchy.new(groups_with_archived_projects) + .base_and_ancestors(upto: parent_group) + + groups = groups_with_nested_archived_projects.merge(groups) + end + + groups end def all_visible_descendant_groups diff --git a/changelogs/unreleased/bvl-children-groups-archived-only.yml b/changelogs/unreleased/bvl-children-groups-archived-only.yml new file mode 100644 index 00000000000..7c28b6621e2 --- /dev/null +++ b/changelogs/unreleased/bvl-children-groups-archived-only.yml @@ -0,0 +1,6 @@ +--- +title: Only show subgroups that have archived projects when selecting to show archived + projects +merge_request: 20693 +author: +type: changed diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb index 796d40cb625..e9e36ff6b36 100644 --- a/spec/finders/group_descendants_finder_spec.rb +++ b/spec/finders/group_descendants_finder_spec.rb @@ -55,6 +55,25 @@ describe GroupDescendantsFinder do expect(finder.execute).to contain_exactly(archived_project) end + + it 'only includes subgroups that have archived projects', :nested_groups do + other_subgroup = create(:group, :public, parent: create(:group)) + _archived_project_in_other_group = create(:project, :archived, namespace: other_subgroup) + subgroup = create(:group, parent: group) + _archived_project = create(:project, :archived, namespace: subgroup) + _other_subgroup = create(:group, parent: group) + + expect(finder.execute).to contain_exactly(subgroup) + end + + it 'only includes subgroups that have nested archived projects', :nested_groups do + subgroup_with_nested_arcived_project = create(:group, parent: group) + sub_sub_group_with_archived_project = create(:group, parent: subgroup_with_nested_arcived_project) + _other_subgroup = create(:group, parent: group) + _archived_project = create(:project, :archived, namespace: sub_sub_group_with_archived_project) + + expect(finder.execute).to contain_exactly(subgroup_with_nested_arcived_project) + end end it 'does not include archived projects' do -- cgit v1.2.1