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:
@@ -30,6 +30,12 @@ class NotificationListener < BaseListener
|
|||||||
def assignee_changed(event)
|
def assignee_changed(event)
|
||||||
conversation, account = extract_conversation_and_account(event)
|
conversation, account = extract_conversation_and_account(event)
|
||||||
assignee = conversation.assignee
|
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 event.data[:notifiable_assignee_change].blank?
|
||||||
return if conversation.pending?
|
return if conversation.pending?
|
||||||
|
|
||||||
|
|||||||
@@ -200,4 +200,28 @@ describe NotificationListener do
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user