diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 764613b0a8c9bd43df5f75d3cb2797f3684c8929..906492003ac81dfc68d84e3aa872d7c72e44709c 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -108,18 +108,12 @@ 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) - when 'commits' - Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) when 'issues' 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' Feature.enabled?(:global_search_users_tab, current_user, type: :ops) else diff --git a/ee/app/services/ee/search_service.rb b/ee/app/services/ee/search_service.rb index de21065815f196532809025fdd7bd3b9ff62c4ac..83155952e691402a4b37d12474dd6bafbea72f74 100644 --- a/ee/app/services/ee/search_service.rb +++ b/ee/app/services/ee/search_service.rb @@ -44,8 +44,14 @@ def use_zoekt? override :global_search_enabled_for_scope? def global_search_enabled_for_scope? case params[:scope] + when 'blobs' + ::Feature.enabled?(:global_search_code_tab, current_user, type: :ops) + when 'commits' + ::Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) when 'epics' ::Feature.enabled?(:global_search_epics_tab, current_user, type: :ops) + when 'wiki_blobs' + ::Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) else super end diff --git a/config/feature_flags/ops/global_search_code_tab.yml b/ee/config/feature_flags/ops/global_search_code_tab.yml similarity index 100% rename from config/feature_flags/ops/global_search_code_tab.yml rename to ee/config/feature_flags/ops/global_search_code_tab.yml diff --git a/config/feature_flags/ops/global_search_epics_tab.yml b/ee/config/feature_flags/ops/global_search_epics_tab.yml similarity index 100% rename from config/feature_flags/ops/global_search_epics_tab.yml rename to ee/config/feature_flags/ops/global_search_epics_tab.yml diff --git a/config/feature_flags/ops/global_search_wiki_tab.yml b/ee/config/feature_flags/ops/global_search_wiki_tab.yml similarity index 100% rename from config/feature_flags/ops/global_search_wiki_tab.yml rename to ee/config/feature_flags/ops/global_search_wiki_tab.yml diff --git a/ee/spec/controllers/ee/search_controller_spec.rb b/ee/spec/controllers/ee/search_controller_spec.rb index af3f38950a8b3d7eeeaa2b28ff6081ae8aee6001..955c275c4ff98a14f0058e33712e71b413d05640 100644 --- a/ee/spec/controllers/ee/search_controller_spec.rb +++ b/ee/spec/controllers/ee/search_controller_spec.rb @@ -197,6 +197,37 @@ end end end + + context 'for tab feature flags' do + using RSpec::Parameterized::TableSyntax + + subject(:show) { get :show, params: { scope: scope, search: 'term' }, format: :html } + + where(:feature_flag, :scope) do + :global_search_code_tab | 'blobs' + :global_search_commits_tab | 'commits' + :global_search_wiki_tab | 'wiki_blobs' + end + + with_them do + it 'returns 200 if flag is enabled' do + stub_feature_flags(feature_flag => true) + + show + + expect(response).to have_gitlab_http_status(:ok) + end + + it 'redirects with alert if flag is disabled' do + stub_feature_flags(feature_flag => false) + + show + + 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 describe 'GET #autocomplete' do diff --git a/ee/spec/services/search_service_spec.rb b/ee/spec/services/search_service_spec.rb index c86ae6a195c98f6bd21ae015b09a4157babab6b2..b3367a6d9cb35e354a325b77684316354e344677 100644 --- a/ee/spec/services/search_service_spec.rb +++ b/ee/spec/services/search_service_spec.rb @@ -110,8 +110,14 @@ let(:search) { 'foobar' } where(:scope, :feature_flag, :enabled, :expected) do + 'blobs' | :global_search_code_tab | false | false + 'blobs' | :global_search_code_tab | true | true + 'commits' | :global_search_commits_tab | false | false + 'commits' | :global_search_commits_tab | true | true 'epics' | :global_search_epics_tab | false | false 'epics' | :global_search_epics_tab | true | true + 'wiki_blobs' | :global_search_wiki_tab | false | false + 'wiki_blobs' | :global_search_wiki_tab | true | true end with_them do diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index ea26f43684fb9dc9079278d5219b51476059b550..47c9626711e5d4735185d4b5f800feddff974d2c 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -267,15 +267,12 @@ end end - context 'tab feature flags' do - subject { get :show, params: { scope: scope, search: 'term' }, format: :html } + context 'for tab feature flags' do + subject(:show) { 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' :global_search_users_tab | 'users' end @@ -283,7 +280,7 @@ it 'returns 200 if flag is enabled' do stub_feature_flags(feature_flag => true) - subject + show expect(response).to have_gitlab_http_status(:ok) end @@ -291,7 +288,7 @@ it 'redirects with alert if flag is disabled' do stub_feature_flags(feature_flag => false) - subject + show expect(response).to redirect_to search_path expect(controller).to set_flash[:alert].to(/Global Search is disabled for this scope/) diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index 47a19e16e4e7c7e7182707fca04a06ecd9fb63b8..6fab16f72d846d4891703de068d6a37caf50dd15 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -490,18 +490,12 @@ let(:search) { 'foobar' } where(:scope, :feature_flag, :enabled, :expected) do - 'blobs' | :global_search_code_tab | false | false - 'blobs' | :global_search_code_tab | true | true - 'commits' | :global_search_commits_tab | false | false - 'commits' | :global_search_commits_tab | true | true 'issues' | :global_search_issues_tab | false | false '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 'users' | :global_search_users_tab | true | true 'random' | :random | nil | true