diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 1d58239aea93133f7151c690212778026173c28a..fb79cf5ffb93978c43c0bb348ab2041eb135c3f8 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -493,6 +493,10 @@ def show_comments_search_tab? @project.nil? && search_service.show_elasticsearch_tabs? end + def show_snippets_search_tab? + search_service.show_snippets? && @project.nil? && feature_flag_tab_enabled?(:global_search_snippet_titles_tab) + end + # search page scope navigation def search_navigation { @@ -506,7 +510,7 @@ def search_navigation notes: { sort: 8, label: _("Comments"), condition: show_comments_search_tab? }, milestones: { sort: 9, label: _("Milestones"), condition: project_search_tabs?(:milestones) || @project.nil? }, users: { sort: 10, label: _("Users"), condition: show_user_search_tab? }, - snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: search_service.show_snippets? && @project.nil? } + snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: show_snippets_search_tab? } } end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 7fca6ed7a20b240bc12365d55ca6546d01883d3e..5705e4c7cef0ee925189fa42755e7789b3b0d95b 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -113,6 +113,8 @@ def show_epics? end def global_search_enabled_for_scope? + return false if show_snippets? && Feature.disabled?(:global_search_snippet_titles_tab, current_user, type: :ops) + case params[:scope] when 'blobs' Feature.enabled?(:global_search_code_tab, current_user, type: :ops) @@ -122,6 +124,8 @@ def global_search_enabled_for_scope? Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) when 'merge_requests' Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) + when 'snippet_titles' + Feature.enabled?(:global_search_snippet_titles_tab, current_user, type: :ops) when 'wiki_blobs' Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) when 'users' diff --git a/config/feature_flags/ops/global_search_snippet_titles_tab.yml b/config/feature_flags/ops/global_search_snippet_titles_tab.yml new file mode 100644 index 0000000000000000000000000000000000000000..e0b7422e0f3a4d81a4f32b01be6113e6aba6f7f8 --- /dev/null +++ b/config/feature_flags/ops/global_search_snippet_titles_tab.yml @@ -0,0 +1,8 @@ +--- +name: global_search_snippet_titles_tab +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123668 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/415353 +milestone: '16.1' +type: ops +group: group::global search +default_enabled: true diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 99ef8a8de08d398bad8e45182ad3236cb92fd596..94c121b7c399f0bfcf5328f183ece256c4544dd7 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -1259,16 +1259,22 @@ def simple_sanitize(str) end context 'snippet_titles' do - where(:global_project, :global_show_snippets, :condition) do - ref(:project) | true | false - nil | false | false - ref(:project) | false | false - nil | true | true + where(:global_project, :global_show_snippets, :global_feature_flag_enabled, :condition) do + ref(:project) | true | false | false + nil | false | false | false + ref(:project) | false | false | false + nil | true | false | false + ref(:project) | true | true | false + nil | false | true | false + ref(:project) | false | true | false + nil | true | true | true end with_them do it 'data item condition is set correctly' do allow(search_service).to receive(:show_snippets?).and_return(global_show_snippets) + allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_snippet_titles_tab) + .and_return(global_feature_flag_enabled) @project = global_project expect(search_navigation[:snippet_titles][:condition]).to eq(condition) diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index a315bca58d1fa9d8d60d076975106dc10fc2ab0d..1b331e9c0992d77db899b1f8a3e7a239f1e75171 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -412,6 +412,22 @@ end end + context 'global snippet search is disabled' do + it 'returns forbidden response' do + stub_feature_flags(global_search_snippet_titles_tab: false) + get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'global snippet search is enabled' do + it 'returns ok response' do + stub_feature_flags(global_search_snippet_titles_tab: true) + get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } + expect(response).to have_gitlab_http_status(:ok) + end + end + it 'increments the custom search sli error rate with error false if no error occurred' do expect(Gitlab::Metrics::GlobalSearchSlis).to receive(:record_error_rate).with( error: false, diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index d11fc377d835edafc070b00b908a4ef0cde2609e..c937a93c6ef05aa20b3523f8219485e40678b26b 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -485,6 +485,8 @@ 'issues' | :global_search_issues_tab | true | true 'merge_requests' | :global_search_merge_requests_tab | false | false 'merge_requests' | :global_search_merge_requests_tab | true | true + 'snippet_titles' | :global_search_snippet_titles_tab | false | false + 'snippet_titles' | :global_search_snippet_titles_tab | true | true 'wiki_blobs' | :global_search_wiki_tab | false | false 'wiki_blobs' | :global_search_wiki_tab | true | true 'users' | :global_search_users_tab | false | false @@ -498,5 +500,25 @@ expect(subject.global_search_enabled_for_scope?).to eq expected end end + + context 'when snippet search is enabled' do + let(:scope) { 'snippet_titles' } + + before do + allow(described_class).to receive(:show_snippets?).and_return(true) + end + + it 'returns false when feature_flag is not enabled' do + stub_feature_flags(global_search_snippet_titles_tab: false) + + expect(subject.global_search_enabled_for_scope?).to eq false + end + + it 'returns true when feature_flag is enabled' do + stub_feature_flags(global_search_snippet_titles_tab: true) + + expect(subject.global_search_enabled_for_scope?).to eq true + end + end end end