Commit 0d75c6cc authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Prevent new note notifications from Ghost user

When the note author is already deleted, we should skip creation of
notifications and events
parent 6eafea1c
......@@ -13,7 +13,7 @@ class NewNoteWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(note_id, _params = {})
if note = Note.find_by(id: note_id)
NotificationService.new.new_note(note) unless note.skip_notification?
NotificationService.new.new_note(note) unless note.skip_notification? || note.author.ghost?
Notes::PostProcessService.new(note).execute
else
Gitlab::AppLogger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job")
......
---
title: Skip new note notifications when author is deleted
merge_request: 53699
author:
type: changed
......@@ -65,4 +65,14 @@ RSpec.describe NewNoteWorker do
subject.perform(note.id)
end
end
context 'when Note author has been deleted' do
let_it_be(:note) { create(:note, author: User.ghost) }
it "does not call NotificationService" do
expect(NotificationService).not_to receive(:new)
described_class.new.perform(note.id)
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