summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-07-18 15:01:56 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-07-18 16:44:39 +0200
commit1b73ca2c0099505e0b036fc08d2bb4b6cd59f7c5 (patch)
tree4f6fa59cfcd4fb326efa1162be979451fb261f46
parentf97c4425ebc3c2dc0549d0bcae91e977cc92d2fc (diff)
downloadgitlab-ce-bvl-children-groups-archived-only.tar.gz
Limit to subgroups with nested archived projectsbvl-children-groups-archived-only
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.
-rw-r--r--app/finders/group_descendants_finder.rb16
-rw-r--r--changelogs/unreleased/bvl-children-groups-archived-only.yml6
-rw-r--r--spec/finders/group_descendants_finder_spec.rb19
3 files changed, 38 insertions, 3 deletions
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