Commit 8062a7ac authored by Alper Akgun's avatar Alper Akgun

Merge branch '348293-fj-introduce-group-descendants-finder-upto' into 'master'

Introduce linear ancestors upto in GroupDescendantsFinder

See merge request gitlab-org/gitlab!78991
parents 47552665 fb91e449
......@@ -110,8 +110,13 @@ class GroupDescendantsFinder
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_groups(base_for_ancestors)
group_ids = base_for_ancestors.except(:select, :sort).select(:id)
Gitlab::ObjectHierarchy.new(Group.where(id: group_ids))
.base_and_ancestors(upto: parent_group.id)
groups = Group.where(id: group_ids)
if Feature.enabled?(:linear_group_descendants_finder_upto, current_user, default_enabled: :yaml)
groups.self_and_ancestors(upto: parent_group.id)
else
Gitlab::ObjectHierarchy.new(groups).base_and_ancestors(upto: parent_group.id)
end
end
# rubocop: enable CodeReuse/ActiveRecord
......
---
name: linear_group_descendants_finder_upto
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78991
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/350972
milestone: '14.8'
type: development
group: group::authentication and authorization
default_enabled: false
......@@ -165,8 +165,8 @@ RSpec.describe GroupDescendantsFinder do
end
context 'with nested groups' do
let!(:project) { create(:project, namespace: group) }
let!(:subgroup) { create(:group, :private, parent: group) }
let_it_be(:project) { create(:project, namespace: group) }
let_it_be_with_reload(:subgroup) { create(:group, :private, parent: group) }
describe '#execute' do
it 'contains projects and subgroups' do
......@@ -208,6 +208,7 @@ RSpec.describe GroupDescendantsFinder do
context 'with a filter' do
let(:params) { { filter: 'test' } }
shared_examples 'filter examples' do
it 'contains only matching projects and subgroups' do
matching_project = create(:project, namespace: group, name: 'Testproject')
matching_subgroup = create(:group, name: 'testgroup', parent: group)
......@@ -261,6 +262,17 @@ RSpec.describe GroupDescendantsFinder do
end
end
end
it_behaves_like 'filter examples'
context 'when feature flag :linear_group_descendants_finder_upto is disabled' do
before do
stub_feature_flags(linear_group_descendants_finder_upto: false)
end
it_behaves_like 'filter examples'
end
end
end
end
end
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