From 3bd1160e2cae0d1f771950b8fe1a68d3d9a1f9a4 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 17:19:58 +0530 Subject: [PATCH 01/21] Add changes for removing the _tab ff --- app/helpers/application_settings_helper.rb | 31 ++++++++++++- app/helpers/search_helper.rb | 2 +- app/services/search_service.rb | 10 ++--- .../_global_search_settings.html.haml | 15 +++++++ .../application_settings/search.html.haml | 7 +++ config/routes/admin.rb | 2 +- ...search_settings_in_application_settings.rb | 44 +++++++++++++++++++ db/schema_migrations/20250109055316 | 1 + .../helpers/ee/application_settings_helper.rb | 33 +++++++++++++- ee/app/services/ee/search_service.rb | 8 ++-- .../application_settings/search.html.haml | 1 + ee/lib/ee/search/navigation.rb | 8 ++-- .../admin/menus/admin_settings_menu.rb | 13 ------ .../ee/application_settings_helper_spec.rb | 44 +++++++++++++++++++ ee/spec/lib/search/navigation_spec.rb | 29 ++++++------ .../api/graphql/search/blob_search_spec.rb | 2 +- ee/spec/services/search_service_spec.rb | 20 ++++----- lib/search/navigation.rb | 8 ++-- .../admin/menus/admin_settings_menu.rb | 11 +++++ locale/gitlab.pot | 30 +++++++++++++ spec/controllers/search_controller_spec.rb | 12 ++--- .../application_settings_helper_spec.rb | 32 ++++++++++++++ spec/helpers/search_helper_spec.rb | 8 ++-- spec/lib/search/navigation_spec.rb | 19 ++++---- ...h_settings_in_application_settings_spec.rb | 44 +++++++++++++++++++ spec/requests/api/search_spec.rb | 4 +- spec/services/search_service_spec.rb | 26 +++++------ 27 files changed, 368 insertions(+), 96 deletions(-) create mode 100644 app/views/admin/application_settings/_global_search_settings.html.haml create mode 100644 app/views/admin/application_settings/search.html.haml create mode 100644 db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb create mode 100644 db/schema_migrations/20250109055316 create mode 100644 spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 6b8cd2b029ee21..75741f2d4a24fe 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -72,6 +72,31 @@ def enabled_protocol_button(container, protocol) end end + def global_search_settings_checkboxes(form) + [ + form.gitlab_ui_checkbox_component( + :global_search_issues_enabled, + _("Enable issues tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_issues_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_merge_requests_enabled, + _("Enable merge requests tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_merge_requests_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_snippet_titles_enabled, + _("Enable snippet tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_snippet_titles_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_users_enabled, + _("Enable users tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_users_enabled, multiple: false } + ) + ] + end + def restricted_level_checkboxes(form) restricted_visibility_levels_help_text = { Gitlab::VisibilityLevel::PUBLIC => s_( @@ -544,7 +569,11 @@ def visible_attributes :require_personal_access_token_expiry, :observability_backend_ssl_verification_enabled, :show_migrate_from_jenkins_banner, - :ropc_without_client_credentials + :ropc_without_client_credentials, + :global_search_snippet_titles_enabled, + :global_search_users_enabled, + :global_search_issues_enabled, + :global_search_merge_requests_enabled ].tap do |settings| unless Gitlab.com? settings << :resource_usage_limits diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 197313c3ff90a3..b58bead78d69ef 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -428,7 +428,7 @@ def projects_autocomplete(term, limit = 5) def users_autocomplete(term, limit = 5) unless current_user && Ability.allowed?(current_user, :read_users_list) && - Feature.enabled?(:global_search_users_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_users_enabled? return [] end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 906492003ac81d..a61788818a8230 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -105,17 +105,17 @@ def level end def global_search_enabled_for_scope? - return false if show_snippets? && Feature.disabled?(:global_search_snippet_titles_tab, current_user, type: :ops) + return false if show_snippets? && !::Gitlab::CurrentSettings.global_search_snippet_titles_enabled? case params[:scope] when 'issues' - Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_issues_enabled? when 'merge_requests' - Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_merge_requests_enabled? when 'snippet_titles' - Feature.enabled?(:global_search_snippet_titles_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_snippet_titles_enabled? when 'users' - Feature.enabled?(:global_search_users_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_users_enabled? else true end diff --git a/app/views/admin/application_settings/_global_search_settings.html.haml b/app/views/admin/application_settings/_global_search_settings.html.haml new file mode 100644 index 00000000000000..185bc4035b3b16 --- /dev/null +++ b/app/views/admin/application_settings/_global_search_settings.html.haml @@ -0,0 +1,15 @@ += render ::Layouts::SettingsBlockComponent.new(_('Global Search'), + id: 'js-global-search-settings', + testid: 'admin-global-search-settings', + expanded: expanded_by_default?) do |c| + - c.with_description do + = _('Configure settings for global search.') + = link_to _('Learn more.'), help_page_path('user/search/index.md', anchor: 'global-search-scopes'), target: '_blank', rel: 'noopener noreferrer' + - c.with_body do + = gitlab_ui_form_for @application_setting, url: general_admin_application_settings_path(anchor: 'js-global-search-settings'), html: { class: 'fieldset-form', id: 'global-search-settings' } do |f| + = form_errors(@application_setting) + %fieldset + .form-group + - global_search_settings_checkboxes(f).each do |checkbox| + = checkbox + = f.submit _('Save changes'), pajamas_button: true diff --git a/app/views/admin/application_settings/search.html.haml b/app/views/admin/application_settings/search.html.haml new file mode 100644 index 00000000000000..d1d3c21aca00c1 --- /dev/null +++ b/app/views/admin/application_settings/search.html.haml @@ -0,0 +1,7 @@ +- breadcrumb_title _("Search") +- page_title _("Search") +- add_page_specific_style 'page_bundles/settings' +- add_page_specific_style 'page_bundles/search' +- @force_desktop_expanded_sidebar = true + += render_if_exists 'admin/application_settings/global_search_settings' diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c54397860e60a4..a00f316e85cd0d 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -168,7 +168,7 @@ put :reset_health_check_token put :reset_error_tracking_access_token put :clear_repository_check_states - match :general, :integrations, :repository, :ci_cd, :reporting, :metrics_and_profiling, :network, :preferences, via: [:get, :patch] + match :general, :integrations, :repository, :ci_cd, :reporting, :metrics_and_profiling, :network, :preferences, :search, via: [:get, :patch] get :lets_encrypt_terms_of_service get :slack_app_manifest_download, format: :json get :slack_app_manifest_share diff --git a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb new file mode 100644 index 00000000000000..39b8db1d33dfa8 --- /dev/null +++ b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class MigrateGlobalSearchSettingsInApplicationSettings < Gitlab::Database::Migration[2.2] + restrict_gitlab_migration gitlab_schema: :gitlab_main + milestone '17.9' + + class ApplicationSetting < MigrationRecord + self.table_name = 'application_settings' + end + + def up + ApplicationSetting.reset_column_information + + application_setting = ApplicationSetting.last + return if application_setting.nil? + + # rubocop:disable Gitlab/FeatureFlagWithoutActor -- Does not execute in user context + search = { + global_search_issues_enabled: Feature.enabled?(:global_search_issues_tab, type: :ops), + global_search_merge_requests_enabled: Feature.enabled?(:global_search_merge_requests_tab, type: :ops), + global_search_snippet_titles_enabled: Feature.enabled?(:global_search_snippet_titles_tab, type: :ops), + global_search_users_enabled: Feature.enabled?(:global_search_users_tab, type: :ops) + } + + if Gitlab.ee? + search.merge!( + global_search_code_enabled: Feature.enabled?(:global_search_code_tab, type: :ops), + global_search_commits_enabled: Feature.enabled?(:global_search_commits_tab, type: :ops), + global_search_epics_enabled: Feature.enabled?(:global_search_epics_tab, type: :ops), + global_search_wiki_enabled: Feature.enabled?(:global_search_wiki_tab, type: :ops) + ) + end + # rubocop:enable Gitlab/FeatureFlagWithoutActor + + application_setting.update_columns(search: search, updated_at: Time.current) + end + + def down + application_setting = ApplicationSetting.last + return unless application_setting + + application_setting.update_column(:search, {}) + end +end diff --git a/db/schema_migrations/20250109055316 b/db/schema_migrations/20250109055316 new file mode 100644 index 00000000000000..5b6db794f915a7 --- /dev/null +++ b/db/schema_migrations/20250109055316 @@ -0,0 +1 @@ +213fa997d255628cb8f3e3fc6b2098e8fded40aa2eae7593ac5b123b08ff72d8 \ No newline at end of file diff --git a/ee/app/helpers/ee/application_settings_helper.rb b/ee/app/helpers/ee/application_settings_helper.rb index 33b4c93c063d5b..7858e58a0441bc 100644 --- a/ee/app/helpers/ee/application_settings_helper.rb +++ b/ee/app/helpers/ee/application_settings_helper.rb @@ -88,7 +88,12 @@ def visible_attributes :scan_execution_policies_action_limit, :secret_detection_service_auth_token, :secret_detection_service_url, - :fetch_observability_alerts_from_cloud + :fetch_observability_alerts_from_cloud, + :global_search_merge_requests_enabled, + :global_search_code_enabled, + :global_search_commits_enabled, + :global_search_wiki_enabled, + :global_search_epics_enabled ].tap do |settings| settings.concat(identity_verification_attributes) settings.concat(enable_promotion_management_attributes) @@ -265,6 +270,32 @@ def sync_purl_types_checkboxes(form) end end + override :global_search_settings_checkboxes + def global_search_settings_checkboxes(form) + super + [ + form.gitlab_ui_checkbox_component( + :global_search_code_enabled, + _("Enable code tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_code_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_commits_enabled, + _("Enable commits tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_commits_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_epics_enabled, + _("Enable epics tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_epics_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_wiki_enabled, + _("Enable wiki tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_wiki_enabled, multiple: false } + ) + ] + end + def zoekt_settings_checkboxes(form) [ form.gitlab_ui_checkbox_component( diff --git a/ee/app/services/ee/search_service.rb b/ee/app/services/ee/search_service.rb index 83155952e69140..26804e7864fb1d 100644 --- a/ee/app/services/ee/search_service.rb +++ b/ee/app/services/ee/search_service.rb @@ -45,13 +45,13 @@ def use_zoekt? def global_search_enabled_for_scope? case params[:scope] when 'blobs' - ::Feature.enabled?(:global_search_code_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_code_enabled? when 'commits' - ::Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_commits_enabled? when 'epics' - ::Feature.enabled?(:global_search_epics_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_epics_enabled? when 'wiki_blobs' - ::Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_wiki_enabled? else super end diff --git a/ee/app/views/admin/application_settings/search.html.haml b/ee/app/views/admin/application_settings/search.html.haml index c23e51a0e747db..8bb19aa4d1a0b3 100644 --- a/ee/app/views/admin/application_settings/search.html.haml +++ b/ee/app/views/admin/application_settings/search.html.haml @@ -51,3 +51,4 @@ = render_if_exists 'admin/application_settings/elasticsearch_form' = render_if_exists 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) += render_if_exists 'admin/application_settings/global_search_settings' diff --git a/ee/lib/ee/search/navigation.rb b/ee/lib/ee/search/navigation.rb index 7fc6ebf08a98a6..8e0ec0bc2526ff 100644 --- a/ee/lib/ee/search/navigation.rb +++ b/ee/lib/ee/search/navigation.rb @@ -47,7 +47,7 @@ def show_code_search_tab? return true if super return false if project - global_search_code_enabled = ::Feature.enabled?(:global_search_code_tab, user, type: :ops) + global_search_code_enabled = ::Gitlab::CurrentSettings.global_search_code_enabled? global_search_zoekt_enabled = ::Feature.enabled?(:zoekt_cross_namespace_search, user, type: :ops) zoekt_enabled_for_user = zoekt_enabled? && ::Search::Zoekt.enabled_for_user?(user) @@ -72,7 +72,7 @@ def show_wiki_search_tab? return false unless show_elasticsearch_tabs? return true if group - ::Feature.enabled?(:global_search_wiki_tab, user, type: :ops) + ::Gitlab::CurrentSettings.global_search_wiki_enabled? end def show_epics_search_tab? @@ -80,7 +80,7 @@ def show_epics_search_tab? return false unless options[:show_epics] return true if group - ::Feature.enabled?(:global_search_epics_tab, user, type: :ops) + ::Gitlab::CurrentSettings.global_search_epics_enabled? end override :show_commits_search_tab? @@ -89,7 +89,7 @@ def show_commits_search_tab? return false unless show_elasticsearch_tabs? # advanced search enabled return true if group # group search - ::Feature.enabled?(:global_search_commits_tab, user, type: :ops) # global search + ::Gitlab::CurrentSettings.global_search_commits_enabled? end end end diff --git a/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb b/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb index 3e438cc1354bcb..4e573944cd2344 100644 --- a/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb +++ b/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb @@ -14,7 +14,6 @@ def configure_menu_items insert_item_after(:general_settings, service_accounts_menu_item) insert_item_after(:service_accounts, roles_and_permissions_menu_item) - insert_item_after(:roles_and_permissions, search_menu_item) insert_item_after(:admin_reporting, templates_menu_item) insert_item_after(:admin_ci_cd, security_and_compliance_menu_item) insert_item_after(:security_and_compliance_menu_item, analytics_menu_item) @@ -55,18 +54,6 @@ def service_accounts_available? !gitlab_com_subscription? end - def search_menu_item - return ::Sidebars::NilMenuItem.new(item_id: :search) unless ::License.feature_available?(:elastic_search) - - ::Sidebars::MenuItem.new( - title: _('Search'), - link: search_admin_application_settings_path, - active_routes: { path: 'admin/application_settings#search' }, - item_id: :search, - container_html_options: { testid: 'admin-settings-search-link' } - ) - end - def templates_menu_item unless ::License.feature_available?(:custom_file_templates) return ::Sidebars::NilMenuItem.new(item_id: :admin_templates) diff --git a/ee/spec/helpers/ee/application_settings_helper_spec.rb b/ee/spec/helpers/ee/application_settings_helper_spec.rb index 97a2a1ec6e0033..1326e987d2d37c 100644 --- a/ee/spec/helpers/ee/application_settings_helper_spec.rb +++ b/ee/spec/helpers/ee/application_settings_helper_spec.rb @@ -13,6 +13,20 @@ expect(visible_attributes).to include(*%i[duo_features_enabled lock_duo_features_enabled duo_availability]) end + it 'contains search parameters' do + expected_fields = %i[ + global_search_code_enabled + global_search_commits_enabled + global_search_wiki_enabled + global_search_epics_enabled + global_search_snippet_titles_enabled + global_search_users_enabled + global_search_issues_enabled + global_search_merge_requests_enabled + ] + expect(helper.visible_attributes).to include(*expected_fields) + end + it 'contains zoekt parameters' do expected_fields = %i[ zoekt_auto_delete_lost_nodes zoekt_auto_index_root_namespace zoekt_indexing_enabled @@ -231,6 +245,36 @@ end end + describe '#global_search_settings_checkboxes', feature_category: :global_search do + let_it_be(:application_setting) { build(:application_setting) } + + before do + application_setting.global_search_issues_enabled = true + application_setting.global_search_merge_requests_enabled = false + application_setting.global_search_snippet_titles_enabled = true + application_setting.global_search_users_enabled = false + application_setting.global_search_code_enabled = true + application_setting.global_search_commits_enabled = false + application_setting.global_search_epics_enabled = true + application_setting.global_search_wiki_enabled = true + helper.instance_variable_set(:@application_setting, application_setting) + end + + it 'returns correctly checked checkboxes' do + helper.gitlab_ui_form_for(application_setting, url: search_admin_application_settings_path) do |form| + result = helper.global_search_settings_checkboxes(form) + expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) + expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) + expect(result[2]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[3]).not_to have_checked_field('Enable users tab in global search results', with: 1) + expect(result[4]).to have_checked_field('Enable code tab in global search results', with: 1) + expect(result[5]).not_to have_checked_field('Enable commits tab in global search results', with: 1) + expect(result[6]).to have_checked_field('Enable epics tab in global search results', with: 1) + expect(result[7]).to have_checked_field('Enable wiki tab in global search results', with: 1) + end + end + end + describe '#zoekt_settings_checkboxes', feature_category: :global_search do let_it_be(:application_setting) { build(:application_setting) } diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index 8f3eddb2716e1f..cd6aa7f11a335f 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -44,7 +44,7 @@ let(:project) { nil } let(:group) { group_double } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true true | false | false false | true | true @@ -55,7 +55,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_commits_tab: feature_flag) + stub_application_setting(global_search_commits_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -68,7 +68,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true false | true | false false | false | false @@ -81,7 +81,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_commits_tab: feature_flag) + stub_application_setting(global_search_commits_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -95,7 +95,7 @@ context 'when project search' do let(:project) { project_double } - where(:feature_flag, :show_epics, :condition) do + where(:setting_enabled, :show_epics, :condition) do false | true | false false | false | false true | true | false @@ -106,8 +106,7 @@ let(:options) { { show_epics: show_epics } } it 'data item condition is set correctly' do - stub_feature_flags(global_search_epics_tab: feature_flag) - + stub_application_setting(global_search_epics_enabled: setting_enabled) expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end end @@ -136,7 +135,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_epics, :condition) do + where(:setting_enabled, :show_epics, :condition) do false | false | false true | false | false false | true | false @@ -147,7 +146,7 @@ let(:options) { { show_epics: show_epics } } it 'data item condition is set correctly' do - stub_feature_flags(global_search_epics_tab: feature_flag) + stub_application_setting(global_search_epics_enabled: setting_enabled) expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end @@ -180,7 +179,7 @@ let(:project) { nil } let(:group) { group_double } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true true | false | false false | true | true @@ -191,7 +190,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_wiki_tab: feature_flag) + stub_application_setting(global_search_wikis_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -204,7 +203,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true false | true | false false | false | false @@ -217,7 +216,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_wiki_tab: feature_flag) + stub_application_setting(global_search_wikis_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -290,7 +289,7 @@ let(:project) { nil } let(:group) { nil } - where(:global_search_code_tab_enabled, :global_search_with_zoekt_enabled, :show_elasticsearch_tabs, + where(:global_search_code_enabled, :global_search_with_zoekt_enabled, :show_elasticsearch_tabs, :zoekt_enabled, :zoekt_enabled_for_user, :condition) do false | false | false | false | false | false false | false | false | false | true | false @@ -330,7 +329,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs, zoekt_enabled: zoekt_enabled } } before do - stub_feature_flags(global_search_code_tab: global_search_code_tab_enabled) + stub_application_setting(global_search_code_enabled: global_search_code_enabled) stub_feature_flags(zoekt_cross_namespace_search: global_search_with_zoekt_enabled) allow(::Search::Zoekt).to receive(:enabled_for_user?).and_return(zoekt_enabled_for_user) end diff --git a/ee/spec/requests/api/graphql/search/blob_search_spec.rb b/ee/spec/requests/api/graphql/search/blob_search_spec.rb index d014eefd0d9572..cb9c69c64a9493 100644 --- a/ee/spec/requests/api/graphql/search/blob_search_spec.rb +++ b/ee/spec/requests/api/graphql/search/blob_search_spec.rb @@ -58,7 +58,7 @@ context 'when global search is disabled for blobs' do before do - stub_feature_flags(global_search_code_tab: false) + stub_application_setting(global_search_code_enabled: false) end context 'when group_id and project_id not passed' do diff --git a/ee/spec/services/search_service_spec.rb b/ee/spec/services/search_service_spec.rb index b3367a6d9cb35e..4f8c7f007f7a5f 100644 --- a/ee/spec/services/search_service_spec.rb +++ b/ee/spec/services/search_service_spec.rb @@ -109,20 +109,20 @@ let(:search_service) { described_class.new(user, { scope: scope, search: search }) } 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 + where(:scope, :admin_setting, :setting_enabled, :expected) do + 'blobs' | :global_search_code_enabled | false | false + 'blobs' | :global_search_code_enabled | true | true + 'commits' | :global_search_commits_enabled | false | false + 'commits' | :global_search_commits_enabled | true | true + 'epics' | :global_search_epics_enabled | false | false + 'epics' | :global_search_epics_enabled | true | true + 'wiki_blobs' | :global_search_wiki_enabled | false | false + 'wiki_blobs' | :global_search_wiki_enabled | true | true end with_them do it 'returns false when feature_flag is not enabled and returns true when feature_flag is enabled' do - stub_feature_flags(feature_flag => enabled) + stub_application_setting(admin_setting => setting_enabled) expect(search_service.global_search_enabled_for_scope?).to eq expected end end diff --git a/lib/search/navigation.rb b/lib/search/navigation.rb index 971b6f4ec801ca..e0facef289a430 100644 --- a/lib/search/navigation.rb +++ b/lib/search/navigation.rb @@ -127,7 +127,7 @@ def show_user_search_tab? return true if tab_enabled_for_project?(:users) return false unless can?(user, :read_users_list) - project.nil? && (group.present? || Feature.enabled?(:global_search_users_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_users_enabled?) end def show_code_search_tab? @@ -145,13 +145,13 @@ def show_commits_search_tab? def show_issues_search_tab? return true if tab_enabled_for_project?(:issues) - project.nil? && (group.present? || Feature.enabled?(:global_search_issues_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_issues_enabled?) end def show_merge_requests_search_tab? return true if tab_enabled_for_project?(:merge_requests) - project.nil? && (group.present? || Feature.enabled?(:global_search_merge_requests_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_merge_requests_enabled?) end def show_comments_search_tab? @@ -162,7 +162,7 @@ def show_comments_search_tab? def show_snippets_search_tab? !!options[:show_snippets] && project.nil? && - (group.present? || Feature.enabled?(:global_search_snippet_titles_tab, user, type: :ops)) + (group.present? || ::Gitlab::CurrentSettings.global_search_snippet_titles_enabled?) end def show_milestones_search_tab? diff --git a/lib/sidebars/admin/menus/admin_settings_menu.rb b/lib/sidebars/admin/menus/admin_settings_menu.rb index bb9cedec9aa405..ce55633d6414a5 100644 --- a/lib/sidebars/admin/menus/admin_settings_menu.rb +++ b/lib/sidebars/admin/menus/admin_settings_menu.rb @@ -7,6 +7,7 @@ class AdminSettingsMenu < ::Sidebars::Admin::BaseMenu override :configure_menu_items def configure_menu_items add_item(general_settings_menu_item) + add_item(search_menu_item) add_item(integrations_menu_item) add_item(repository_menu_item) add_item(ci_cd_menu_item) @@ -51,6 +52,16 @@ def general_settings_menu_item ) end + def search_menu_item + ::Sidebars::MenuItem.new( + title: _('Search'), + link: search_admin_application_settings_path, + active_routes: { path: 'admin/application_settings#search' }, + item_id: :search, + container_html_options: { testid: 'admin-settings-search-link' } + ) + end + def integrations_menu_item return ::Sidebars::NilMenuItem.new(item_id: :admin_integrations) unless instance_level_integrations? diff --git a/locale/gitlab.pot b/locale/gitlab.pot index ebfb0f694dc78c..cef52070ffab76 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -15229,6 +15229,9 @@ msgstr "" msgid "Configure settings for exact code search." msgstr "" +msgid "Configure settings for global search." +msgstr "" + msgid "Configure specific limits for Files API requests that supersede the general user and IP rate limits." msgstr "" @@ -22057,12 +22060,21 @@ msgstr "" msgid "Enable cleanup policy caching." msgstr "" +msgid "Enable code tab in global search results" +msgstr "" + +msgid "Enable commits tab in global search results" +msgstr "" + msgid "Enable diagrams.net" msgstr "" msgid "Enable email notification" msgstr "" +msgid "Enable epics tab in global search results" +msgstr "" + msgid "Enable exact code search" msgstr "" @@ -22096,9 +22108,15 @@ msgstr "" msgid "Enable integration" msgstr "" +msgid "Enable issues tab in global search results" +msgstr "" + msgid "Enable maintenance mode" msgstr "" +msgid "Enable merge requests tab in global search results" +msgstr "" + msgid "Enable multipart emails" msgstr "" @@ -22126,6 +22144,9 @@ msgstr "" msgid "Enable security training" msgstr "" +msgid "Enable snippet tab in global search results" +msgstr "" + msgid "Enable two-factor authentication" msgstr "" @@ -22141,9 +22162,15 @@ msgstr "" msgid "Enable user deactivation emails" msgstr "" +msgid "Enable users tab in global search results" +msgstr "" + msgid "Enable version check" msgstr "" +msgid "Enable wiki tab in global search results" +msgstr "" + msgid "EnableReviewApp|Add a job in your CI/CD configuration that:" msgstr "" @@ -26346,6 +26373,9 @@ msgstr "" msgid "Global SAML group membership lock" msgstr "" +msgid "Global Search" +msgstr "" + msgid "Global Search is disabled for this scope" msgstr "" diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 47c9626711e5d4..d9699ed4aaa155 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -270,15 +270,15 @@ context 'for tab feature flags' do subject(:show) { get :show, params: { scope: scope, search: 'term' }, format: :html } - where(:feature_flag, :scope) do - :global_search_issues_tab | 'issues' - :global_search_merge_requests_tab | 'merge_requests' - :global_search_users_tab | 'users' + where(:admin_setting, :scope) do + :global_search_issues_enabled | 'issues' + :global_search_merge_requests_enabled | 'merge_requests' + :global_search_users_enabled | 'users' end with_them do it 'returns 200 if flag is enabled' do - stub_feature_flags(feature_flag => true) + stub_application_setting(feature_flag => true) show @@ -286,7 +286,7 @@ end it 'redirects with alert if flag is disabled' do - stub_feature_flags(feature_flag => false) + stub_application_setting(feature_flag => false) show diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 6c915b288d333d..c43fa847f89591 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -83,6 +83,16 @@ ]) end + it 'contains search parameters' do + expected_fields = %i[ + global_search_snippet_titles_enabled + global_search_users_enabled + global_search_issues_enabled + global_search_merge_requests_enabled + ] + expect(helper.visible_attributes).to include(*expected_fields) + end + it 'contains GitLab for Slack app parameters' do params = %i[slack_app_enabled slack_app_id slack_app_secret slack_app_signing_secret slack_app_verification_token] @@ -355,6 +365,28 @@ end end + describe '#global_search_settings_checkboxes', feature_category: :global_search do + let_it_be(:application_setting) { build(:application_setting) } + + before do + application_setting.global_search_issues_enabled = true + application_setting.global_search_merge_requests_enabled = false + application_setting.global_search_users_enabled = false + application_setting.global_search_snippet_titles_enabled = true + helper.instance_variable_set(:@application_setting, application_setting) + end + + it 'returns correctly checked checkboxes' do + helper.gitlab_ui_form_for(application_setting, url: search_admin_application_settings_path) do |form| + result = helper.global_search_settings_checkboxes(form) + expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) + expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) + expect(result[2]).not_to have_checked_field('Enable users tab in global search results', with: 1) + expect(result[3]).to have_checked_field('Enable snippet tab in global search results', with: 1) + end + end + end + describe '#restricted_level_checkboxes' do let_it_be(:application_setting) { create(:application_setting) } diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 615ff95c7c7768..bd18d29372037e 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -473,9 +473,9 @@ def simple_sanitize(str) end end - context 'when global_search_users_tab feature flag is disabled' do + context 'when global_search_users_enabled setting is disabled' do before do - stub_feature_flags(global_search_users_tab: false) + stub_application_setting(global_search_users_enabled: false) end it 'does not return results' do @@ -524,9 +524,9 @@ def simple_sanitize(str) end end - context 'when global_search_users_tab feature flag is disabled' do + context 'when global_search_users_enabled setting is disabled' do before do - stub_feature_flags(global_search_users_tab: false) + stub_application_setting(global_search_users_enabled: false) end it 'does not return results' do diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 7f8ff6322f9ec5..10269b3070de27 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -94,7 +94,7 @@ end context 'for issues tab' do - where(:tab_enabled, :feature_flag_enabled, :project, :condition) do + where(:setting_enabled, :feature_flag_enabled, :project, :condition) do false | false | nil | false false | true | nil | true false | true | ref(:project_double) | false @@ -107,8 +107,7 @@ with_them do before do - stub_feature_flags(global_search_issues_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:issues).and_return(tab_enabled) + stub_application_setting(global_search_issues_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -118,7 +117,7 @@ end context 'for merge requests tab' do - where(:tab_enabled, :feature_flag_enabled, :project, :condition) do + where(:setting_enabled, :feature_flag_enabled, :project, :condition) do false | false | nil | false true | false | nil | true false | false | ref(:project_double) | false @@ -131,8 +130,7 @@ with_them do before do - stub_feature_flags(global_search_merge_requests_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:merge_requests).and_return(tab_enabled) + stub_application_setting(global_search_merge_requests_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -219,7 +217,7 @@ end context 'for users tab' do - where(:feature_flag_enabled, :can_read_users_list, :project, :tab_enabled, :condition) do + where(:setting_enabled, :can_read_users_list, :project, :tab_enabled, :condition) do false | false | ref(:project_double) | true | true false | false | nil | false | false false | true | nil | false | false @@ -230,8 +228,7 @@ with_them do before do - stub_feature_flags(global_search_users_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) + stub_application_setting(global_search_users_enabled: setting_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) end @@ -243,7 +240,7 @@ end context 'for snippet_titles tab' do - where(:project, :show_snippets, :feature_flag_enabled, :condition) do + where(:project, :show_snippets, :setting_enabled, :condition) do ref(:project_double) | true | false | false nil | false | false | false ref(:project_double) | false | false | false @@ -258,7 +255,7 @@ let(:options) { { show_snippets: show_snippets } } before do - stub_feature_flags(global_search_snippet_titles_tab: feature_flag_enabled) + stub_application_setting(global_search_snippet_titles_enabled: setting_enabled) end it 'data item condition is set correctly' do diff --git a/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb new file mode 100644 index 00000000000000..84533693995e25 --- /dev/null +++ b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe MigrateGlobalSearchSettingsInApplicationSettings, feature_category: :global_search do + let!(:application_setting) { table(:application_settings).create! } + + describe '#up' do + context 'when search is not already set' do + before do + stub_feature_flags(global_search_code_tab: false) + stub_feature_flags(global_search_commits_tab: false) + stub_feature_flags(global_search_issues_tab: false) + end + + it 'migrates search from the feature flags in the application_settings successfully' do + expected_search = if ::Gitlab.ee? + { + 'global_search_code_enabled' => false, + 'global_search_commits_enabled' => false, + 'global_search_epics_enabled' => true, + 'global_search_issues_enabled' => false, + 'global_search_merge_requests_enabled' => true, + 'global_search_snippet_titles_enabled' => true, + 'global_search_users_enabled' => true, + 'global_search_wiki_enabled' => true + } + else + { + 'global_search_issues_enabled' => false, + 'global_search_merge_requests_enabled' => true, + 'global_search_snippet_titles_enabled' => true, + 'global_search_users_enabled' => true + } + end + + expect { migrate! }.to change { + application_setting.reload.search + }.from({}).to(expected_search) + end + end + end +end diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index 3b61cef054673e..3e8e1eb9f34057 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -419,7 +419,7 @@ context 'global snippet search is disabled' do it 'returns forbidden response' do - stub_feature_flags(global_search_snippet_titles_tab: false) + stub_application_setting(global_search_snippet_titles_enabled: false) get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } expect(response).to have_gitlab_http_status(:forbidden) end @@ -427,7 +427,7 @@ context 'global snippet search is enabled' do it 'returns ok response' do - stub_feature_flags(global_search_snippet_titles_tab: true) + stub_application_setting(global_search_snippet_titles_enabled: true) get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } expect(response).to have_gitlab_http_status(:ok) end diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index e54218e82f0321..e7dde0ecf6dd48 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -489,21 +489,21 @@ using RSpec::Parameterized::TableSyntax let(:search) { 'foobar' } - where(:scope, :feature_flag, :enabled, :expected) do - '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 - 'users' | :global_search_users_tab | false | false - 'users' | :global_search_users_tab | true | true - 'random' | :random | nil | true + where(:scope, :admin_setting, :setting_enabled, :expected) do + 'issues' | :global_search_issues_enabled | false | false + 'issues' | :global_search_issues_enabled | true | true + 'merge_requests' | :global_search_merge_requests_enabled | false | false + 'merge_requests' | :global_search_merge_requests_enabled | true | true + 'snippet_titles' | :global_search_snippet_titles_enabled | false | false + 'snippet_titles' | :global_search_snippet_titles_enabled | true | true + 'users' | :global_search_users_enabled | false | false + 'users' | :global_search_users_enabled | true | true + 'random' | :random | nil | true end with_them do it 'returns false when feature_flag is not enabled and returns true when feature_flag is enabled' do - stub_feature_flags(feature_flag => enabled) + stub_application_setting(admin_setting => setting_enabled) expect(search_service.global_search_enabled_for_scope?).to eq expected end end @@ -516,13 +516,13 @@ end it 'returns false when feature_flag is not enabled' do - stub_feature_flags(global_search_snippet_titles_tab: false) + stub_application_setting(global_search_snippet_titles_enabled: false) expect(search_service.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) + stub_application_setting(global_search_snippet_titles_enabled: true) expect(search_service.global_search_enabled_for_scope?).to eq true end -- GitLab From 7dcd50c6214b75a01dd8ff83df438521f910589b Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 12:56:13 +0000 Subject: [PATCH 02/21] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Arturo Herrero --- ee/app/helpers/ee/application_settings_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/ee/app/helpers/ee/application_settings_helper.rb b/ee/app/helpers/ee/application_settings_helper.rb index 7858e58a0441bc..155810e3b47758 100644 --- a/ee/app/helpers/ee/application_settings_helper.rb +++ b/ee/app/helpers/ee/application_settings_helper.rb @@ -89,7 +89,6 @@ def visible_attributes :secret_detection_service_auth_token, :secret_detection_service_url, :fetch_observability_alerts_from_cloud, - :global_search_merge_requests_enabled, :global_search_code_enabled, :global_search_commits_enabled, :global_search_wiki_enabled, -- GitLab From 178aa3f1816390857c54cd5c88305620cc74c750 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 14:06:51 +0000 Subject: [PATCH 03/21] Apply 2 suggestion(s) to 2 file(s) Co-authored-by: Arturo Herrero --- ee/spec/lib/search/navigation_spec.rb | 1 + spec/lib/search/navigation_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index cd6aa7f11a335f..71eafe4d5c0989 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -107,6 +107,7 @@ it 'data item condition is set correctly' do stub_application_setting(global_search_epics_enabled: setting_enabled) + expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end end diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 10269b3070de27..49fb17d99cd54b 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -228,6 +228,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) stub_application_setting(global_search_users_enabled: setting_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) -- GitLab From fb0646d0aaf818b0440fd4b4368767c43c8e9c4e Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 20:06:47 +0530 Subject: [PATCH 04/21] Fix failing spec --- ee/spec/controllers/ee/search_controller_spec.rb | 12 ++++++------ ee/spec/lib/search/navigation_spec.rb | 4 ++-- spec/helpers/application_settings_helper_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ee/spec/controllers/ee/search_controller_spec.rb b/ee/spec/controllers/ee/search_controller_spec.rb index 955c275c4ff98a..1c8ce453ca5c56 100644 --- a/ee/spec/controllers/ee/search_controller_spec.rb +++ b/ee/spec/controllers/ee/search_controller_spec.rb @@ -203,15 +203,15 @@ 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' + where(:admin_setting, :scope) do + :global_search_code_enabled | 'blobs' + :global_search_commits_enabled | 'commits' + :global_search_wiki_enabled | 'wiki_blobs' end with_them do it 'returns 200 if flag is enabled' do - stub_feature_flags(feature_flag => true) + stub_application_setting(admin_setting => true) show @@ -219,7 +219,7 @@ end it 'redirects with alert if flag is disabled' do - stub_feature_flags(feature_flag => false) + stub_application_setting(admin_setting => false) show diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index 71eafe4d5c0989..9b79294c77cf32 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -191,7 +191,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_application_setting(global_search_wikis_enabled: setting_enabled) + stub_application_setting(global_search_wiki_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -217,7 +217,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_application_setting(global_search_wikis_enabled: setting_enabled) + stub_application_setting(global_search_wiki_enabled: setting_enabled) end it 'data item condition is set correctly' do diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index c43fa847f89591..6f1dc1704e33a6 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -381,8 +381,8 @@ result = helper.global_search_settings_checkboxes(form) expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) - expect(result[2]).not_to have_checked_field('Enable users tab in global search results', with: 1) - expect(result[3]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[2]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[3]).not_to have_checked_field('Enable users tab in global search results', with: 1) end end end -- GitLab From 3b76b72b2f77da43f6ad88894f2ab452d74e276a Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 05:15:37 +0000 Subject: [PATCH 05/21] Apply 2 suggestion(s) to 2 file(s) Co-authored-by: Arturo Herrero --- ...16_migrate_global_search_settings_in_application_settings.rb | 2 +- spec/lib/search/navigation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb index 39b8db1d33dfa8..aff522460c2ad0 100644 --- a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb +++ b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb @@ -12,7 +12,7 @@ def up ApplicationSetting.reset_column_information application_setting = ApplicationSetting.last - return if application_setting.nil? + return unless application_setting # rubocop:disable Gitlab/FeatureFlagWithoutActor -- Does not execute in user context search = { diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 49fb17d99cd54b..477b0f5853d7b0 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -228,8 +228,8 @@ with_them do before do - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) stub_application_setting(global_search_users_enabled: setting_enabled) + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) end -- GitLab From 45e19299b89d28b8c05cfa50b91921ea550a8d05 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 11:49:05 +0530 Subject: [PATCH 06/21] Fix failing specs --- .../admin/menus/admin_settings_menu_spec.rb | 20 ------------------- spec/controllers/search_controller_spec.rb | 4 ++-- spec/lib/search/navigation_spec.rb | 6 ++++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb index a6465ea33a1e80..ae90f6070a80f0 100644 --- a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb +++ b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb @@ -75,25 +75,5 @@ end end end - - describe 'Search', feature_category: :global_search do - let(:item_id) { :search } - - context 'when elastic_search feature is not licensed' do - before do - stub_licensed_features(elastic_search: false) - end - - it { is_expected.not_to be_present } - end - - context 'when elastic_search feature is licensed' do - before do - stub_licensed_features(elastic_search: true) - end - - it { is_expected.to be_present } - end - end end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index d9699ed4aaa155..80f63b4049c09d 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -278,7 +278,7 @@ with_them do it 'returns 200 if flag is enabled' do - stub_application_setting(feature_flag => true) + stub_application_setting(admin_setting => true) show @@ -286,7 +286,7 @@ end it 'redirects with alert if flag is disabled' do - stub_application_setting(feature_flag => false) + stub_application_setting(admin_setting => false) show diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 477b0f5853d7b0..23a9996ae05fac 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -94,7 +94,7 @@ end context 'for issues tab' do - where(:setting_enabled, :feature_flag_enabled, :project, :condition) do + where(:tab_enabled, :setting_enabled, :project, :condition) do false | false | nil | false false | true | nil | true false | true | ref(:project_double) | false @@ -107,6 +107,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:issues).and_return(tab_enabled) stub_application_setting(global_search_issues_enabled: setting_enabled) end @@ -117,7 +118,7 @@ end context 'for merge requests tab' do - where(:setting_enabled, :feature_flag_enabled, :project, :condition) do + where(:tab_enabled, :setting_enabled, :project, :condition) do false | false | nil | false true | false | nil | true false | false | ref(:project_double) | false @@ -130,6 +131,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:merge_requests).and_return(tab_enabled) stub_application_setting(global_search_merge_requests_enabled: setting_enabled) end -- GitLab From 8f8e37a816ad2800454e15e1d2315ae6a7e667dc Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 11:56:27 +0530 Subject: [PATCH 07/21] Add specs and feature category --- app/controllers/admin/application_settings_controller.rb | 1 + spec/routing/admin_routing_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 3708c885143701..2300687ed4c031 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -36,6 +36,7 @@ class ApplicationSettingsController < Admin::ApplicationController feature_category :integrations, [:integrations, :slack_app_manifest_share, :slack_app_manifest_download] feature_category :pages, [:lets_encrypt_terms_of_service] feature_category :observability, [:reset_error_tracking_access_token] + feature_category :global_search, [:search] VALID_SETTING_PANELS = %w[general repository ci_cd reporting metrics_and_profiling diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index d8f36e01b0fb28..12aaadb3a4c092 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -213,3 +213,10 @@ expect(get("/admin/runners/runner_setup_scripts")).to route_to('admin/runners#runner_setup_scripts') end end + +RSpec.describe Admin::ApplicationSettingsController, 'routing' do + it 'redirects /search to #search' do + expect(get('/admin/application_settings/search')).to route_to('admin/application_settings#search') + expect(patch('/admin/application_settings/search')).to route_to('admin/application_settings#search') + end +end -- GitLab From d80a0b03db2da600128cc64abb3c36528732d27d Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 17:19:58 +0530 Subject: [PATCH 08/21] Add changes for removing the _tab ff --- app/helpers/application_settings_helper.rb | 31 ++++++++++++- app/helpers/search_helper.rb | 2 +- app/services/search_service.rb | 10 ++--- .../_global_search_settings.html.haml | 15 +++++++ .../application_settings/search.html.haml | 7 +++ config/routes/admin.rb | 2 +- ...search_settings_in_application_settings.rb | 44 +++++++++++++++++++ db/schema_migrations/20250109055316 | 1 + .../helpers/ee/application_settings_helper.rb | 33 +++++++++++++- ee/app/services/ee/search_service.rb | 8 ++-- .../application_settings/search.html.haml | 1 + ee/lib/ee/search/navigation.rb | 8 ++-- .../admin/menus/admin_settings_menu.rb | 13 ------ .../ee/application_settings_helper_spec.rb | 44 +++++++++++++++++++ ee/spec/lib/search/navigation_spec.rb | 29 ++++++------ .../api/graphql/search/blob_search_spec.rb | 2 +- ee/spec/services/search_service_spec.rb | 20 ++++----- lib/search/navigation.rb | 8 ++-- .../admin/menus/admin_settings_menu.rb | 11 +++++ locale/gitlab.pot | 30 +++++++++++++ spec/controllers/search_controller_spec.rb | 12 ++--- .../application_settings_helper_spec.rb | 32 ++++++++++++++ spec/helpers/search_helper_spec.rb | 8 ++-- spec/lib/search/navigation_spec.rb | 19 ++++---- ...h_settings_in_application_settings_spec.rb | 44 +++++++++++++++++++ spec/requests/api/search_spec.rb | 4 +- spec/services/search_service_spec.rb | 26 +++++------ 27 files changed, 368 insertions(+), 96 deletions(-) create mode 100644 app/views/admin/application_settings/_global_search_settings.html.haml create mode 100644 app/views/admin/application_settings/search.html.haml create mode 100644 db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb create mode 100644 db/schema_migrations/20250109055316 create mode 100644 spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 6b8cd2b029ee21..75741f2d4a24fe 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -72,6 +72,31 @@ def enabled_protocol_button(container, protocol) end end + def global_search_settings_checkboxes(form) + [ + form.gitlab_ui_checkbox_component( + :global_search_issues_enabled, + _("Enable issues tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_issues_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_merge_requests_enabled, + _("Enable merge requests tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_merge_requests_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_snippet_titles_enabled, + _("Enable snippet tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_snippet_titles_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_users_enabled, + _("Enable users tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_users_enabled, multiple: false } + ) + ] + end + def restricted_level_checkboxes(form) restricted_visibility_levels_help_text = { Gitlab::VisibilityLevel::PUBLIC => s_( @@ -544,7 +569,11 @@ def visible_attributes :require_personal_access_token_expiry, :observability_backend_ssl_verification_enabled, :show_migrate_from_jenkins_banner, - :ropc_without_client_credentials + :ropc_without_client_credentials, + :global_search_snippet_titles_enabled, + :global_search_users_enabled, + :global_search_issues_enabled, + :global_search_merge_requests_enabled ].tap do |settings| unless Gitlab.com? settings << :resource_usage_limits diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 197313c3ff90a3..b58bead78d69ef 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -428,7 +428,7 @@ def projects_autocomplete(term, limit = 5) def users_autocomplete(term, limit = 5) unless current_user && Ability.allowed?(current_user, :read_users_list) && - Feature.enabled?(:global_search_users_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_users_enabled? return [] end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 906492003ac81d..a61788818a8230 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -105,17 +105,17 @@ def level end def global_search_enabled_for_scope? - return false if show_snippets? && Feature.disabled?(:global_search_snippet_titles_tab, current_user, type: :ops) + return false if show_snippets? && !::Gitlab::CurrentSettings.global_search_snippet_titles_enabled? case params[:scope] when 'issues' - Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_issues_enabled? when 'merge_requests' - Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_merge_requests_enabled? when 'snippet_titles' - Feature.enabled?(:global_search_snippet_titles_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_snippet_titles_enabled? when 'users' - Feature.enabled?(:global_search_users_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_users_enabled? else true end diff --git a/app/views/admin/application_settings/_global_search_settings.html.haml b/app/views/admin/application_settings/_global_search_settings.html.haml new file mode 100644 index 00000000000000..185bc4035b3b16 --- /dev/null +++ b/app/views/admin/application_settings/_global_search_settings.html.haml @@ -0,0 +1,15 @@ += render ::Layouts::SettingsBlockComponent.new(_('Global Search'), + id: 'js-global-search-settings', + testid: 'admin-global-search-settings', + expanded: expanded_by_default?) do |c| + - c.with_description do + = _('Configure settings for global search.') + = link_to _('Learn more.'), help_page_path('user/search/index.md', anchor: 'global-search-scopes'), target: '_blank', rel: 'noopener noreferrer' + - c.with_body do + = gitlab_ui_form_for @application_setting, url: general_admin_application_settings_path(anchor: 'js-global-search-settings'), html: { class: 'fieldset-form', id: 'global-search-settings' } do |f| + = form_errors(@application_setting) + %fieldset + .form-group + - global_search_settings_checkboxes(f).each do |checkbox| + = checkbox + = f.submit _('Save changes'), pajamas_button: true diff --git a/app/views/admin/application_settings/search.html.haml b/app/views/admin/application_settings/search.html.haml new file mode 100644 index 00000000000000..d1d3c21aca00c1 --- /dev/null +++ b/app/views/admin/application_settings/search.html.haml @@ -0,0 +1,7 @@ +- breadcrumb_title _("Search") +- page_title _("Search") +- add_page_specific_style 'page_bundles/settings' +- add_page_specific_style 'page_bundles/search' +- @force_desktop_expanded_sidebar = true + += render_if_exists 'admin/application_settings/global_search_settings' diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c54397860e60a4..a00f316e85cd0d 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -168,7 +168,7 @@ put :reset_health_check_token put :reset_error_tracking_access_token put :clear_repository_check_states - match :general, :integrations, :repository, :ci_cd, :reporting, :metrics_and_profiling, :network, :preferences, via: [:get, :patch] + match :general, :integrations, :repository, :ci_cd, :reporting, :metrics_and_profiling, :network, :preferences, :search, via: [:get, :patch] get :lets_encrypt_terms_of_service get :slack_app_manifest_download, format: :json get :slack_app_manifest_share diff --git a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb new file mode 100644 index 00000000000000..39b8db1d33dfa8 --- /dev/null +++ b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class MigrateGlobalSearchSettingsInApplicationSettings < Gitlab::Database::Migration[2.2] + restrict_gitlab_migration gitlab_schema: :gitlab_main + milestone '17.9' + + class ApplicationSetting < MigrationRecord + self.table_name = 'application_settings' + end + + def up + ApplicationSetting.reset_column_information + + application_setting = ApplicationSetting.last + return if application_setting.nil? + + # rubocop:disable Gitlab/FeatureFlagWithoutActor -- Does not execute in user context + search = { + global_search_issues_enabled: Feature.enabled?(:global_search_issues_tab, type: :ops), + global_search_merge_requests_enabled: Feature.enabled?(:global_search_merge_requests_tab, type: :ops), + global_search_snippet_titles_enabled: Feature.enabled?(:global_search_snippet_titles_tab, type: :ops), + global_search_users_enabled: Feature.enabled?(:global_search_users_tab, type: :ops) + } + + if Gitlab.ee? + search.merge!( + global_search_code_enabled: Feature.enabled?(:global_search_code_tab, type: :ops), + global_search_commits_enabled: Feature.enabled?(:global_search_commits_tab, type: :ops), + global_search_epics_enabled: Feature.enabled?(:global_search_epics_tab, type: :ops), + global_search_wiki_enabled: Feature.enabled?(:global_search_wiki_tab, type: :ops) + ) + end + # rubocop:enable Gitlab/FeatureFlagWithoutActor + + application_setting.update_columns(search: search, updated_at: Time.current) + end + + def down + application_setting = ApplicationSetting.last + return unless application_setting + + application_setting.update_column(:search, {}) + end +end diff --git a/db/schema_migrations/20250109055316 b/db/schema_migrations/20250109055316 new file mode 100644 index 00000000000000..5b6db794f915a7 --- /dev/null +++ b/db/schema_migrations/20250109055316 @@ -0,0 +1 @@ +213fa997d255628cb8f3e3fc6b2098e8fded40aa2eae7593ac5b123b08ff72d8 \ No newline at end of file diff --git a/ee/app/helpers/ee/application_settings_helper.rb b/ee/app/helpers/ee/application_settings_helper.rb index 33b4c93c063d5b..7858e58a0441bc 100644 --- a/ee/app/helpers/ee/application_settings_helper.rb +++ b/ee/app/helpers/ee/application_settings_helper.rb @@ -88,7 +88,12 @@ def visible_attributes :scan_execution_policies_action_limit, :secret_detection_service_auth_token, :secret_detection_service_url, - :fetch_observability_alerts_from_cloud + :fetch_observability_alerts_from_cloud, + :global_search_merge_requests_enabled, + :global_search_code_enabled, + :global_search_commits_enabled, + :global_search_wiki_enabled, + :global_search_epics_enabled ].tap do |settings| settings.concat(identity_verification_attributes) settings.concat(enable_promotion_management_attributes) @@ -265,6 +270,32 @@ def sync_purl_types_checkboxes(form) end end + override :global_search_settings_checkboxes + def global_search_settings_checkboxes(form) + super + [ + form.gitlab_ui_checkbox_component( + :global_search_code_enabled, + _("Enable code tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_code_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_commits_enabled, + _("Enable commits tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_commits_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_epics_enabled, + _("Enable epics tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_epics_enabled, multiple: false } + ), + form.gitlab_ui_checkbox_component( + :global_search_wiki_enabled, + _("Enable wiki tab in global search results"), + checkbox_options: { checked: @application_setting.global_search_wiki_enabled, multiple: false } + ) + ] + end + def zoekt_settings_checkboxes(form) [ form.gitlab_ui_checkbox_component( diff --git a/ee/app/services/ee/search_service.rb b/ee/app/services/ee/search_service.rb index 83155952e69140..26804e7864fb1d 100644 --- a/ee/app/services/ee/search_service.rb +++ b/ee/app/services/ee/search_service.rb @@ -45,13 +45,13 @@ def use_zoekt? def global_search_enabled_for_scope? case params[:scope] when 'blobs' - ::Feature.enabled?(:global_search_code_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_code_enabled? when 'commits' - ::Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_commits_enabled? when 'epics' - ::Feature.enabled?(:global_search_epics_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_epics_enabled? when 'wiki_blobs' - ::Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) + ::Gitlab::CurrentSettings.global_search_wiki_enabled? else super end diff --git a/ee/app/views/admin/application_settings/search.html.haml b/ee/app/views/admin/application_settings/search.html.haml index c23e51a0e747db..8bb19aa4d1a0b3 100644 --- a/ee/app/views/admin/application_settings/search.html.haml +++ b/ee/app/views/admin/application_settings/search.html.haml @@ -51,3 +51,4 @@ = render_if_exists 'admin/application_settings/elasticsearch_form' = render_if_exists 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) += render_if_exists 'admin/application_settings/global_search_settings' diff --git a/ee/lib/ee/search/navigation.rb b/ee/lib/ee/search/navigation.rb index 7fc6ebf08a98a6..8e0ec0bc2526ff 100644 --- a/ee/lib/ee/search/navigation.rb +++ b/ee/lib/ee/search/navigation.rb @@ -47,7 +47,7 @@ def show_code_search_tab? return true if super return false if project - global_search_code_enabled = ::Feature.enabled?(:global_search_code_tab, user, type: :ops) + global_search_code_enabled = ::Gitlab::CurrentSettings.global_search_code_enabled? global_search_zoekt_enabled = ::Feature.enabled?(:zoekt_cross_namespace_search, user, type: :ops) zoekt_enabled_for_user = zoekt_enabled? && ::Search::Zoekt.enabled_for_user?(user) @@ -72,7 +72,7 @@ def show_wiki_search_tab? return false unless show_elasticsearch_tabs? return true if group - ::Feature.enabled?(:global_search_wiki_tab, user, type: :ops) + ::Gitlab::CurrentSettings.global_search_wiki_enabled? end def show_epics_search_tab? @@ -80,7 +80,7 @@ def show_epics_search_tab? return false unless options[:show_epics] return true if group - ::Feature.enabled?(:global_search_epics_tab, user, type: :ops) + ::Gitlab::CurrentSettings.global_search_epics_enabled? end override :show_commits_search_tab? @@ -89,7 +89,7 @@ def show_commits_search_tab? return false unless show_elasticsearch_tabs? # advanced search enabled return true if group # group search - ::Feature.enabled?(:global_search_commits_tab, user, type: :ops) # global search + ::Gitlab::CurrentSettings.global_search_commits_enabled? end end end diff --git a/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb b/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb index 3e438cc1354bcb..4e573944cd2344 100644 --- a/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb +++ b/ee/lib/ee/sidebars/admin/menus/admin_settings_menu.rb @@ -14,7 +14,6 @@ def configure_menu_items insert_item_after(:general_settings, service_accounts_menu_item) insert_item_after(:service_accounts, roles_and_permissions_menu_item) - insert_item_after(:roles_and_permissions, search_menu_item) insert_item_after(:admin_reporting, templates_menu_item) insert_item_after(:admin_ci_cd, security_and_compliance_menu_item) insert_item_after(:security_and_compliance_menu_item, analytics_menu_item) @@ -55,18 +54,6 @@ def service_accounts_available? !gitlab_com_subscription? end - def search_menu_item - return ::Sidebars::NilMenuItem.new(item_id: :search) unless ::License.feature_available?(:elastic_search) - - ::Sidebars::MenuItem.new( - title: _('Search'), - link: search_admin_application_settings_path, - active_routes: { path: 'admin/application_settings#search' }, - item_id: :search, - container_html_options: { testid: 'admin-settings-search-link' } - ) - end - def templates_menu_item unless ::License.feature_available?(:custom_file_templates) return ::Sidebars::NilMenuItem.new(item_id: :admin_templates) diff --git a/ee/spec/helpers/ee/application_settings_helper_spec.rb b/ee/spec/helpers/ee/application_settings_helper_spec.rb index 97a2a1ec6e0033..1326e987d2d37c 100644 --- a/ee/spec/helpers/ee/application_settings_helper_spec.rb +++ b/ee/spec/helpers/ee/application_settings_helper_spec.rb @@ -13,6 +13,20 @@ expect(visible_attributes).to include(*%i[duo_features_enabled lock_duo_features_enabled duo_availability]) end + it 'contains search parameters' do + expected_fields = %i[ + global_search_code_enabled + global_search_commits_enabled + global_search_wiki_enabled + global_search_epics_enabled + global_search_snippet_titles_enabled + global_search_users_enabled + global_search_issues_enabled + global_search_merge_requests_enabled + ] + expect(helper.visible_attributes).to include(*expected_fields) + end + it 'contains zoekt parameters' do expected_fields = %i[ zoekt_auto_delete_lost_nodes zoekt_auto_index_root_namespace zoekt_indexing_enabled @@ -231,6 +245,36 @@ end end + describe '#global_search_settings_checkboxes', feature_category: :global_search do + let_it_be(:application_setting) { build(:application_setting) } + + before do + application_setting.global_search_issues_enabled = true + application_setting.global_search_merge_requests_enabled = false + application_setting.global_search_snippet_titles_enabled = true + application_setting.global_search_users_enabled = false + application_setting.global_search_code_enabled = true + application_setting.global_search_commits_enabled = false + application_setting.global_search_epics_enabled = true + application_setting.global_search_wiki_enabled = true + helper.instance_variable_set(:@application_setting, application_setting) + end + + it 'returns correctly checked checkboxes' do + helper.gitlab_ui_form_for(application_setting, url: search_admin_application_settings_path) do |form| + result = helper.global_search_settings_checkboxes(form) + expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) + expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) + expect(result[2]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[3]).not_to have_checked_field('Enable users tab in global search results', with: 1) + expect(result[4]).to have_checked_field('Enable code tab in global search results', with: 1) + expect(result[5]).not_to have_checked_field('Enable commits tab in global search results', with: 1) + expect(result[6]).to have_checked_field('Enable epics tab in global search results', with: 1) + expect(result[7]).to have_checked_field('Enable wiki tab in global search results', with: 1) + end + end + end + describe '#zoekt_settings_checkboxes', feature_category: :global_search do let_it_be(:application_setting) { build(:application_setting) } diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index 8f3eddb2716e1f..cd6aa7f11a335f 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -44,7 +44,7 @@ let(:project) { nil } let(:group) { group_double } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true true | false | false false | true | true @@ -55,7 +55,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_commits_tab: feature_flag) + stub_application_setting(global_search_commits_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -68,7 +68,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true false | true | false false | false | false @@ -81,7 +81,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_commits_tab: feature_flag) + stub_application_setting(global_search_commits_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -95,7 +95,7 @@ context 'when project search' do let(:project) { project_double } - where(:feature_flag, :show_epics, :condition) do + where(:setting_enabled, :show_epics, :condition) do false | true | false false | false | false true | true | false @@ -106,8 +106,7 @@ let(:options) { { show_epics: show_epics } } it 'data item condition is set correctly' do - stub_feature_flags(global_search_epics_tab: feature_flag) - + stub_application_setting(global_search_epics_enabled: setting_enabled) expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end end @@ -136,7 +135,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_epics, :condition) do + where(:setting_enabled, :show_epics, :condition) do false | false | false true | false | false false | true | false @@ -147,7 +146,7 @@ let(:options) { { show_epics: show_epics } } it 'data item condition is set correctly' do - stub_feature_flags(global_search_epics_tab: feature_flag) + stub_application_setting(global_search_epics_enabled: setting_enabled) expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end @@ -180,7 +179,7 @@ let(:project) { nil } let(:group) { group_double } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true true | false | false false | true | true @@ -191,7 +190,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_wiki_tab: feature_flag) + stub_application_setting(global_search_wikis_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -204,7 +203,7 @@ let(:project) { nil } let(:group) { nil } - where(:feature_flag, :show_elasticsearch_tabs, :condition) do + where(:setting_enabled, :show_elasticsearch_tabs, :condition) do true | true | true false | true | false false | false | false @@ -217,7 +216,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_feature_flags(global_search_wiki_tab: feature_flag) + stub_application_setting(global_search_wikis_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -290,7 +289,7 @@ let(:project) { nil } let(:group) { nil } - where(:global_search_code_tab_enabled, :global_search_with_zoekt_enabled, :show_elasticsearch_tabs, + where(:global_search_code_enabled, :global_search_with_zoekt_enabled, :show_elasticsearch_tabs, :zoekt_enabled, :zoekt_enabled_for_user, :condition) do false | false | false | false | false | false false | false | false | false | true | false @@ -330,7 +329,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs, zoekt_enabled: zoekt_enabled } } before do - stub_feature_flags(global_search_code_tab: global_search_code_tab_enabled) + stub_application_setting(global_search_code_enabled: global_search_code_enabled) stub_feature_flags(zoekt_cross_namespace_search: global_search_with_zoekt_enabled) allow(::Search::Zoekt).to receive(:enabled_for_user?).and_return(zoekt_enabled_for_user) end diff --git a/ee/spec/requests/api/graphql/search/blob_search_spec.rb b/ee/spec/requests/api/graphql/search/blob_search_spec.rb index d014eefd0d9572..cb9c69c64a9493 100644 --- a/ee/spec/requests/api/graphql/search/blob_search_spec.rb +++ b/ee/spec/requests/api/graphql/search/blob_search_spec.rb @@ -58,7 +58,7 @@ context 'when global search is disabled for blobs' do before do - stub_feature_flags(global_search_code_tab: false) + stub_application_setting(global_search_code_enabled: false) end context 'when group_id and project_id not passed' do diff --git a/ee/spec/services/search_service_spec.rb b/ee/spec/services/search_service_spec.rb index b3367a6d9cb35e..4f8c7f007f7a5f 100644 --- a/ee/spec/services/search_service_spec.rb +++ b/ee/spec/services/search_service_spec.rb @@ -109,20 +109,20 @@ let(:search_service) { described_class.new(user, { scope: scope, search: search }) } 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 + where(:scope, :admin_setting, :setting_enabled, :expected) do + 'blobs' | :global_search_code_enabled | false | false + 'blobs' | :global_search_code_enabled | true | true + 'commits' | :global_search_commits_enabled | false | false + 'commits' | :global_search_commits_enabled | true | true + 'epics' | :global_search_epics_enabled | false | false + 'epics' | :global_search_epics_enabled | true | true + 'wiki_blobs' | :global_search_wiki_enabled | false | false + 'wiki_blobs' | :global_search_wiki_enabled | true | true end with_them do it 'returns false when feature_flag is not enabled and returns true when feature_flag is enabled' do - stub_feature_flags(feature_flag => enabled) + stub_application_setting(admin_setting => setting_enabled) expect(search_service.global_search_enabled_for_scope?).to eq expected end end diff --git a/lib/search/navigation.rb b/lib/search/navigation.rb index 971b6f4ec801ca..e0facef289a430 100644 --- a/lib/search/navigation.rb +++ b/lib/search/navigation.rb @@ -127,7 +127,7 @@ def show_user_search_tab? return true if tab_enabled_for_project?(:users) return false unless can?(user, :read_users_list) - project.nil? && (group.present? || Feature.enabled?(:global_search_users_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_users_enabled?) end def show_code_search_tab? @@ -145,13 +145,13 @@ def show_commits_search_tab? def show_issues_search_tab? return true if tab_enabled_for_project?(:issues) - project.nil? && (group.present? || Feature.enabled?(:global_search_issues_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_issues_enabled?) end def show_merge_requests_search_tab? return true if tab_enabled_for_project?(:merge_requests) - project.nil? && (group.present? || Feature.enabled?(:global_search_merge_requests_tab, user, type: :ops)) + project.nil? && (group.present? || ::Gitlab::CurrentSettings.global_search_merge_requests_enabled?) end def show_comments_search_tab? @@ -162,7 +162,7 @@ def show_comments_search_tab? def show_snippets_search_tab? !!options[:show_snippets] && project.nil? && - (group.present? || Feature.enabled?(:global_search_snippet_titles_tab, user, type: :ops)) + (group.present? || ::Gitlab::CurrentSettings.global_search_snippet_titles_enabled?) end def show_milestones_search_tab? diff --git a/lib/sidebars/admin/menus/admin_settings_menu.rb b/lib/sidebars/admin/menus/admin_settings_menu.rb index bb9cedec9aa405..ce55633d6414a5 100644 --- a/lib/sidebars/admin/menus/admin_settings_menu.rb +++ b/lib/sidebars/admin/menus/admin_settings_menu.rb @@ -7,6 +7,7 @@ class AdminSettingsMenu < ::Sidebars::Admin::BaseMenu override :configure_menu_items def configure_menu_items add_item(general_settings_menu_item) + add_item(search_menu_item) add_item(integrations_menu_item) add_item(repository_menu_item) add_item(ci_cd_menu_item) @@ -51,6 +52,16 @@ def general_settings_menu_item ) end + def search_menu_item + ::Sidebars::MenuItem.new( + title: _('Search'), + link: search_admin_application_settings_path, + active_routes: { path: 'admin/application_settings#search' }, + item_id: :search, + container_html_options: { testid: 'admin-settings-search-link' } + ) + end + def integrations_menu_item return ::Sidebars::NilMenuItem.new(item_id: :admin_integrations) unless instance_level_integrations? diff --git a/locale/gitlab.pot b/locale/gitlab.pot index d7d28d4d5264b7..df6a2f592aaa09 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -15229,6 +15229,9 @@ msgstr "" msgid "Configure settings for exact code search." msgstr "" +msgid "Configure settings for global search." +msgstr "" + msgid "Configure specific limits for Files API requests that supersede the general user and IP rate limits." msgstr "" @@ -22069,12 +22072,21 @@ msgstr "" msgid "Enable cleanup policy caching." msgstr "" +msgid "Enable code tab in global search results" +msgstr "" + +msgid "Enable commits tab in global search results" +msgstr "" + msgid "Enable diagrams.net" msgstr "" msgid "Enable email notification" msgstr "" +msgid "Enable epics tab in global search results" +msgstr "" + msgid "Enable exact code search" msgstr "" @@ -22108,9 +22120,15 @@ msgstr "" msgid "Enable integration" msgstr "" +msgid "Enable issues tab in global search results" +msgstr "" + msgid "Enable maintenance mode" msgstr "" +msgid "Enable merge requests tab in global search results" +msgstr "" + msgid "Enable multipart emails" msgstr "" @@ -22138,6 +22156,9 @@ msgstr "" msgid "Enable security training" msgstr "" +msgid "Enable snippet tab in global search results" +msgstr "" + msgid "Enable two-factor authentication" msgstr "" @@ -22153,9 +22174,15 @@ msgstr "" msgid "Enable user deactivation emails" msgstr "" +msgid "Enable users tab in global search results" +msgstr "" + msgid "Enable version check" msgstr "" +msgid "Enable wiki tab in global search results" +msgstr "" + msgid "EnableReviewApp|Add a job in your CI/CD configuration that:" msgstr "" @@ -26361,6 +26388,9 @@ msgstr "" msgid "Global SAML group membership lock" msgstr "" +msgid "Global Search" +msgstr "" + msgid "Global Search is disabled for this scope" msgstr "" diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 47c9626711e5d4..d9699ed4aaa155 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -270,15 +270,15 @@ context 'for tab feature flags' do subject(:show) { get :show, params: { scope: scope, search: 'term' }, format: :html } - where(:feature_flag, :scope) do - :global_search_issues_tab | 'issues' - :global_search_merge_requests_tab | 'merge_requests' - :global_search_users_tab | 'users' + where(:admin_setting, :scope) do + :global_search_issues_enabled | 'issues' + :global_search_merge_requests_enabled | 'merge_requests' + :global_search_users_enabled | 'users' end with_them do it 'returns 200 if flag is enabled' do - stub_feature_flags(feature_flag => true) + stub_application_setting(feature_flag => true) show @@ -286,7 +286,7 @@ end it 'redirects with alert if flag is disabled' do - stub_feature_flags(feature_flag => false) + stub_application_setting(feature_flag => false) show diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 6c915b288d333d..c43fa847f89591 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -83,6 +83,16 @@ ]) end + it 'contains search parameters' do + expected_fields = %i[ + global_search_snippet_titles_enabled + global_search_users_enabled + global_search_issues_enabled + global_search_merge_requests_enabled + ] + expect(helper.visible_attributes).to include(*expected_fields) + end + it 'contains GitLab for Slack app parameters' do params = %i[slack_app_enabled slack_app_id slack_app_secret slack_app_signing_secret slack_app_verification_token] @@ -355,6 +365,28 @@ end end + describe '#global_search_settings_checkboxes', feature_category: :global_search do + let_it_be(:application_setting) { build(:application_setting) } + + before do + application_setting.global_search_issues_enabled = true + application_setting.global_search_merge_requests_enabled = false + application_setting.global_search_users_enabled = false + application_setting.global_search_snippet_titles_enabled = true + helper.instance_variable_set(:@application_setting, application_setting) + end + + it 'returns correctly checked checkboxes' do + helper.gitlab_ui_form_for(application_setting, url: search_admin_application_settings_path) do |form| + result = helper.global_search_settings_checkboxes(form) + expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) + expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) + expect(result[2]).not_to have_checked_field('Enable users tab in global search results', with: 1) + expect(result[3]).to have_checked_field('Enable snippet tab in global search results', with: 1) + end + end + end + describe '#restricted_level_checkboxes' do let_it_be(:application_setting) { create(:application_setting) } diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 615ff95c7c7768..bd18d29372037e 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -473,9 +473,9 @@ def simple_sanitize(str) end end - context 'when global_search_users_tab feature flag is disabled' do + context 'when global_search_users_enabled setting is disabled' do before do - stub_feature_flags(global_search_users_tab: false) + stub_application_setting(global_search_users_enabled: false) end it 'does not return results' do @@ -524,9 +524,9 @@ def simple_sanitize(str) end end - context 'when global_search_users_tab feature flag is disabled' do + context 'when global_search_users_enabled setting is disabled' do before do - stub_feature_flags(global_search_users_tab: false) + stub_application_setting(global_search_users_enabled: false) end it 'does not return results' do diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 7f8ff6322f9ec5..10269b3070de27 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -94,7 +94,7 @@ end context 'for issues tab' do - where(:tab_enabled, :feature_flag_enabled, :project, :condition) do + where(:setting_enabled, :feature_flag_enabled, :project, :condition) do false | false | nil | false false | true | nil | true false | true | ref(:project_double) | false @@ -107,8 +107,7 @@ with_them do before do - stub_feature_flags(global_search_issues_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:issues).and_return(tab_enabled) + stub_application_setting(global_search_issues_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -118,7 +117,7 @@ end context 'for merge requests tab' do - where(:tab_enabled, :feature_flag_enabled, :project, :condition) do + where(:setting_enabled, :feature_flag_enabled, :project, :condition) do false | false | nil | false true | false | nil | true false | false | ref(:project_double) | false @@ -131,8 +130,7 @@ with_them do before do - stub_feature_flags(global_search_merge_requests_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:merge_requests).and_return(tab_enabled) + stub_application_setting(global_search_merge_requests_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -219,7 +217,7 @@ end context 'for users tab' do - where(:feature_flag_enabled, :can_read_users_list, :project, :tab_enabled, :condition) do + where(:setting_enabled, :can_read_users_list, :project, :tab_enabled, :condition) do false | false | ref(:project_double) | true | true false | false | nil | false | false false | true | nil | false | false @@ -230,8 +228,7 @@ with_them do before do - stub_feature_flags(global_search_users_tab: feature_flag_enabled) - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) + stub_application_setting(global_search_users_enabled: setting_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) end @@ -243,7 +240,7 @@ end context 'for snippet_titles tab' do - where(:project, :show_snippets, :feature_flag_enabled, :condition) do + where(:project, :show_snippets, :setting_enabled, :condition) do ref(:project_double) | true | false | false nil | false | false | false ref(:project_double) | false | false | false @@ -258,7 +255,7 @@ let(:options) { { show_snippets: show_snippets } } before do - stub_feature_flags(global_search_snippet_titles_tab: feature_flag_enabled) + stub_application_setting(global_search_snippet_titles_enabled: setting_enabled) end it 'data item condition is set correctly' do diff --git a/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb new file mode 100644 index 00000000000000..84533693995e25 --- /dev/null +++ b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe MigrateGlobalSearchSettingsInApplicationSettings, feature_category: :global_search do + let!(:application_setting) { table(:application_settings).create! } + + describe '#up' do + context 'when search is not already set' do + before do + stub_feature_flags(global_search_code_tab: false) + stub_feature_flags(global_search_commits_tab: false) + stub_feature_flags(global_search_issues_tab: false) + end + + it 'migrates search from the feature flags in the application_settings successfully' do + expected_search = if ::Gitlab.ee? + { + 'global_search_code_enabled' => false, + 'global_search_commits_enabled' => false, + 'global_search_epics_enabled' => true, + 'global_search_issues_enabled' => false, + 'global_search_merge_requests_enabled' => true, + 'global_search_snippet_titles_enabled' => true, + 'global_search_users_enabled' => true, + 'global_search_wiki_enabled' => true + } + else + { + 'global_search_issues_enabled' => false, + 'global_search_merge_requests_enabled' => true, + 'global_search_snippet_titles_enabled' => true, + 'global_search_users_enabled' => true + } + end + + expect { migrate! }.to change { + application_setting.reload.search + }.from({}).to(expected_search) + end + end + end +end diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index 3b61cef054673e..3e8e1eb9f34057 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -419,7 +419,7 @@ context 'global snippet search is disabled' do it 'returns forbidden response' do - stub_feature_flags(global_search_snippet_titles_tab: false) + stub_application_setting(global_search_snippet_titles_enabled: false) get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } expect(response).to have_gitlab_http_status(:forbidden) end @@ -427,7 +427,7 @@ context 'global snippet search is enabled' do it 'returns ok response' do - stub_feature_flags(global_search_snippet_titles_tab: true) + stub_application_setting(global_search_snippet_titles_enabled: true) get api(endpoint, user), params: { search: 'awesome', scope: 'snippet_titles' } expect(response).to have_gitlab_http_status(:ok) end diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index e54218e82f0321..e7dde0ecf6dd48 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -489,21 +489,21 @@ using RSpec::Parameterized::TableSyntax let(:search) { 'foobar' } - where(:scope, :feature_flag, :enabled, :expected) do - '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 - 'users' | :global_search_users_tab | false | false - 'users' | :global_search_users_tab | true | true - 'random' | :random | nil | true + where(:scope, :admin_setting, :setting_enabled, :expected) do + 'issues' | :global_search_issues_enabled | false | false + 'issues' | :global_search_issues_enabled | true | true + 'merge_requests' | :global_search_merge_requests_enabled | false | false + 'merge_requests' | :global_search_merge_requests_enabled | true | true + 'snippet_titles' | :global_search_snippet_titles_enabled | false | false + 'snippet_titles' | :global_search_snippet_titles_enabled | true | true + 'users' | :global_search_users_enabled | false | false + 'users' | :global_search_users_enabled | true | true + 'random' | :random | nil | true end with_them do it 'returns false when feature_flag is not enabled and returns true when feature_flag is enabled' do - stub_feature_flags(feature_flag => enabled) + stub_application_setting(admin_setting => setting_enabled) expect(search_service.global_search_enabled_for_scope?).to eq expected end end @@ -516,13 +516,13 @@ end it 'returns false when feature_flag is not enabled' do - stub_feature_flags(global_search_snippet_titles_tab: false) + stub_application_setting(global_search_snippet_titles_enabled: false) expect(search_service.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) + stub_application_setting(global_search_snippet_titles_enabled: true) expect(search_service.global_search_enabled_for_scope?).to eq true end -- GitLab From 888405e28e1952c53f3d56b3c39d900049d9057b Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 12:56:13 +0000 Subject: [PATCH 09/21] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Arturo Herrero --- ee/app/helpers/ee/application_settings_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/ee/app/helpers/ee/application_settings_helper.rb b/ee/app/helpers/ee/application_settings_helper.rb index 7858e58a0441bc..155810e3b47758 100644 --- a/ee/app/helpers/ee/application_settings_helper.rb +++ b/ee/app/helpers/ee/application_settings_helper.rb @@ -89,7 +89,6 @@ def visible_attributes :secret_detection_service_auth_token, :secret_detection_service_url, :fetch_observability_alerts_from_cloud, - :global_search_merge_requests_enabled, :global_search_code_enabled, :global_search_commits_enabled, :global_search_wiki_enabled, -- GitLab From bc5a11337dd55d9fc5423e8a87e18d33cee15a69 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 14:06:51 +0000 Subject: [PATCH 10/21] Apply 2 suggestion(s) to 2 file(s) Co-authored-by: Arturo Herrero --- ee/spec/lib/search/navigation_spec.rb | 1 + spec/lib/search/navigation_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index cd6aa7f11a335f..71eafe4d5c0989 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -107,6 +107,7 @@ it 'data item condition is set correctly' do stub_application_setting(global_search_epics_enabled: setting_enabled) + expect(tabs[:issues][:sub_items][:epic][:condition]).to eq(condition) end end diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 10269b3070de27..49fb17d99cd54b 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -228,6 +228,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) stub_application_setting(global_search_users_enabled: setting_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) -- GitLab From 045704ea69cb89f9bfd1c5fcadbfbad4cbc37498 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Thu, 30 Jan 2025 20:06:47 +0530 Subject: [PATCH 11/21] Fix failing spec --- ee/spec/controllers/ee/search_controller_spec.rb | 12 ++++++------ ee/spec/lib/search/navigation_spec.rb | 4 ++-- spec/helpers/application_settings_helper_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ee/spec/controllers/ee/search_controller_spec.rb b/ee/spec/controllers/ee/search_controller_spec.rb index 955c275c4ff98a..1c8ce453ca5c56 100644 --- a/ee/spec/controllers/ee/search_controller_spec.rb +++ b/ee/spec/controllers/ee/search_controller_spec.rb @@ -203,15 +203,15 @@ 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' + where(:admin_setting, :scope) do + :global_search_code_enabled | 'blobs' + :global_search_commits_enabled | 'commits' + :global_search_wiki_enabled | 'wiki_blobs' end with_them do it 'returns 200 if flag is enabled' do - stub_feature_flags(feature_flag => true) + stub_application_setting(admin_setting => true) show @@ -219,7 +219,7 @@ end it 'redirects with alert if flag is disabled' do - stub_feature_flags(feature_flag => false) + stub_application_setting(admin_setting => false) show diff --git a/ee/spec/lib/search/navigation_spec.rb b/ee/spec/lib/search/navigation_spec.rb index 71eafe4d5c0989..9b79294c77cf32 100644 --- a/ee/spec/lib/search/navigation_spec.rb +++ b/ee/spec/lib/search/navigation_spec.rb @@ -191,7 +191,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_application_setting(global_search_wikis_enabled: setting_enabled) + stub_application_setting(global_search_wiki_enabled: setting_enabled) end it 'data item condition is set correctly' do @@ -217,7 +217,7 @@ let(:options) { { show_elasticsearch_tabs: show_elasticsearch_tabs } } before do - stub_application_setting(global_search_wikis_enabled: setting_enabled) + stub_application_setting(global_search_wiki_enabled: setting_enabled) end it 'data item condition is set correctly' do diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index c43fa847f89591..6f1dc1704e33a6 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -381,8 +381,8 @@ result = helper.global_search_settings_checkboxes(form) expect(result[0]).to have_checked_field('Enable issues tab in global search results', with: 1) expect(result[1]).not_to have_checked_field('Enable merge requests tab in global search results', with: 1) - expect(result[2]).not_to have_checked_field('Enable users tab in global search results', with: 1) - expect(result[3]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[2]).to have_checked_field('Enable snippet tab in global search results', with: 1) + expect(result[3]).not_to have_checked_field('Enable users tab in global search results', with: 1) end end end -- GitLab From f995961f38356d12488f6d687c0904d1b2198515 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 05:15:37 +0000 Subject: [PATCH 12/21] Apply 2 suggestion(s) to 2 file(s) Co-authored-by: Arturo Herrero --- ...16_migrate_global_search_settings_in_application_settings.rb | 2 +- spec/lib/search/navigation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb index 39b8db1d33dfa8..aff522460c2ad0 100644 --- a/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb +++ b/db/migrate/20250109055316_migrate_global_search_settings_in_application_settings.rb @@ -12,7 +12,7 @@ def up ApplicationSetting.reset_column_information application_setting = ApplicationSetting.last - return if application_setting.nil? + return unless application_setting # rubocop:disable Gitlab/FeatureFlagWithoutActor -- Does not execute in user context search = { diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 49fb17d99cd54b..477b0f5853d7b0 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -228,8 +228,8 @@ with_them do before do - allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) stub_application_setting(global_search_users_enabled: setting_enabled) + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:users).and_return(tab_enabled) allow(search_navigation).to receive(:can?) .with(user, :read_users_list, project_double).and_return(can_read_users_list) end -- GitLab From 003c2d2b4ab696d5d6109758a64bb46302328570 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 11:49:05 +0530 Subject: [PATCH 13/21] Fix failing specs --- .../admin/menus/admin_settings_menu_spec.rb | 20 ------------------- spec/controllers/search_controller_spec.rb | 4 ++-- spec/lib/search/navigation_spec.rb | 6 ++++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb index a6465ea33a1e80..ae90f6070a80f0 100644 --- a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb +++ b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb @@ -75,25 +75,5 @@ end end end - - describe 'Search', feature_category: :global_search do - let(:item_id) { :search } - - context 'when elastic_search feature is not licensed' do - before do - stub_licensed_features(elastic_search: false) - end - - it { is_expected.not_to be_present } - end - - context 'when elastic_search feature is licensed' do - before do - stub_licensed_features(elastic_search: true) - end - - it { is_expected.to be_present } - end - end end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index d9699ed4aaa155..80f63b4049c09d 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -278,7 +278,7 @@ with_them do it 'returns 200 if flag is enabled' do - stub_application_setting(feature_flag => true) + stub_application_setting(admin_setting => true) show @@ -286,7 +286,7 @@ end it 'redirects with alert if flag is disabled' do - stub_application_setting(feature_flag => false) + stub_application_setting(admin_setting => false) show diff --git a/spec/lib/search/navigation_spec.rb b/spec/lib/search/navigation_spec.rb index 477b0f5853d7b0..23a9996ae05fac 100644 --- a/spec/lib/search/navigation_spec.rb +++ b/spec/lib/search/navigation_spec.rb @@ -94,7 +94,7 @@ end context 'for issues tab' do - where(:setting_enabled, :feature_flag_enabled, :project, :condition) do + where(:tab_enabled, :setting_enabled, :project, :condition) do false | false | nil | false false | true | nil | true false | true | ref(:project_double) | false @@ -107,6 +107,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:issues).and_return(tab_enabled) stub_application_setting(global_search_issues_enabled: setting_enabled) end @@ -117,7 +118,7 @@ end context 'for merge requests tab' do - where(:setting_enabled, :feature_flag_enabled, :project, :condition) do + where(:tab_enabled, :setting_enabled, :project, :condition) do false | false | nil | false true | false | nil | true false | false | ref(:project_double) | false @@ -130,6 +131,7 @@ with_them do before do + allow(search_navigation).to receive(:tab_enabled_for_project?).with(:merge_requests).and_return(tab_enabled) stub_application_setting(global_search_merge_requests_enabled: setting_enabled) end -- GitLab From 18a9a8bb020c69d7584493f7399fc252c9431c00 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 11:56:27 +0530 Subject: [PATCH 14/21] Add specs and feature category --- app/controllers/admin/application_settings_controller.rb | 1 + spec/routing/admin_routing_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 3708c885143701..2300687ed4c031 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -36,6 +36,7 @@ class ApplicationSettingsController < Admin::ApplicationController feature_category :integrations, [:integrations, :slack_app_manifest_share, :slack_app_manifest_download] feature_category :pages, [:lets_encrypt_terms_of_service] feature_category :observability, [:reset_error_tracking_access_token] + feature_category :global_search, [:search] VALID_SETTING_PANELS = %w[general repository ci_cd reporting metrics_and_profiling diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index d8f36e01b0fb28..12aaadb3a4c092 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -213,3 +213,10 @@ expect(get("/admin/runners/runner_setup_scripts")).to route_to('admin/runners#runner_setup_scripts') end end + +RSpec.describe Admin::ApplicationSettingsController, 'routing' do + it 'redirects /search to #search' do + expect(get('/admin/application_settings/search')).to route_to('admin/application_settings#search') + expect(patch('/admin/application_settings/search')).to route_to('admin/application_settings#search') + end +end -- GitLab From 1ac942d3e777f87dde2f0ca2c369f06d2191fc60 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 06:39:36 +0000 Subject: [PATCH 15/21] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: DANGER_GITLAB_API_TOKEN --- spec/routing/admin_routing_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index 12aaadb3a4c092..ffb8e9cf974df5 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -214,7 +214,7 @@ end end -RSpec.describe Admin::ApplicationSettingsController, 'routing' do +RSpec.describe Admin::ApplicationSettingsController, 'routing', feature_category: :global_search do it 'redirects /search to #search' do expect(get('/admin/application_settings/search')).to route_to('admin/application_settings#search') expect(patch('/admin/application_settings/search')).to route_to('admin/application_settings#search') -- GitLab From 2c3e0063110a3b13954daa97608e7d2633f2a12b Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 20:08:32 +0530 Subject: [PATCH 16/21] Add the spec without context back --- .../lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb index ae90f6070a80f0..f18639e9a11825 100644 --- a/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb +++ b/ee/spec/lib/ee/sidebars/admin/menus/admin_settings_menu_spec.rb @@ -75,5 +75,11 @@ end end end + + describe 'Search', feature_category: :global_search do + let(:item_id) { :search } + + it { is_expected.to be_present } + end end end -- GitLab From 0436b08d46eb185a56d192fd52bc9129b99e0fe9 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Fri, 31 Jan 2025 15:22:45 +0000 Subject: [PATCH 17/21] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Terri Chu --- ee/app/views/admin/application_settings/search.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/app/views/admin/application_settings/search.html.haml b/ee/app/views/admin/application_settings/search.html.haml index 8bb19aa4d1a0b3..f8d85755768715 100644 --- a/ee/app/views/admin/application_settings/search.html.haml +++ b/ee/app/views/admin/application_settings/search.html.haml @@ -49,6 +49,6 @@ - c.with_body do = s_('AdvancedSearch|You have %{count} pending %{migrations_link_start}advanced search migrations%{link_end} that are obsolete. These migrations might affect your search experience. To resolve the issue, you must %{recreate_link_start}recreate your index%{link_end}.').html_safe % { count: @elasticsearch_pending_obsolete_migrations.count, migrations_link_start: help_advanced_search_migrations_link_start, recreate_link_start: help_recreate_index_link_start, link_end: ''.html_safe } += render_if_exists 'admin/application_settings/global_search_settings' = render_if_exists 'admin/application_settings/elasticsearch_form' = render_if_exists 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) -= render_if_exists 'admin/application_settings/global_search_settings' -- GitLab From c0d7770e65787401697a430af13d0b3d2016a2a3 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Mon, 3 Feb 2025 14:38:13 +0530 Subject: [PATCH 18/21] Fix the undercoverage job --- ...al_search_settings_in_application_settings_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb index 84533693995e25..1c8e51f9dfa3c9 100644 --- a/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb +++ b/spec/migrations/20250109055316_migrate_global_search_settings_in_application_settings_spec.rb @@ -6,6 +6,17 @@ RSpec.describe MigrateGlobalSearchSettingsInApplicationSettings, feature_category: :global_search do let!(:application_setting) { table(:application_settings).create! } + describe '#down' do + let(:migration) { described_class.new } + + context 'when search settings is already set' do + it 'does not update the search settings' do + migration.up + expect { migration.down }.to change { application_setting.reload.search }.to({}) + end + end + end + describe '#up' do context 'when search is not already set' do before do -- GitLab From e4771d59fa7c70d1de1bc23b205458a7b7508339 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Mon, 3 Feb 2025 10:27:05 +0000 Subject: [PATCH 19/21] Apply 1 suggestion(s) to 1 file(s) --- app/views/admin/application_settings/search.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/application_settings/search.html.haml b/app/views/admin/application_settings/search.html.haml index d1d3c21aca00c1..1e6cd122190961 100644 --- a/app/views/admin/application_settings/search.html.haml +++ b/app/views/admin/application_settings/search.html.haml @@ -4,4 +4,4 @@ - add_page_specific_style 'page_bundles/search' - @force_desktop_expanded_sidebar = true -= render_if_exists 'admin/application_settings/global_search_settings' += render 'admin/application_settings/global_search_settings' -- GitLab From 2954d78df92864311970a135347596af456800b9 Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Mon, 3 Feb 2025 17:29:23 +0530 Subject: [PATCH 20/21] Add render for other partials --- ee/app/views/admin/application_settings/search.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/app/views/admin/application_settings/search.html.haml b/ee/app/views/admin/application_settings/search.html.haml index f8d85755768715..f36d325da842b1 100644 --- a/ee/app/views/admin/application_settings/search.html.haml +++ b/ee/app/views/admin/application_settings/search.html.haml @@ -50,5 +50,5 @@ = s_('AdvancedSearch|You have %{count} pending %{migrations_link_start}advanced search migrations%{link_end} that are obsolete. These migrations might affect your search experience. To resolve the issue, you must %{recreate_link_start}recreate your index%{link_end}.').html_safe % { count: @elasticsearch_pending_obsolete_migrations.count, migrations_link_start: help_advanced_search_migrations_link_start, recreate_link_start: help_recreate_index_link_start, link_end: ''.html_safe } = render_if_exists 'admin/application_settings/global_search_settings' -= render_if_exists 'admin/application_settings/elasticsearch_form' -= render_if_exists 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) += render 'admin/application_settings/elasticsearch_form' if License.feature_available?(:elastic_search) += render 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) -- GitLab From 5fc9c700247c843e0093677b454beb4079419bba Mon Sep 17 00:00:00 2001 From: Siddharth Dungarwal Date: Mon, 3 Feb 2025 13:02:59 +0000 Subject: [PATCH 21/21] Apply 1 suggestion(s) to 1 file(s) --- ee/app/views/admin/application_settings/search.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/app/views/admin/application_settings/search.html.haml b/ee/app/views/admin/application_settings/search.html.haml index f36d325da842b1..1bf1155ca165e4 100644 --- a/ee/app/views/admin/application_settings/search.html.haml +++ b/ee/app/views/admin/application_settings/search.html.haml @@ -49,6 +49,6 @@ - c.with_body do = s_('AdvancedSearch|You have %{count} pending %{migrations_link_start}advanced search migrations%{link_end} that are obsolete. These migrations might affect your search experience. To resolve the issue, you must %{recreate_link_start}recreate your index%{link_end}.').html_safe % { count: @elasticsearch_pending_obsolete_migrations.count, migrations_link_start: help_advanced_search_migrations_link_start, recreate_link_start: help_recreate_index_link_start, link_end: ''.html_safe } -= render_if_exists 'admin/application_settings/global_search_settings' += render 'admin/application_settings/global_search_settings' = render 'admin/application_settings/elasticsearch_form' if License.feature_available?(:elastic_search) = render 'admin/application_settings/zoekt_configuration_settings' if ::License.feature_available?(:zoekt_code_search) -- GitLab