From 7e3a4d2c20f2cbc1404ed9fce267c85f88e2a8ac Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 30 Mar 2023 11:39:53 +0530 Subject: [PATCH] fix: Adds assignee as a participant during auto-assign (#6789) - Ensures that the assignee is added as a participant during auto-assign --- app/models/concerns/auto_assignment_handler.rb | 1 + app/services/messages/mention_service.rb | 2 +- spec/models/concerns/auto_assignment_handler_shared.rb | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/auto_assignment_handler.rb b/app/models/concerns/auto_assignment_handler.rb index de5fdae7d..059e4db71 100644 --- a/app/models/concerns/auto_assignment_handler.rb +++ b/app/models/concerns/auto_assignment_handler.rb @@ -15,6 +15,7 @@ module AutoAssignmentHandler return unless should_run_auto_assignment? ::AutoAssignment::AgentAssignmentService.new(conversation: self, allowed_agent_ids: inbox.member_ids_with_assignment_capacity).perform + conversation_participants.find_or_create_by(user_id: assignee_id) if assignee_id.present? end def should_run_auto_assignment? diff --git a/app/services/messages/mention_service.rb b/app/services/messages/mention_service.rb index aa8cbfce2..ec7709ae1 100644 --- a/app/services/messages/mention_service.rb +++ b/app/services/messages/mention_service.rb @@ -42,7 +42,7 @@ class Messages::MentionService def add_mentioned_users_as_participants(validated_mentioned_ids) validated_mentioned_ids.each do |user_id| - message.conversation.conversation_participants.find_or_create_by!(user_id: user_id) + message.conversation.conversation_participants.find_or_create_by(user_id: user_id) end end end diff --git a/spec/models/concerns/auto_assignment_handler_shared.rb b/spec/models/concerns/auto_assignment_handler_shared.rb index 90c9c9d20..cef1e17ee 100644 --- a/spec/models/concerns/auto_assignment_handler_shared.rb +++ b/spec/models/concerns/auto_assignment_handler_shared.rb @@ -26,6 +26,10 @@ shared_examples_for 'auto_assignment_handler' do expect(conversation.reload.assignee).to eq(agent) end + it 'adds assignee to conversation participants' do + expect(conversation.conversation_participants.map(&:user)).to include(agent) + end + it 'will not auto assign agent if enable_auto_assignment is false' do inbox.update(enable_auto_assignment: false)