Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-22 15:08:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-22 15:08:41 +0300
commitedd183a633915eacd9b73cab43ea839a4cd42bf6 (patch)
treee950000a90a3ebf05d135b5add8e569fafffbd38 /app/helpers/search_helper.rb
parent9dab4d7b6492628eb9222f14954fdd8889bd6e34 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r--app/helpers/search_helper.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index 6b27ab6a4e2..ae7882c0013 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -20,7 +20,8 @@ module SearchHelper
resources_results = [
recent_items_autocomplete(term),
groups_autocomplete(term),
- projects_autocomplete(term)
+ projects_autocomplete(term),
+ issue_autocomplete(term)
].flatten
search_pattern = Regexp.new(Regexp.escape(term), "i")
@@ -183,6 +184,24 @@ module SearchHelper
end
# rubocop: enable CodeReuse/ActiveRecord
+ def issue_autocomplete(term)
+ return [] unless @project.present? && current_user && term =~ /\A#{Issue.reference_prefix}\d+\z/
+
+ iid = term.sub(Issue.reference_prefix, '').to_i
+ issue = @project.issues.find_by_iid(iid)
+ return [] unless issue && Ability.allowed?(current_user, :read_issue, issue)
+
+ [
+ {
+ category: 'In this project',
+ id: issue.id,
+ label: search_result_sanitize("#{issue.title} (#{issue.to_reference})"),
+ url: issue_path(issue),
+ avatar_url: issue.project.avatar_url || ''
+ }
+ ]
+ end
+
# Autocomplete results for the current user's projects
# rubocop: disable CodeReuse/ActiveRecord
def projects_autocomplete(term, limit = 5)