Commit 8d1d6aa3 authored by Doug Stull's avatar Doug Stull

Merge branch '339233-fj-use-application_setting-ancestor-linear-scopes' into 'master'

Use ApplicationSetting ancestors linear scopes

See merge request gitlab-org/gitlab!70579
parents 958b6550 d7aaa809
---
name: linear_application_setting_ancestor_scopes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70579
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/341346
milestone: '14.4'
type: development
group: group::access
default_enabled: false
...@@ -384,11 +384,14 @@ module EE ...@@ -384,11 +384,14 @@ module EE
private private
def elasticsearch_limited_project_exists?(project) def elasticsearch_limited_project_exists?(project)
indexed_namespaces = ::Gitlab::ObjectHierarchy project_namespaces = ::Namespace.where(id: project.namespace_id)
.new(::Namespace.where(id: project.namespace_id)) indexed_namespaces = if ::Feature.enabled?(:linear_application_setting_ancestor_scopes, default_enabled: :yaml)
.base_and_ancestors project_namespaces.self_and_ancestors
.joins(:elasticsearch_indexed_namespace) else
::Gitlab::ObjectHierarchy.new(project_namespaces).base_and_ancestors
end
indexed_namespaces = indexed_namespaces.joins(:elasticsearch_indexed_namespace)
indexed_namespaces = ::Project.where('EXISTS (?)', indexed_namespaces) indexed_namespaces = ::Project.where('EXISTS (?)', indexed_namespaces)
indexed_projects = ::Project.where('EXISTS (?)', ElasticsearchIndexedProject.where(project_id: project.id)) indexed_projects = ::Project.where('EXISTS (?)', ElasticsearchIndexedProject.where(project_id: project.id))
......
...@@ -427,31 +427,43 @@ RSpec.describe ApplicationSetting do ...@@ -427,31 +427,43 @@ RSpec.describe ApplicationSetting do
end end
describe '#elasticsearch_indexes_project?' do describe '#elasticsearch_indexes_project?' do
context 'when project is in a subgroup' do shared_examples 'whether the project is indexed' do
let(:root_group) { create(:group) } context 'when project is in a subgroup' do
let(:subgroup) { create(:group, parent: root_group) } let(:root_group) { create(:group) }
let(:project) { create(:project, group: subgroup) } let(:subgroup) { create(:group, parent: root_group) }
let(:project) { create(:project, group: subgroup) }
before do
create(:elasticsearch_indexed_namespace, namespace: root_group) before do
create(:elasticsearch_indexed_namespace, namespace: root_group)
end
it 'allows project to be indexed' do
expect(setting.elasticsearch_indexes_project?(project)).to be(true)
end
end end
it 'allows project to be indexed' do context 'when project is in a namespace' do
expect(setting.elasticsearch_indexes_project?(project)).to be(true) let(:namespace) { create(:namespace) }
let(:project) { create(:project, namespace: namespace) }
before do
create(:elasticsearch_indexed_namespace, namespace: namespace)
end
it 'allows project to be indexed' do
expect(setting.elasticsearch_indexes_project?(project)).to be(true)
end
end end
end end
context 'when project is in a namespace' do it_behaves_like 'whether the project is indexed'
let(:namespace) { create(:namespace) }
let(:project) { create(:project, namespace: namespace) }
context 'when feature flag :linear_application_setting_ancestor_scopes is disabled' do
before do before do
create(:elasticsearch_indexed_namespace, namespace: namespace) stub_feature_flags(linear_application_setting_ancestor_scopes: false)
end end
it 'allows project to be indexed' do it_behaves_like 'whether the project is indexed'
expect(setting.elasticsearch_indexes_project?(project)).to be(true)
end
end 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