Commit 309a0ac5 authored by David Kim's avatar David Kim

Merge branch '340716-add-option-to-require-login-for-issue-and-merge-request-search' into 'master'

Add option to require login for any filtering workflow (issues, merge requests, epics,  dashboards)

See merge request gitlab-org/gitlab!70223
parents ef92ff22 c1d87cb1
...@@ -332,6 +332,7 @@ class IssuableFinder ...@@ -332,6 +332,7 @@ class IssuableFinder
def by_search(items) def by_search(items)
return items unless search return items unless search
return items if items.is_a?(ActiveRecord::NullRelation) return items if items.is_a?(ActiveRecord::NullRelation)
return items if Feature.enabled?(:disable_anonymous_search, type: :ops) && current_user.nil?
if use_cte_for_search? if use_cte_for_search?
cte = Gitlab::SQL::CTE.new(klass.table_name, items) cte = Gitlab::SQL::CTE.new(klass.table_name, items)
......
---
name: disable_anonymous_search
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70223
rollout_issue_url:
milestone: '14.3'
type: ops
group: group::project management
default_enabled: false
...@@ -90,6 +90,35 @@ RSpec.describe EpicsFinder do ...@@ -90,6 +90,35 @@ RSpec.describe EpicsFinder do
it 'returns all epics that match the search' do it 'returns all epics that match the search' do
expect(epics(search: 'awesome')).to contain_exactly(epic1, epic3) expect(epics(search: 'awesome')).to contain_exactly(epic1, epic3)
end end
context 'with anonymous user' do
let_it_be(:public_group) { create(:group, :public) }
let_it_be(:epic5) { create(:epic, group: public_group, title: 'tanuki') }
let_it_be(:epic6) { create(:epic, group: public_group, title: 'ikunat') }
let(:search_user) { nil }
let(:params) { { group_id: public_group.id, search: 'tanuki' } }
context 'with disable_anonymous_search feature flag enabled' do
before do
stub_feature_flags(disable_anonymous_search: true)
end
it 'does not perform search' do
expect(epics(params)).to contain_exactly(epic5, epic6)
end
end
context 'with disable_anonymous_search feature flag disabled' do
before do
stub_feature_flags(disable_anonymous_search: false)
end
it 'returns matching epics' do
expect(epics(params)).to contain_exactly(epic5)
end
end
end
end end
context 'by user reaction emoji' do context 'by user reaction emoji' do
......
...@@ -567,6 +567,35 @@ RSpec.describe IssuesFinder do ...@@ -567,6 +567,35 @@ RSpec.describe IssuesFinder do
it 'returns issues with title and description match for search term' do it 'returns issues with title and description match for search term' do
expect(issues).to contain_exactly(issue1, issue2) expect(issues).to contain_exactly(issue1, issue2)
end end
context 'with anonymous user' do
let_it_be(:public_project) { create(:project, :public, group: subgroup) }
let_it_be(:issue6) { create(:issue, project: public_project, title: 'tanuki') }
let_it_be(:issue7) { create(:issue, project: public_project, title: 'ikunat') }
let(:search_user) { nil }
let(:params) { { search: 'tanuki' } }
context 'with disable_anonymous_search feature flag enabled' do
before do
stub_feature_flags(disable_anonymous_search: true)
end
it 'does not perform search' do
expect(issues).to contain_exactly(issue6, issue7)
end
end
context 'with disable_anonymous_search feature flag disabled' do
before do
stub_feature_flags(disable_anonymous_search: false)
end
it 'finds one public issue' do
expect(issues).to contain_exactly(issue6)
end
end
end
end end
context 'filtering by issue term in title' do context 'filtering by issue term in title' do
......
...@@ -729,6 +729,36 @@ RSpec.describe MergeRequestsFinder do ...@@ -729,6 +729,36 @@ RSpec.describe MergeRequestsFinder do
merge_requests = described_class.new(user, params).execute merge_requests = described_class.new(user, params).execute
expect { merge_requests.load }.not_to raise_error expect { merge_requests.load }.not_to raise_error
end end
context 'filtering by search text' do
let!(:merge_request6) { create(:merge_request, source_project: project1, target_project: project1, source_branch: 'tanuki-branch', title: 'tanuki') }
let(:params) { { project_id: project1.id, search: 'tanuki' } }
context 'with anonymous user' do
let(:merge_requests) { described_class.new(nil, params).execute }
context 'with disable_anonymous_search feature flag enabled' do
before do
stub_feature_flags(disable_anonymous_search: true)
end
it 'does not perform search' do
expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request6)
end
end
context 'with disable_anonymous_search feature flag disabled' do
before do
stub_feature_flags(disable_anonymous_search: false)
end
it 'returns matching merge requests' do
expect(merge_requests).to contain_exactly(merge_request6)
end
end
end
end
end end
describe '#row_count', :request_store do describe '#row_count', :request_store do
......
...@@ -305,6 +305,9 @@ RSpec.configure do |config| ...@@ -305,6 +305,9 @@ RSpec.configure do |config|
# For more information check https://gitlab.com/gitlab-com/gl-infra/production/-/issues/4321 # For more information check https://gitlab.com/gitlab-com/gl-infra/production/-/issues/4321
stub_feature_flags(block_issue_repositioning: false) stub_feature_flags(block_issue_repositioning: false)
# This is an ops feature flag that's disabled by default
stub_feature_flags(disable_anonymous_search: false)
# Disable the refactored top nav search until there is functionality # Disable the refactored top nav search until there is functionality
# Can be removed once all existing functionality has been replicated # Can be removed once all existing functionality has been replicated
# For more information check https://gitlab.com/gitlab-org/gitlab/-/issues/339348 # For more information check https://gitlab.com/gitlab-org/gitlab/-/issues/339348
......
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