Use linear version GroupsWithTemplatesFinder#extended_group_search

In this commit we're removing the ff
`linear_groups_template_finder_extended_group_search_ancestors_scopes`
and enabling the linear version of
`GroupsWithTemplatesFinder#extended_group_search`.

Changelog: changed
EE: true
parent a4cb0770
---
name: linear_groups_template_finder_extended_group_search_ancestors_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74599
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/345786
milestone: '14.6'
type: development
group: group::access
default_enabled: false
...@@ -18,16 +18,11 @@ class GroupsWithTemplatesFinder ...@@ -18,16 +18,11 @@ class GroupsWithTemplatesFinder
attr_reader :group_id attr_reader :group_id
def extended_group_search def extended_group_search
# We're adding an extra query that will be removed once we remove the feature flag in https://gitlab.com/gitlab-org/gitlab/-/issues/339439 Group
groups = if Feature.enabled?(:linear_groups_template_finder_extended_group_search_ancestors_scopes, current_group, default_enabled: :yaml) .with_project_templates
Group.with_project_templates.self_and_ancestors .self_and_ancestors
else .with_feature_available_in_plan(:group_project_templates)
Gitlab::ObjectHierarchy .self_and_descendants
.new(Group.with_project_templates)
.base_and_ancestors
end
groups.with_feature_available_in_plan(:group_project_templates).self_and_descendants
end end
def simple_group_search(groups) def simple_group_search(groups)
...@@ -36,9 +31,4 @@ class GroupsWithTemplatesFinder ...@@ -36,9 +31,4 @@ class GroupsWithTemplatesFinder
groups.with_project_templates groups.with_project_templates
end end
# This method will be removed https://gitlab.com/gitlab-org/gitlab/-/issues/339439
def current_group
Group.find_by(id: group_id) # rubocop:disable CodeReuse/ActiveRecord
end
end end
...@@ -26,38 +26,57 @@ RSpec.describe GroupsWithTemplatesFinder, :saas do ...@@ -26,38 +26,57 @@ RSpec.describe GroupsWithTemplatesFinder, :saas do
create(:gitlab_subscription, :premium, namespace: group_2) create(:gitlab_subscription, :premium, namespace: group_2)
end end
shared_examples 'group template finder examples' do describe 'without group id' do
describe 'without group id' do it 'returns all groups' do
it 'returns all groups' do expect(described_class.new.execute).to contain_exactly(group_1, group_2, group_3)
expect(described_class.new.execute).to contain_exactly(group_1, group_2, group_3) end
context 'when namespace checked' do
before do
stub_ee_application_setting(should_check_namespace_plan: true)
end
it 'returns groups on ultimate/premium plan' do
expect(described_class.new.execute).to contain_exactly(group_1, group_2)
end end
context 'when namespace checked' do context 'with subgroup with template' do
before do before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true } subgroup_4.update!(custom_project_templates_group_id: subgroup_5.id)
create(:project, namespace: subgroup_5)
end end
it 'returns groups on ultimate/premium plan' do it 'returns groups on ultimate/premium plan' do
expect(described_class.new.execute).to contain_exactly(group_1, group_2) expect(described_class.new.execute).to contain_exactly(group_1, group_2, subgroup_4)
end end
end
end
end
context 'with subgroup with template' do describe 'with group id' do
before do it 'returns given group with it descendants' do
subgroup_4.update!(custom_project_templates_group_id: subgroup_5.id) expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
create(:project, namespace: subgroup_5) end
end
it 'returns groups on ultimate/premium plan' do context 'with subgroup with template' do
expect(described_class.new.execute).to contain_exactly(group_1, group_2, subgroup_4) before do
end subgroup_4.update!(custom_project_templates_group_id: subgroup_5.id)
end create(:project, namespace: subgroup_5)
end end
end
describe 'with group id' do it 'returns only chosen group' do
it 'returns given group with it descendants' do
expect(described_class.new(group_1.id).execute).to contain_exactly(group_1) expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
end end
end
context 'when namespace checked' do
before do
stub_ee_application_setting(should_check_namespace_plan: true)
end
it 'does not return the group' do
expect(described_class.new(group_3.id).execute).to be_empty
end
context 'with subgroup with template' do context 'with subgroup with template' do
before do before do
...@@ -68,42 +87,11 @@ RSpec.describe GroupsWithTemplatesFinder, :saas do ...@@ -68,42 +87,11 @@ RSpec.describe GroupsWithTemplatesFinder, :saas do
it 'returns only chosen group' do it 'returns only chosen group' do
expect(described_class.new(group_1.id).execute).to contain_exactly(group_1) expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
end end
end
context 'when namespace checked' do
before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { true }
end
it 'does not return the group' do it 'returns only chosen subgroup' do
expect(described_class.new(group_3.id).execute).to be_empty expect(described_class.new(subgroup_4.id).execute).to contain_exactly(group_1, subgroup_4)
end
context 'with subgroup with template' do
before do
subgroup_4.update!(custom_project_templates_group_id: subgroup_5.id)
create(:project, namespace: subgroup_5)
end
it 'returns only chosen group' do
expect(described_class.new(group_1.id).execute).to contain_exactly(group_1)
end
it 'returns only chosen subgroup' do
expect(described_class.new(subgroup_4.id).execute).to contain_exactly(group_1, subgroup_4)
end
end end
end end
end end
end end
it_behaves_like 'group template finder examples'
context 'when feature flag :linear_groups_template_finder_extended_group_search_ancestors_scopes is disabled' do
before do
stub_feature_flags(linear_groups_template_finder_extended_group_search_ancestors_scopes: false)
end
it_behaves_like 'group template finder examples'
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