Commit bfbf3c53 authored by Marcia Ramos's avatar Marcia Ramos

Merge branch '338902-add-global-tabs-feature-flags' into 'master'

Advanced Search: Create feature flags to disable some tabs

See merge request gitlab-org/gitlab!68640
parents 2c9c37e7 ecf94981
...@@ -11,7 +11,7 @@ class SearchController < ApplicationController ...@@ -11,7 +11,7 @@ class SearchController < ApplicationController
around_action :allow_gitaly_ref_name_caching around_action :allow_gitaly_ref_name_caching
before_action :block_anonymous_global_searches, except: :opensearch before_action :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
search_term_present = params[:search].present? || params[:term].present? search_term_present = params[:search].present? || params[:term].present?
...@@ -156,6 +156,29 @@ class SearchController < ApplicationController ...@@ -156,6 +156,29 @@ class SearchController < ApplicationController
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 check_scope_global_search_enabled
return if params[:project_id].present? || params[:group_id].present?
search_allowed = case params[:scope]
when 'blobs'
Feature.enabled?(:global_search_code_tab, current_user, type: :ops, default_enabled: true)
when 'commits'
Feature.enabled?(:global_search_commits_tab, current_user, type: :ops, default_enabled: true)
when 'issues'
Feature.enabled?(:global_search_issues_tab, current_user, type: :ops, default_enabled: true)
when 'merge_requests'
Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops, default_enabled: true)
when 'wiki_blobs'
Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops, default_enabled: true)
else
true
end
return if search_allowed
redirect_to search_path, alert: _('Global Search is disabled for this scope')
end
def render_timeout(exception) def render_timeout(exception)
raise exception unless action_name.to_sym.in?(RESCUE_FROM_TIMEOUT_ACTIONS) raise exception unless action_name.to_sym.in?(RESCUE_FROM_TIMEOUT_ACTIONS)
......
...@@ -443,6 +443,10 @@ module SearchHelper ...@@ -443,6 +443,10 @@ module SearchHelper
_("Open") _("Open")
end end
end end
def feature_flag_tab_enabled?(flag)
@group || Feature.enabled?(flag, current_user, type: :ops, default_enabled: true)
end
end end
SearchHelper.prepend_mod_with('SearchHelper') SearchHelper.prepend_mod_with('SearchHelper')
...@@ -27,11 +27,11 @@ ...@@ -27,11 +27,11 @@
= search_filter_link 'snippet_titles', _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil } = search_filter_link 'snippet_titles', _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }
- else - else
= search_filter_link 'projects', _("Projects"), data: { qa_selector: 'projects_tab' } = search_filter_link 'projects', _("Projects"), data: { qa_selector: 'projects_tab' }
= render_if_exists 'search/category_code' = render_if_exists 'search/category_code' if feature_flag_tab_enabled?(:global_search_code_tab)
= render_if_exists 'search/epics_filter_link' = render_if_exists 'search/epics_filter_link'
= search_filter_link 'issues', _("Issues") = search_filter_link 'issues', _("Issues") if feature_flag_tab_enabled?(:global_search_issues_tab)
= search_filter_link 'merge_requests', _("Merge requests") = search_filter_link 'merge_requests', _("Merge requests") if feature_flag_tab_enabled?(:global_search_merge_requests_tab)
= render_if_exists 'search/category_wiki' = render_if_exists 'search/category_wiki' if feature_flag_tab_enabled?(:global_search_wiki_tab)
= render_if_exists 'search/category_elasticsearch' = render_if_exists 'search/category_elasticsearch'
= search_filter_link 'milestones', _("Milestones") = search_filter_link 'milestones', _("Milestones")
= users = users
---
name: global_search_code_tab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339207
milestone: '14.3'
type: ops
group: group::global search
default_enabled: true
---
name: global_search_commits_tab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339207
milestone: '14.3'
type: ops
group: group::global search
default_enabled: true
---
name: global_search_issues_tab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339207
milestone: '14.3'
type: ops
group: group::global search
default_enabled: true
---
name: global_search_merge_requests_tab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339207
milestone: '14.3'
type: ops
group: group::global search
default_enabled: true
---
name: global_search_wiki_tab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339207
milestone: '14.3'
type: ops
group: group::global search
default_enabled: true
...@@ -119,3 +119,24 @@ You can search a specific issue or merge request by its ID with a special prefix ...@@ -119,3 +119,24 @@ You can search a specific issue or merge request by its ID with a special prefix
- To search by issue ID, use prefix `#` followed by issue ID. For example, [#23456](https://gitlab.com/search?snippets=&scope=issues&repository_ref=&search=%2323456&group_id=9970&project_id=278964) - To search by issue ID, use prefix `#` followed by issue ID. For example, [#23456](https://gitlab.com/search?snippets=&scope=issues&repository_ref=&search=%2323456&group_id=9970&project_id=278964)
- To search by merge request ID, use prefix `!` followed by merge request ID. For example [!23456](https://gitlab.com/search?snippets=&scope=merge_requests&repository_ref=&search=%2123456&group_id=9970&project_id=278964) - To search by merge request ID, use prefix `!` followed by merge request ID. For example [!23456](https://gitlab.com/search?snippets=&scope=merge_requests&repository_ref=&search=%2123456&group_id=9970&project_id=278964)
## Global search scopes **(FREE SELF)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68640) in GitLab 14.3.
To improve the performance of your instance's global search, you can limit
the scope of the search. To do so, you can exclude global search scopes by disabling
[`ops` feature flags](../../development/feature_flags/index.md#ops-type).
Global search has all its scopes **enabled** by default in GitLab SaaS and
self-managed instances. A GitLab administrator can disable the following `ops`
feature flags to limit the scope of your instance's global search and optimize
its performance:
| Scope | Feature flag | Description |
|--|--|--|
| Code | `global_search_code_tab` | When enabled, the global search includes code as part of the search. |
| Commits | `global_search_commits_tab` | When enabled, the global search includes commits as part of the search. |
| Issues | `global_search_issues_tab` | When enabled, the global search includes issues as part of the search. |
| Merge Requests | `global_search_merge_requests_tab` | When enabled, the global search includes merge requests as part of the search. |
| Wiki | `global_search_wiki_tab` | When enabled, the global search includes wiki as part of the search. |
- if search_service.show_elasticsearch_tabs? - if search_service.show_elasticsearch_tabs?
= search_filter_link 'commits', _("Commits") = search_filter_link 'commits', _("Commits") if feature_flag_tab_enabled?(:global_search_commits_tab)
= search_filter_link 'notes', _("Comments") = search_filter_link 'notes', _("Comments")
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'search/_category' do
let_it_be(:group) { create(:group) }
context 'feature flags' do
using RSpec::Parameterized::TableSyntax
before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end
where(:feature_flag, :tab_name) do
:global_search_code_tab | 'Code'
:global_search_issues_tab | 'Issues'
:global_search_merge_requests_tab | 'Merge requests'
:global_search_wiki_tab | 'Wiki'
:global_search_commits_tab | 'Commits'
end
with_them do
context 'global search' do
it 'shows the tab if FF is enabled' do
stub_feature_flags(feature_flag => true)
render
expect(rendered).to have_selector('.nav-tabs li', text: tab_name)
end
it 'hides the tab if FF is disabled' do
stub_feature_flags(feature_flag => false)
render
expect(rendered).not_to have_selector('.nav-tabs li', text: tab_name)
end
end
context 'group search' do
before do
assign(:group, group)
end
it 'shows the tab even if FF is disabled for group search' do
stub_feature_flags(feature_flag => false)
render
expect(rendered).to have_selector('.nav-tabs li', text: tab_name)
end
end
end
end
end
...@@ -15488,6 +15488,9 @@ msgstr "" ...@@ -15488,6 +15488,9 @@ msgstr ""
msgid "Given epic is already related to this epic." msgid "Given epic is already related to this epic."
msgstr "" msgstr ""
msgid "Global Search is disabled for this scope"
msgstr ""
msgid "Global Shortcuts" msgid "Global Shortcuts"
msgstr "" msgstr ""
......
...@@ -182,6 +182,37 @@ RSpec.describe SearchController do ...@@ -182,6 +182,37 @@ RSpec.describe SearchController do
end end
end end
end end
context 'tab feature flags' do
subject { get :show, params: { scope: scope, search: 'term' }, format: :html }
where(:feature_flag, :scope) do
:global_search_code_tab | 'blobs'
:global_search_issues_tab | 'issues'
:global_search_merge_requests_tab | 'merge_requests'
:global_search_wiki_tab | 'wiki_blobs'
:global_search_commits_tab | 'commits'
end
with_them do
it 'returns 200 if flag is enabled' do
stub_feature_flags(feature_flag => true)
subject
expect(response).to have_gitlab_http_status(:ok)
end
it 'redirects with alert if flag is disabled' do
stub_feature_flags(feature_flag => false)
subject
expect(response).to redirect_to search_path
expect(controller).to set_flash[:alert].to(/Global Search is disabled for this scope/)
end
end
end
end end
it 'finds issue comments' do it 'finds issue comments' do
......
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