Commit 2e3c2a35 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch 'snippets-with-comments-cause-a-500-when-they-show-up-in-search-results-14764' into 'master'

Fix Error 500 when searching for a comment in a project snippet

Closes #14764. /cc @stanhu, and thank you for the spec! ;)

See merge request !3468
parents 670f8540 e60f0341
...@@ -27,6 +27,9 @@ v 8.6.3 ...@@ -27,6 +27,9 @@ v 8.6.3
v 8.6.3 (unreleased) v 8.6.3 (unreleased)
- Mentions on confidential issues doesn't create todos for non-members - Mentions on confidential issues doesn't create todos for non-members
v 8.6.3 (unreleased)
- Fix Error 500 when searching for a comment in a project snippet. !3468
v 8.6.2 v 8.6.2
- Fix dropdown alignment. !3298 - Fix dropdown alignment. !3298
- Fix issuable sidebar overlaps on tablet. !3299 - Fix issuable sidebar overlaps on tablet. !3299
......
...@@ -311,7 +311,7 @@ class Note < ActiveRecord::Base ...@@ -311,7 +311,7 @@ class Note < ActiveRecord::Base
for_merge_request? && for_diff_line? for_merge_request? && for_diff_line?
end end
def for_project_snippet? def for_snippet?
noteable_type == "Snippet" noteable_type == "Snippet"
end end
......
...@@ -123,7 +123,7 @@ class TodoService ...@@ -123,7 +123,7 @@ class TodoService
def handle_note(note, author) def handle_note(note, author)
# Skip system notes, and notes on project snippet # Skip system notes, and notes on project snippet
return if note.system? || note.for_project_snippet? return if note.system? || note.for_snippet?
project = note.project project = note.project
target = note.noteable target = note.noteable
......
- project = note.project - project = note.project
- note_url = Gitlab::UrlBuilder.new(:note).build(note.id)
- noteable_identifier = note.noteable.try(:iid) || note.noteable.id
.search-result-row .search-result-row
%h5.note-search-caption.str-truncated %h5.note-search-caption.str-truncated
%i.fa.fa-comment %i.fa.fa-comment
= link_to_member(project, note.author, avatar: false) = link_to_member(project, note.author, avatar: false)
commented on commented on
= link_to project.name_with_namespace, project
&middot;
- if note.for_commit? - if note.for_commit?
= link_to project do = link_to "Commit #{truncate_sha(note.commit_id)}", note_url
= project.name_with_namespace
&middot;
= link_to namespace_project_commit_path(project.namespace, project, note.commit_id, anchor: dom_id(note)) do
Commit #{truncate_sha(note.commit_id)}
- else - else
= link_to project do %span #{note.noteable_type.titleize} ##{noteable_identifier}
= project.name_with_namespace
&middot;
%span #{note.noteable_type.titleize} ##{note.noteable.iid}
&middot; &middot;
= link_to [project.namespace.becomes(Namespace), project, note.noteable, anchor: dom_id(note)] do = link_to note.noteable.title, note_url
= note.noteable.title
.note-search-result .note-search-result
.term .term
......
...@@ -41,7 +41,7 @@ module Gitlab ...@@ -41,7 +41,7 @@ module Gitlab
data[:issue] = note.noteable.hook_attrs data[:issue] = note.noteable.hook_attrs
elsif note.for_merge_request? elsif note.for_merge_request?
data[:merge_request] = note.noteable.hook_attrs data[:merge_request] = note.noteable.hook_attrs
elsif note.for_project_snippet? elsif note.for_snippet?
data[:snippet] = note.noteable.hook_attrs data[:snippet] = note.noteable.hook_attrs
end end
......
...@@ -2,6 +2,7 @@ module Gitlab ...@@ -2,6 +2,7 @@ module Gitlab
class UrlBuilder class UrlBuilder
include Gitlab::Application.routes.url_helpers include Gitlab::Application.routes.url_helpers
include GitlabRoutingHelper include GitlabRoutingHelper
include ActionView::RecordIdentifier
def initialize(type) def initialize(type)
@type = type @type = type
...@@ -37,19 +38,16 @@ module Gitlab ...@@ -37,19 +38,16 @@ module Gitlab
namespace_project_commit_url(namespace_id: note.project.namespace, namespace_project_commit_url(namespace_id: note.project.namespace,
id: note.commit_id, id: note.commit_id,
project_id: note.project, project_id: note.project,
anchor: "note_#{note.id}") anchor: dom_id(note))
elsif note.for_issue? elsif note.for_issue?
issue = Issue.find(note.noteable_id) issue = Issue.find(note.noteable_id)
issue_url(issue, issue_url(issue, anchor: dom_id(note))
anchor: "note_#{note.id}")
elsif note.for_merge_request? elsif note.for_merge_request?
merge_request = MergeRequest.find(note.noteable_id) merge_request = MergeRequest.find(note.noteable_id)
merge_request_url(merge_request, merge_request_url(merge_request, anchor: dom_id(note))
anchor: "note_#{note.id}") elsif note.for_snippet?
elsif note.for_project_snippet?
snippet = Snippet.find(note.noteable_id) snippet = Snippet.find(note.noteable_id)
project_snippet_url(snippet, project_snippet_url(snippet, anchor: dom_id(note))
anchor: "note_#{note.id}")
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe "Search", feature: true do describe "Search", feature: true do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
before do before do
login_as :user login_with(user)
@project = create(:project, namespace: @user.namespace) project.team << [user, :reporter]
@project.team << [@user, :reporter]
visit search_path visit search_path
end
page.within '.search-holder' do describe 'searching for Projects' do
fill_in "search", with: @project.name[0..3] it 'finds a project' do
click_button "Search" page.within '.search-holder' do
fill_in "search", with: project.name[0..3]
click_button "Search"
end
expect(page).to have_content project.name
end end
end end
it "should show project in search results" do context 'search for comments' do
expect(page).to have_content @project.name it 'finds a snippet' do
snippet = create(:project_snippet, :private, project: project, author: user, title: 'Some title')
note = create(:note,
noteable: snippet,
author: user,
note: 'Supercalifragilisticexpialidocious',
project: project)
# Must visit project dashboard since global search won't search
# everything (e.g. comments, snippets, etc.)
visit namespace_project_path(project.namespace, project)
page.within '.search' do
fill_in 'search', with: note.note
click_button 'Go'
end
click_link 'Comments'
expect(page).to have_link(snippet.title)
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment