chore: Ignore notification when assignee is nil (#11105)

The issue was that when a team change results in an assignee being set
to nil, the system was still trying to create a notification about the
assignment change, but there was no assignee to notify, causing
potential issues in the notification system.
This commit is contained in:
Sojan Jose
2025-03-18 20:14:19 -07:00
committed by GitHub
parent 8066b36ebf
commit e2e4da8b1e
2 changed files with 30 additions and 0 deletions

View File

@@ -30,6 +30,12 @@ class NotificationListener < BaseListener
def assignee_changed(event)
conversation, account = extract_conversation_and_account(event)
assignee = conversation.assignee
# NOTE: The issue was that when a team change results in an assignee being set to nil,
# the system was still trying to create a notification about the assignment change,
# but there was no assignee to notify, causing potential issues in the notification system.
# We need to debug this properly, but for now no need to pollute the jobs
return if assignee.blank?
return if event.data[:notifiable_assignee_change].blank?
return if conversation.pending?

View File

@@ -200,4 +200,28 @@ describe NotificationListener do
end
end
end
describe 'assignee_changed' do
let(:event_name) { :'conversation.assignee_changed' }
context 'when notifiable_assignee_change is true but assignee is nil' do
it 'does not create a notification' do
conversation_with_nil_assignee = create(:conversation, account: account, inbox: inbox, assignee: nil)
notification_builder_mock = instance_double(NotificationBuilder)
allow(NotificationBuilder).to receive(:new).and_return(notification_builder_mock)
event = Events::Base.new(
event_name,
Time.zone.now,
conversation: conversation_with_nil_assignee,
data: { notifiable_assignee_change: true }
)
expect(notification_builder_mock).not_to receive(:perform)
listener.assignee_changed(event)
end
end
end
end