fix: Adds condition to handle base and mergee contact being same (#2485)

When an agent updates a contact email in the dashboard and the contact also update his email via the email collect box,
Merge action receives the same base and mergee contacts which could cause data corruption.
This commit is contained in:
Sojan Jose
2021-06-22 15:57:48 +05:30
committed by GitHub
parent 29b9915d3b
commit bd9bac75ad
2 changed files with 12 additions and 0 deletions

View File

@@ -2,6 +2,10 @@ class ContactMergeAction
pattr_initialize [:account!, :base_contact!, :mergee_contact!]
def perform
# This case happens when an agent updates a contact email in dashboard,
# while the contact also update his email via email collect box
return @base_contact if base_contact.id == mergee_contact.id
ActiveRecord::Base.transaction do
validate_contacts
merge_conversations

View File

@@ -19,6 +19,14 @@ describe ::ContactMergeAction do
expect { mergee_contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
context 'when base contact and merge contact are same' do
it 'does not delete contact' do
mergee_contact = base_contact
contact_merge
expect { mergee_contact.reload }.not_to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'when mergee contact has conversations' do
it 'moves the conversations to base contact' do
contact_merge