diff --git a/app/models/observer/ticket/reset_new_state.rb b/app/models/observer/ticket/reset_new_state.rb index 3c426526c..c676b0391 100644 --- a/app/models/observer/ticket/reset_new_state.rb +++ b/app/models/observer/ticket/reset_new_state.rb @@ -8,6 +8,9 @@ class Observer::Ticket::ResetNewState < ActiveRecord::Observer # return if we run 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 return true if record.internal diff --git a/test/unit/email_process_sender_is_system_address_or_agent_test.rb b/test/unit/email_process_sender_is_system_address_or_agent_test.rb index 47c0f62e4..bd0b7093b 100644 --- a/test/unit/email_process_sender_is_system_address_or_agent_test.rb +++ b/test/unit/email_process_sender_is_system_address_or_agent_test.rb @@ -46,7 +46,7 @@ Some Text" article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('me+is+customer@example.com', ticket.customer.email) @@ -152,7 +152,7 @@ Some Text" ticket = Ticket.find(ticket_p.id) article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) @@ -169,7 +169,7 @@ Some Text" ticket = Ticket.find(ticket_p.id) article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) @@ -186,7 +186,7 @@ Some Text" ticket = Ticket.find(ticket_p.id) article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email) @@ -203,7 +203,7 @@ Some Text" ticket = Ticket.find(ticket_p.id) article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email) @@ -220,7 +220,7 @@ Some Text" ticket = Ticket.find(ticket_p.id) article = Ticket::Article.find(article_p.id) 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', article.sender.name) assert_equal('ticket-system-sender-agent1@example.com', ticket.customer.email) diff --git a/test/unit/email_process_state_open_set.rb b/test/unit/email_process_state_open_set.rb new file mode 100644 index 000000000..6ae4bf578 --- /dev/null +++ b/test/unit/email_process_state_open_set.rb @@ -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