Fixes #2922 - Replying on newly created phone notes to agent customers sets wrong TO-address.
This commit is contained in:
parent
1b3d2417e2
commit
97fc711370
5 changed files with 97 additions and 7 deletions
|
@ -1086,7 +1086,7 @@ class App.Utils
|
||||||
# the article we are replying to is an outbound call
|
# the article we are replying to is an outbound call
|
||||||
if article.sender.name is 'Agent'
|
if article.sender.name is 'Agent'
|
||||||
if article.to?.match(/@/)
|
if article.to?.match(/@/)
|
||||||
articleNew.to = article.to
|
articleNew.to = App.Utils.parseAddressListLocal(article.to).join(', ')
|
||||||
|
|
||||||
# the article we are replying to is an incoming call
|
# the article we are replying to is an incoming call
|
||||||
else if article.from?.match(/@/)
|
else if article.from?.match(/@/)
|
||||||
|
|
|
@ -37,8 +37,9 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
|
||||||
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
||||||
end
|
end
|
||||||
|
|
||||||
# in case origin_by_id is customer, force it to set sender to Customer
|
# in case origin_by is different than created_by, set sender to Customer
|
||||||
if record.origin_by != record.created_by_id && !record.origin_by.permissions?('ticket.agent')
|
# Customer in context of this conversation, not as a permission
|
||||||
|
if record.origin_by != record.created_by_id
|
||||||
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
||||||
user_id = record.origin_by_id
|
user_id = record.origin_by_id
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :'ticket/article', aliases: %i[ticket_article] do
|
factory :'ticket/article', aliases: %i[ticket_article] do
|
||||||
transient do
|
inbound_email
|
||||||
type_name { 'email' }
|
|
||||||
sender_name { 'Customer' }
|
|
||||||
end
|
|
||||||
|
|
||||||
association :ticket, strategy: :create # or else build(:ticket_article).save fails
|
association :ticket, strategy: :create # or else build(:ticket_article).save fails
|
||||||
from { 'factory-customer-1@example.com' }
|
from { 'factory-customer-1@example.com' }
|
||||||
|
@ -17,6 +14,40 @@ FactoryBot.define do
|
||||||
updated_by_id { 1 }
|
updated_by_id { 1 }
|
||||||
created_by_id { 1 }
|
created_by_id { 1 }
|
||||||
|
|
||||||
|
trait :inbound_email do
|
||||||
|
transient do
|
||||||
|
type_name { 'email' }
|
||||||
|
sender_name { 'Customer' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :outbound_email do
|
||||||
|
transient do
|
||||||
|
type_name { 'email' }
|
||||||
|
sender_name { 'Agent' }
|
||||||
|
end
|
||||||
|
|
||||||
|
from { ticket.group.name }
|
||||||
|
to { "#{ticket.customer.fullname} <#{ticket.customer.email}>" }
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :inbound_phone do
|
||||||
|
transient do
|
||||||
|
type_name { 'phone' }
|
||||||
|
sender_name { 'Customer' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :outbound_phone do
|
||||||
|
transient do
|
||||||
|
type_name { 'phone' }
|
||||||
|
sender_name { 'Agent' }
|
||||||
|
end
|
||||||
|
|
||||||
|
from { nil }
|
||||||
|
to { ticket.customer.fullname }
|
||||||
|
end
|
||||||
|
|
||||||
factory :twitter_article do
|
factory :twitter_article do
|
||||||
transient do
|
transient do
|
||||||
type_name { 'twitter status' }
|
type_name { 'twitter status' }
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Observer::Ticket::Article::FillupFromGeneral, current_user_id: -> { agent.id } do
|
||||||
|
let(:agent) { create(:agent) }
|
||||||
|
|
||||||
|
context 'when customer is agent' do
|
||||||
|
let(:customer) { create(:agent) }
|
||||||
|
|
||||||
|
it 'show customer agent details in from field' do
|
||||||
|
ticket = create(:ticket, customer_id: customer.id)
|
||||||
|
article = create(:ticket_article, :inbound_phone, ticket: ticket)
|
||||||
|
|
||||||
|
expect(article.from).to include customer.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -203,6 +203,48 @@ RSpec.describe 'Ticket zoom', type: :system do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'to inbound phone call', current_user_id: -> { agent.id }, authenticated_as: -> { agent } do
|
||||||
|
let(:agent) { create(:agent, groups: [Group.first]) }
|
||||||
|
let(:customer) { create(:agent) }
|
||||||
|
let(:ticket) { create(:ticket, customer: customer, group: agent.groups.first) }
|
||||||
|
let!(:article) { create(:ticket_article, :inbound_phone, ticket: ticket) }
|
||||||
|
|
||||||
|
it 'goes to customer email' do
|
||||||
|
visit "ticket/zoom/#{ticket.id}"
|
||||||
|
|
||||||
|
within :active_ticket_article, article do
|
||||||
|
click '.js-ArticleAction[data-type=emailReply]'
|
||||||
|
end
|
||||||
|
|
||||||
|
within :active_content do
|
||||||
|
within '.article-new' do
|
||||||
|
expect(find('[name=to]', visible: :all).value).to eq customer.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'to outbound phone call', current_user_id: -> { agent.id }, authenticated_as: -> { agent } do
|
||||||
|
let(:agent) { create(:agent, groups: [Group.first]) }
|
||||||
|
let(:customer) { create(:agent) }
|
||||||
|
let(:ticket) { create(:ticket, customer: customer, group: agent.groups.first) }
|
||||||
|
let!(:article) { create(:ticket_article, :outbound_phone, ticket: ticket) }
|
||||||
|
|
||||||
|
it 'goes to customer email' do
|
||||||
|
visit "ticket/zoom/#{ticket.id}"
|
||||||
|
|
||||||
|
within :active_ticket_article, article do
|
||||||
|
click '.js-ArticleAction[data-type=emailReply]'
|
||||||
|
end
|
||||||
|
|
||||||
|
within :active_content do
|
||||||
|
within '.article-new' do
|
||||||
|
expect(find('[name=to]', visible: :all).value).to eq customer.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'delete article', authenticated_as: :authenticate do
|
describe 'delete article', authenticated_as: :authenticate do
|
||||||
|
|
Loading…
Reference in a new issue