From 8fb46b04488cc5ab4d158b43772f1ca3a383f34b Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Tue, 2 Oct 2018 06:50:04 +0200 Subject: [PATCH] Fixed issue #2184 - Reply does not work as expected (fixes #2184) --- .../javascripts/app/lib/app_post/utils.coffee | 10 +- public/assets/tests/html_utils.js | 98 ++++++++++++++++++- 2 files changed, 102 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index d199a0577..62353dd1c 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -1021,14 +1021,14 @@ class App.Utils if type.name is 'phone' - # inbound call + # the article we are replying to is an outbound call if article.sender.name is 'Agent' - if article.to + if article.to?.match(/@/) articleNew.to = article.to - # outbound call - else if article.to - articleNew.to = article.to + # the article we are replying to is an incoming call + else if article.from?.match(/@/) + articleNew.to = article.from # if sender is customer but in article.from is no email, try to get # customers email via customer user diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index 62204a44f..c105987f4 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -2100,7 +2100,7 @@ test('check getRecipientArticle format', function() { }, } result = { - to: customer.email, + to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id3', @@ -2915,6 +2915,102 @@ test('check getRecipientArticle format', function() { verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) deepEqual(verify, result) + // Regression test for issue #2184 + // Case 1 + // 1. Create a "Received Call" Ticket for article_customer + // 2. Change the Customer of the ticket to ticket_customer (but article.from still points to article_customer) + // 3. Reply to the first Article + // Recipient SHOULD BE Article.from + + var article_customer = { + login: 'login', + firstname: 'article', + lastname: 'lastname', + email: 'article_customer@example.com', + } + var ticket_customer = { + login: 'login2', + firstname: 'ticket', + lastname: 'lastname', + email: 'ticket_customer@example.com', + } + ticket = { + customer: ticket_customer, + } + article = { + type: { + name: 'phone', + }, + sender: { + name: 'Customer', + }, + from: article_customer.email, + to: 'some group', + message_id: 'message_id22', + created_by: { + login: 'login', + firstname: 'firstname', + lastname: 'lastname', + email: 'article_created_by@example.com', + }, + } + result = { + to: 'article_customer@example.com', + cc: '', + body: '', + in_reply_to: 'message_id22', + } + verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) + deepEqual(verify, result) + + // Regression test for issue #2184 + // Case 2 + // 1. Create a "Outbound Call" Ticket for article_customer + // 2. Change the Customer of the Ticket to ticket_customer (but article.to still points to article_customer) + // 3. Reply to the first Article + // Recipient SHOULD BE Article.to + + article_customer = { + login: 'login', + firstname: 'article', + lastname: 'lastname', + email: 'article_customer@example.com', + } + ticket_customer = { + login: 'login2', + firstname: 'ticket', + lastname: 'lastname', + email: 'ticket_customer@example.com', + } + ticket = { + customer: ticket_customer, + } + article = { + type: { + name: 'phone', + }, + sender: { + name: 'Agent', + }, + from: 'agent1@example.com', + to: article_customer.email, + message_id: 'message_id23', + created_by: { + login: 'login', + firstname: 'firstname', + lastname: 'lastname', + email: 'article_created_by@example.com', + }, + } + result = { + to: 'article_customer@example.com', + cc: '', + body: '', + in_reply_to: 'message_id23', + } + verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) + deepEqual(verify, result) + }); test("contentTypeCleanup", function() {