diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 7df426a16..c3948d45a 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -1086,7 +1086,7 @@ class App.Utils # the article we are replying to is an outbound call if article.sender.name is 'Agent' 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 else if article.from?.match(/@/) diff --git a/app/models/observer/ticket/article/fillup_from_general.rb b/app/models/observer/ticket/article/fillup_from_general.rb index 4b1a89315..0eba231c6 100644 --- a/app/models/observer/ticket/article/fillup_from_general.rb +++ b/app/models/observer/ticket/article/fillup_from_general.rb @@ -37,8 +37,9 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id end - # in case origin_by_id is customer, force it to set sender to Customer - if record.origin_by != record.created_by_id && !record.origin_by.permissions?('ticket.agent') + # in case origin_by is different than created_by, set sender to Customer + # 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 user_id = record.origin_by_id end diff --git a/spec/factories/ticket/article.rb b/spec/factories/ticket/article.rb index 796dc3fcc..f530ddf99 100644 --- a/spec/factories/ticket/article.rb +++ b/spec/factories/ticket/article.rb @@ -1,9 +1,6 @@ FactoryBot.define do factory :'ticket/article', aliases: %i[ticket_article] do - transient do - type_name { 'email' } - sender_name { 'Customer' } - end + inbound_email association :ticket, strategy: :create # or else build(:ticket_article).save fails from { 'factory-customer-1@example.com' } @@ -17,6 +14,40 @@ FactoryBot.define do updated_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 transient do type_name { 'twitter status' } diff --git a/spec/models/observer/ticket/article/fillup_from_general_spec.rb b/spec/models/observer/ticket/article/fillup_from_general_spec.rb new file mode 100644 index 000000000..c73bfadc5 --- /dev/null +++ b/spec/models/observer/ticket/article/fillup_from_general_spec.rb @@ -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 diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 530ee04b0..abae6b014 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -203,6 +203,48 @@ RSpec.describe 'Ticket zoom', type: :system do 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 describe 'delete article', authenticated_as: :authenticate do