Skip to content
代码片段 群组 项目
提交 4f0628d3 编辑于 作者: Terri Chu's avatar Terri Chu
浏览文件

Merge branch '434219-add-allow-anonymous-searches-ff' into 'master'

Add allow_anonymous_searches feature flag

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138975



Merged-by: default avatarTerri Chu <tchu@gitlab.com>
Approved-by: default avatarRavi Kumar <rkumar@gitlab.com>
Approved-by: default avatarTerri Chu <tchu@gitlab.com>
Reviewed-by: default avatarTerri Chu <tchu@gitlab.com>
Co-authored-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -27,7 +27,10 @@ def self.search_rate_limited_endpoints ...@@ -27,7 +27,10 @@ def self.search_rate_limited_endpoints
around_action :allow_gitaly_ref_name_caching around_action :allow_gitaly_ref_name_caching
before_action :block_anonymous_global_searches, :check_scope_global_search_enabled, except: :opensearch before_action :block_all_anonymous_searches,
:block_anonymous_global_searches,
:check_scope_global_search_enabled,
except: :opensearch
skip_before_action :authenticate_user! skip_before_action :authenticate_user!
requires_cross_project_access if: -> do requires_cross_project_access if: -> do
...@@ -226,6 +229,14 @@ def block_anonymous_global_searches ...@@ -226,6 +229,14 @@ def block_anonymous_global_searches
redirect_to new_user_session_path, alert: _('You must be logged in to search across all of GitLab') redirect_to new_user_session_path, alert: _('You must be logged in to search across all of GitLab')
end end
def block_all_anonymous_searches
return if current_user || ::Feature.enabled?(:allow_anonymous_searches, type: :ops)
store_location_for(:user, request.fullpath)
redirect_to new_user_session_path, alert: _('You must be logged in to search')
end
def check_scope_global_search_enabled def check_scope_global_search_enabled
return unless search_service.global_search? return unless search_service.global_search?
......
---
name: allow_anonymous_searches
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138975
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/434218
milestone: '16.7'
type: ops
group: group::global search
default_enabled: true
...@@ -55983,6 +55983,9 @@ msgstr "" ...@@ -55983,6 +55983,9 @@ msgstr ""
msgid "You must be authenticated to access this path." msgid "You must be authenticated to access this path."
msgstr "" msgstr ""
   
msgid "You must be logged in to search"
msgstr ""
msgid "You must be logged in to search across all of GitLab" msgid "You must be logged in to search across all of GitLab"
msgstr "" msgstr ""
   
...@@ -189,6 +189,25 @@ ...@@ -189,6 +189,25 @@
end end
end end
context 'when allow_anonymous_searches is disabled' do
before do
stub_feature_flags(allow_anonymous_searches: false)
end
context 'for unauthenticated user' do
before do
sign_out(user)
end
it 'redirects to login page' do
get :show, params: { scope: 'projects', search: '*' }
expect(response).to redirect_to new_user_session_path
expect(flash[:alert]).to match(/You must be logged in/)
end
end
end
context 'tab feature flags' do context 'tab feature flags' do
subject { get :show, params: { scope: scope, search: 'term' }, format: :html } subject { get :show, params: { scope: scope, search: 'term' }, format: :html }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册