Fixed issue #1482 - Tickets sent by agent via email into Zammad have state open (not new).

This commit is contained in:
Martin Edenhofer 2017-09-27 20:12:21 +02:00
parent 88feeb38ba
commit 977cb07dc9
3 changed files with 161 additions and 6 deletions

View file

@ -8,6 +8,9 @@ class Observer::Ticket::ResetNewState < ActiveRecord::Observer
# return if we run import mode # return if we run import mode
return if Setting.get('import_mode') return if Setting.get('import_mode')
# only change state if not processed via postmaster
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
# if article in internal # if article in internal
return true if record.internal return true if record.internal

View file

@ -46,7 +46,7 @@ Some Text"
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal(subject, ticket.title) assert_equal(subject, ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('me+is+customer@example.com', ticket.customer.email) assert_equal('me+is+customer@example.com', ticket.customer.email)
@ -152,7 +152,7 @@ Some Text"
ticket = Ticket.find(ticket_p.id) ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal('some subject #2', ticket.title) assert_equal('some subject #2', ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
@ -169,7 +169,7 @@ Some Text"
ticket = Ticket.find(ticket_p.id) ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal('some subject #3', ticket.title) assert_equal('some subject #3', ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
@ -186,7 +186,7 @@ Some Text"
ticket = Ticket.find(ticket_p.id) ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal('some subject #4', ticket.title) assert_equal('some subject #4', ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
@ -203,7 +203,7 @@ Some Text"
ticket = Ticket.find(ticket_p.id) ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal('some subject #5', ticket.title) assert_equal('some subject #5', ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email) assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email)
@ -220,7 +220,7 @@ Some Text"
ticket = Ticket.find(ticket_p.id) ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id) article = Ticket::Article.find(article_p.id)
assert_equal('some subject #6', ticket.title) assert_equal('some subject #6', ticket.title)
assert_equal('open', ticket.state.name) assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name) assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name) assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email) assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email)

View file

@ -0,0 +1,152 @@
# encoding: utf-8
require 'test_helper'
class EmailProcessStateOpenSet < ActiveSupport::TestCase
setup do
groups = Group.all
roles = Role.where(name: 'Agent')
@agent1 = User.create_or_update(
login: 'agent-ticket-state-open-set@example.com',
firstname: 'StateOpenSet',
lastname: 'Agent1',
email: 'agent-ticket-state-open-set@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: groups,
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
@customer1 = User.create_or_update(
login: 'customer-ticket-state-open-set@example.com',
firstname: 'StateOpenSet',
lastname: 'Customer',
email: 'customer-ticket-state-open-set@example.com',
password: 'customerpw',
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
end
test 'new as agent' do
email_raw_string = "From: agent-ticket-state-open-set@example.com
To: customer-ticket-state-open-set@example.com
Subject: test sender is agent
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id)
assert_equal('test sender is agent', ticket.title)
assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
article = Ticket::Article.create!(
ticket_id: ticket.id,
type_id: Ticket::Article::Type.find_by(name: 'email').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
body: 'test',
internal: false,
updated_by_id: @customer1.id,
created_by_id: @customer1.id,
)
ticket.reload
assert_equal('test sender is agent', ticket.title)
assert_equal('new', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Customer', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
article = Ticket::Article.create!(
ticket_id: ticket.id,
type_id: Ticket::Article::Type.find_by(name: 'email').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
body: 'test',
internal: false,
updated_by_id: @agent1.id,
created_by_id: @agent1.id,
)
ticket.reload
assert_equal('test sender is agent', ticket.title)
assert_equal('open', ticket.state.name)
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
end
test 'new as customer' do
email_raw_string = "From: customer-ticket-state-open-set@example.com
To: agent-ticket-state-open-set@example.com
Subject: test sender is customer
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket_p.id)
article = Ticket::Article.find(article_p.id)
assert_equal('test sender is customer', ticket.title)
assert_equal('new', ticket.state.name)
assert_equal('Customer', ticket.create_article_sender.name)
assert_equal('Customer', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
article = Ticket::Article.create!(
ticket_id: ticket.id,
type_id: Ticket::Article::Type.find_by(name: 'email').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
body: 'test',
internal: false,
updated_by_id: @customer1.id,
created_by_id: @customer1.id,
)
ticket.reload
assert_equal('test sender is customer', ticket.title)
assert_equal('new', ticket.state.name)
assert_equal('Customer', ticket.create_article_sender.name)
assert_equal('Customer', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
article = Ticket::Article.create!(
ticket_id: ticket.id,
type_id: Ticket::Article::Type.find_by(name: 'email').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Agent').id,
body: 'test',
internal: false,
updated_by_id: @agent1.id,
created_by_id: @agent1.id,
)
ticket.reload
assert_equal('test sender is customer', ticket.title)
assert_equal('open', ticket.state.name)
assert_equal('Customer', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('customer-ticket-state-open-set@example.com', ticket.customer.email)
assert_equal('StateOpenSet', ticket.customer.firstname)
assert_equal('Customer', ticket.customer.lastname)
end
end