diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /app/helpers/search_helper.rb | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r-- | app/helpers/search_helper.rb | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index b8ac2afa7d6..e03365ad5f1 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -40,6 +40,7 @@ module SearchHelper [ groups_autocomplete(term), projects_autocomplete(term), + users_autocomplete(term), issue_autocomplete(term) ].flatten end @@ -308,8 +309,8 @@ module SearchHelper { category: "Groups", id: group.id, - value: "#{search_result_sanitize(group.name)}", - label: "#{search_result_sanitize(group.full_name)}", + value: search_result_sanitize(group.name), + label: search_result_sanitize(group.full_name), url: group_path(group), avatar_url: group.avatar_url || '' } @@ -343,14 +344,32 @@ module SearchHelper { category: "Projects", id: p.id, - value: "#{search_result_sanitize(p.name)}", - label: "#{search_result_sanitize(p.full_name)}", + value: search_result_sanitize(p.name), + label: search_result_sanitize(p.full_name), url: project_path(p), avatar_url: p.avatar_url || '' } end end + def users_autocomplete(term, limit = 5) + return [] unless current_user && Ability.allowed?(current_user, :read_users_list) + + SearchService + .new(current_user, { scope: 'users', per_page: limit, search: term }) + .search_objects + .map do |user| + { + category: "Users", + id: user.id, + value: search_result_sanitize(user.name), + label: search_result_sanitize(user.username), + url: user_path(user), + avatar_url: user.avatar_url || '' + } + end + end + def recent_merge_requests_autocomplete(term) return [] unless current_user @@ -427,20 +446,38 @@ module SearchHelper result end + def code_tab_condition + return true if project_search_tabs?(:blobs) + + @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_code_tab) + end + + def wiki_tab_condition + return true if project_search_tabs?(:wiki) + + @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_wiki_tab) + end + + def commits_tab_condition + return true if project_search_tabs?(:commits) + + @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_commits_tab) + end + # search page scope navigation def search_navigation { projects: { sort: 1, label: _("Projects"), data: { qa_selector: 'projects_tab' }, condition: @project.nil? }, - blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: project_search_tabs?(:blobs) || (search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_code_tab)) }, + blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: code_tab_condition }, # sort: 3 is reserved for EE items issues: { sort: 4, label: _("Issues"), condition: project_search_tabs?(:issues) || feature_flag_tab_enabled?(:global_search_issues_tab) }, merge_requests: { sort: 5, label: _("Merge requests"), condition: project_search_tabs?(:merge_requests) || feature_flag_tab_enabled?(:global_search_merge_requests_tab) }, - wiki_blobs: { sort: 6, label: _("Wiki"), condition: project_search_tabs?(:wiki) || search_service.show_elasticsearch_tabs? }, - commits: { sort: 7, label: _("Commits"), condition: project_search_tabs?(:commits) || (search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_commits_tab)) }, + wiki_blobs: { sort: 6, label: _("Wiki"), condition: wiki_tab_condition }, + commits: { sort: 7, label: _("Commits"), condition: commits_tab_condition }, notes: { sort: 8, label: _("Comments"), condition: project_search_tabs?(:notes) || search_service.show_elasticsearch_tabs? }, milestones: { sort: 9, label: _("Milestones"), condition: project_search_tabs?(:milestones) || @project.nil? }, - users: { sort: 10, label: _("Users"), condition: show_user_search_tab? }, - snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: @show_snippets.present? && @project.nil? } + users: { sort: 10, label: _("Users"), condition: show_user_search_tab? }, + snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: search_service.show_snippets? && @project.nil? } } end @@ -545,12 +582,10 @@ module SearchHelper else :success end + elsif issuable.closed? + :info else - if issuable.closed? - :info - else - :success - end + :success end end @@ -566,7 +601,7 @@ module SearchHelper end def feature_flag_tab_enabled?(flag) - @group || Feature.enabled?(flag, current_user, type: :ops) + @group.present? || Feature.enabled?(flag, current_user, type: :ops) end def sanitized_search_params |