Commit 3b7130d3 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Skip resource and todo processing in Snippet Notes

PersonalSnippets should not have references or todos and
suggestions, so the handling of those during the update of a
note is unneccessary
parent 55c3ea37
...@@ -417,7 +417,7 @@ class Note < ApplicationRecord ...@@ -417,7 +417,7 @@ class Note < ApplicationRecord
end end
def can_create_todo? def can_create_todo?
# Skip system notes, and notes on project snippet # Skip system notes, and notes on snippets
!system? && !for_snippet? !system? && !for_snippet?
end end
......
...@@ -25,7 +25,7 @@ module Notes ...@@ -25,7 +25,7 @@ module Notes
note.note = content note.note = content
end end
unless only_commands unless only_commands || note.for_personal_snippet?
note.create_new_cross_references!(current_user) note.create_new_cross_references!(current_user)
update_todos(note, old_mentioned_users) update_todos(note, old_mentioned_users)
......
...@@ -13,6 +13,17 @@ RSpec.describe Notes::UpdateService do ...@@ -13,6 +13,17 @@ RSpec.describe Notes::UpdateService do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:issue2) { create(:issue, project: private_project) } let(:issue2) { create(:issue, project: private_project) }
let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") } let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") }
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```suggestion
foo
```
```suggestion
bar
```
MARKDOWN
end
before do before do
project.add_maintainer(user) project.add_maintainer(user)
...@@ -48,16 +59,6 @@ RSpec.describe Notes::UpdateService do ...@@ -48,16 +59,6 @@ RSpec.describe Notes::UpdateService do
context 'suggestions' do context 'suggestions' do
it 'refreshes note suggestions' do it 'refreshes note suggestions' do
markdown = <<-MARKDOWN.strip_heredoc
```suggestion
foo
```
```suggestion
bar
```
MARKDOWN
suggestion = create(:suggestion) suggestion = create(:suggestion)
note = suggestion.note note = suggestion.note
...@@ -201,5 +202,24 @@ RSpec.describe Notes::UpdateService do ...@@ -201,5 +202,24 @@ RSpec.describe Notes::UpdateService do
end end
end end
end end
context 'for a personal snippet' do
let_it_be(:snippet) { create(:personal_snippet, :public) }
let(:note) { create(:note, project: nil, noteable: snippet, author: user, note: "Note on a snippet with reference #{issue.to_reference}" ) }
it 'does not create todos' do
expect { update_note({ note: "Mentioning user #{user2}" }) }.not_to change { note.todos.count }
end
it 'does not create suggestions' do
expect { update_note({ note: "Updated snippet with markdown suggestion #{markdown}" }) }
.not_to change { note.suggestions.count }
end
it 'does not create mentions' do
expect(note).not_to receive(:create_new_cross_references!)
update_note({ note: "Updated with new reference: #{issue.to_reference}" })
end
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