Maintenance: Rework stored 'from' attribute for web and phone articles.
This commit is contained in:
parent
d32ea5e0d3
commit
e90dd791f0
3 changed files with 33 additions and 8 deletions
|
@ -55,7 +55,9 @@ module Ticket::Article::AddsMetadataGeneral
|
||||||
return true if user_id.blank?
|
return true if user_id.blank?
|
||||||
|
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
if type.name == 'web' || type.name == 'phone'
|
is_customer = !TicketPolicy.new(user, ticket).agent_read_access?
|
||||||
|
|
||||||
|
if (type.name == 'web' || type.name == 'phone') && is_customer
|
||||||
self.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
|
self.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,6 +66,13 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :outbound_web do
|
||||||
|
transient do
|
||||||
|
type_name { 'web' }
|
||||||
|
sender_name { 'Agent' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
factory :twitter_article do
|
factory :twitter_article do
|
||||||
transient do
|
transient do
|
||||||
type_name { 'twitter status' }
|
type_name { 'twitter status' }
|
||||||
|
|
|
@ -2,17 +2,33 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Ticket::Article::AddsMetadataGeneral, current_user_id: -> { agent.id } do
|
RSpec.describe Ticket::Article::AddsMetadataGeneral do
|
||||||
let(:agent) { create(:agent) }
|
let(:agent) { create(:agent) }
|
||||||
|
|
||||||
context 'when customer is agent' do
|
context 'when Agent creates Article' do
|
||||||
let(:customer) { create(:agent) }
|
shared_examples 'not including email in from' do |factory|
|
||||||
|
subject(:article) { create(:ticket_article, factory, ticket: ticket, created_by_id: agent.id, updated_by_id: agent.id ) }
|
||||||
|
|
||||||
it 'show customer agent details in from field' do
|
let(:ticket) { create(:ticket) }
|
||||||
ticket = create(:ticket, customer_id: customer.id)
|
let!(:agent) { create(:agent, groups: [ticket.group]) }
|
||||||
article = create(:ticket_article, :inbound_phone, ticket: ticket)
|
|
||||||
|
|
||||||
expect(article.from).to include customer.email
|
it "doesn't include email in from" do
|
||||||
|
expect(article.from).not_to include agent.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like 'not including email in from', :outbound_phone
|
||||||
|
it_behaves_like 'not including email in from', :outbound_web
|
||||||
|
|
||||||
|
context 'when as Customer' do
|
||||||
|
subject(:article) { create(:ticket_article, :inbound_phone, ticket: ticket) }
|
||||||
|
|
||||||
|
let(:customer) { agent }
|
||||||
|
let(:ticket) { create(:ticket, customer_id: customer.id) }
|
||||||
|
|
||||||
|
it 'includes email in from' do
|
||||||
|
expect(article.from).not_to include agent.email
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue