Skip to content

Commit c56326f

Browse files
committed
Fix filter on dashboard/groups & `explore/groups
When searching we would limit the scope of ancestors to load because the filter would be applied to the ancestors. Instead, we need to load _all_ ancestors for matching projects.
1 parent b871764 commit c56326f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app/controllers/concerns/group_tree.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ module GroupTree
22
# rubocop:disable Gitlab/ModuleWithInstanceVariables
33
def render_group_tree(groups)
44
@groups = if params[:filter].present?
5-
Gitlab::GroupHierarchy.new(groups.search(params[:filter]))
5+
# We find the ancestors by ID of the search results here.
6+
# Otherwise the ancestors would also have filters applied,
7+
# which would cause them not to be preloaded.
8+
group_ids = groups.search(params[:filter]).select(:id)
9+
Gitlab::GroupHierarchy.new(Group.where(id: group_ids))
610
.base_and_ancestors
711
else
812
# Only show root groups if no parent-id is given
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Fix issues when rendering groups and their children
3+
merge_request: 16584
4+
author:
5+
type: fixed

spec/controllers/dashboard/groups_controller_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,24 @@
2020

2121
expect(assigns(:groups)).to contain_exactly(member_of_group)
2222
end
23+
24+
context 'when rendering an expanded hierarchy with public groups you are not a member of', :nested_groups do
25+
let!(:top_level_result) { create(:group, name: 'chef-top') }
26+
let!(:top_level_a) { create(:group, name: 'top-a') }
27+
let!(:sub_level_result_a) { create(:group, name: 'chef-sub-a', parent: top_level_a) }
28+
let!(:other_group) { create(:group, name: 'other') }
29+
30+
before do
31+
top_level_result.add_master(user)
32+
top_level_a.add_master(user)
33+
end
34+
35+
it 'renders only groups the user is a member of when searching hierarchy correctly' do
36+
get :index, filter: 'chef', format: :json
37+
38+
expect(response).to have_gitlab_http_status(200)
39+
all_groups = [top_level_result, top_level_a, sub_level_result_a]
40+
expect(assigns(:groups)).to contain_exactly(*all_groups)
41+
end
42+
end
2343
end

0 commit comments

Comments
 (0)