diff --git a/app/models/concerns/assignment_handler.rb b/app/models/concerns/assignment_handler.rb index dde962ba1..9f9b7a79e 100644 --- a/app/models/concerns/assignment_handler.rb +++ b/app/models/concerns/assignment_handler.rb @@ -4,7 +4,7 @@ module AssignmentHandler included do before_save :ensure_assignee_is_from_team - after_commit :notify_assignment_change, :process_assignment_activities + after_commit :notify_assignment_change, :process_assignment_changes end private @@ -36,6 +36,11 @@ module AssignmentHandler end end + def process_assignment_changes + process_assignment_activities + process_participant_assignment + end + def process_assignment_activities user_name = Current.user.name if Current.user.present? if saved_change_to_team_id? @@ -44,4 +49,9 @@ module AssignmentHandler create_assignee_change_activity(user_name) end end + + def process_participant_assignment + return unless saved_change_to_assignee_id? && assignee_id.present? + self.conversation_participants.find_or_create_by!(user_id: assignee_id) + end end diff --git a/spec/models/concerns/assignment_handler_shared.rb b/spec/models/concerns/assignment_handler_shared.rb index 816351248..0fff7777a 100644 --- a/spec/models/concerns/assignment_handler_shared.rb +++ b/spec/models/concerns/assignment_handler_shared.rb @@ -85,6 +85,10 @@ shared_examples_for 'assignment_handler' do expect(update_assignee).to be(true) end + it 'adds assignee to conversation participants' do + expect { update_assignee }.to change { conversation.conversation_participants.count }.by(1) + end + context 'when agent is current user' do before do Current.user = agent