Fixed issue #206 - Wrong recipient on reply to Received call.

This commit is contained in:
Rolf Schmidt 2017-04-25 16:06:23 +02:00 committed by Thorsten Eckel
parent 06c009255f
commit 87ec273b57
7 changed files with 83 additions and 1 deletions

View file

@ -157,7 +157,7 @@ class ArticleViewItem extends App.ObserverController
new App.WidgetAvatar(
el: @$('.js-avatar')
object_id: article.created_by_id
object_id: article.origin_by_id || article.created_by_id
size: 40
)

View file

@ -34,6 +34,7 @@ module CreatesTicketArticles
if !current_user.permissions?('ticket.agent')
clean_params[:sender_id] = Ticket::Article::Sender.lookup(name: 'Customer').id
clean_params.delete(:sender)
clean_params.delete(:origin_by_id)
type = Ticket::Article::Type.lookup(id: clean_params[:type_id])
if type.name !~ /^(note|web)$/
clean_params[:type_id] = Ticket::Article::Type.lookup(name: 'note').id

View file

@ -0,0 +1,25 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Observer::Ticket::Article::FillupFromOriginById < ActiveRecord::Observer
observe 'ticket::_article'
def before_create(record)
# return if we run import mode
return if Setting.get('import_mode')
# only do fill of from if article got created via application_server (e. g. not
# if article and sender type is set via *.postmaster)
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
# check if origin_by_id exists
return if record.origin_by_id.present?
return if !record.ticket.customer_id
return if record.sender.name != 'Customer'
return if record.type.name != 'phone'
record.origin_by_id = record.ticket.customer_id
user = User.find(record.origin_by_id)
record.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
end
end

View file

@ -27,6 +27,7 @@ module Zammad
'observer::_ticket::_article_changes',
'observer::_ticket::_article::_fillup_from_general',
'observer::_ticket::_article::_fillup_from_email',
'observer::_ticket::_article::_fillup_from_origin_by_id',
'observer::_ticket::_article::_communicate_email',
'observer::_ticket::_article::_communicate_facebook',
'observer::_ticket::_article::_communicate_twitter',

View file

@ -166,6 +166,7 @@ class CreateTicket < ActiveRecord::Migration
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false
t.column :origin_by_id, :integer
t.timestamps limit: 3, null: false
end
add_index :ticket_articles, [:ticket_id]

View file

@ -0,0 +1,9 @@
class AddOriginById < ActiveRecord::Migration
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
add_column :ticket_articles, :origin_by_id, :integer
end
end

View file

@ -280,4 +280,49 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
end
test '03.01 create phone ticket for customer and expected origin_by_id' do
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
params = {
title: 'a new ticket #1',
group: 'Users',
customer_id: @customer_without_org.id,
article: {
body: 'some body',
sender: 'Customer',
type: 'phone',
}
}
post '/api/v1/tickets', params.to_json, @headers.merge('Authorization' => credentials)
assert_response(201)
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
article = Ticket::Article.find_by( ticket_id: result['id'] )
assert_equal(@customer_without_org.id, article.origin_by_id)
assert_equal('Tickets Customer1 <tickets-customer1@example.com>', article.from)
end
test '03.02 create phone ticket by customer and manipulate origin_by_id' do
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
params = {
title: 'a new ticket #1',
group: 'Users',
customer_id: @customer_without_org.id,
article: {
body: 'some body',
sender: 'Customer',
type: 'phone',
origin_by_id: 1,
}
}
post '/api/v1/tickets', params.to_json, @headers.merge('Authorization' => credentials)
assert_response(201)
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
article = Ticket::Article.find_by( ticket_id: result['id'] )
assert_nil(article.origin_by_id)
end
end