Overwrite article from based on current user.
This commit is contained in:
parent
2078a079cd
commit
2f6eb168a2
4 changed files with 35 additions and 13 deletions
|
@ -35,7 +35,7 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
||||||
# generate message id, force it in prodution, in test allow to set it for testing reasons
|
# generate message id, force it in prodution, in test allow to set it for testing reasons
|
||||||
if !record.message_id || Rails.env.production?
|
if !record.message_id || Rails.env.production?
|
||||||
fqdn = Setting.get('fqdn')
|
fqdn = Setting.get('fqdn')
|
||||||
record.message_id = '<' + DateTime.current.to_s(:number) + '.' + record.ticket_id.to_s + '.' + rand(999_999).to_s() + '@' + fqdn + '>'
|
record.message_id = "<#{DateTime.current.to_s(:number)}.#{record.ticket_id}.#{rand(999_999)}@#{fqdn}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
# generate message_id_md5
|
# generate message_id_md5
|
||||||
|
|
|
@ -12,14 +12,10 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
|
||||||
# if article and sender type is set via *.postmaster)
|
# if article and sender type is set via *.postmaster)
|
||||||
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
# if sender is customer, do not change anything
|
# set from on all article types excluding email
|
||||||
return if !record.sender_id
|
return if !record.type_id
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
||||||
return if sender.nil?
|
return if type['name'] == 'email'
|
||||||
return if sender['name'] == 'Customer'
|
|
||||||
|
|
||||||
# set from if not given
|
|
||||||
return if record.from
|
|
||||||
|
|
||||||
return if !record.created_by_id
|
return if !record.created_by_id
|
||||||
user = User.find(record.created_by_id)
|
user = User.find(record.created_by_id)
|
||||||
|
|
|
@ -246,6 +246,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Agent', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -258,6 +259,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_response(200)
|
assert_response(200)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
from: 'something which should not be changed on server side',
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
subject: 'some subject',
|
subject: 'some subject',
|
||||||
body: 'some body',
|
body: 'some body',
|
||||||
|
@ -269,6 +271,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Agent via Zammad <zammad@localhost>', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -285,6 +288,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Agent via Zammad <zammad@localhost>', result['from'])
|
||||||
assert_equal('new subject', result['subject'])
|
assert_equal('new subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -342,6 +346,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal(1, result['created_by_id'])
|
assert_equal(1, result['created_by_id'])
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
from: 'something which should not be changed on server side',
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
subject: 'some subject',
|
subject: 'some subject',
|
||||||
body: 'some body',
|
body: 'some body',
|
||||||
|
@ -351,6 +356,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Admin', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -368,6 +374,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Admin', result['from'])
|
||||||
assert_equal('new subject', result['subject'])
|
assert_equal('new subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -390,6 +397,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Admin via Zammad <zammad@localhost>', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -530,6 +538,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Customer1', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -555,6 +564,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Customer1', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
@ -569,6 +579,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal('Not authorized (admin permission required)!', result['error'])
|
assert_equal('Not authorized (admin permission required)!', result['error'])
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
|
from: 'something which should not be changed on server side',
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
subject: 'some subject',
|
subject: 'some subject',
|
||||||
body: 'some body',
|
body: 'some body',
|
||||||
|
@ -582,6 +593,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
||||||
result = JSON.parse(@response.body)
|
result = JSON.parse(@response.body)
|
||||||
assert_equal(Hash, result.class)
|
assert_equal(Hash, result.class)
|
||||||
assert_equal(ticket.id, result['ticket_id'])
|
assert_equal(ticket.id, result['ticket_id'])
|
||||||
|
assert_equal('Tickets Customer1', result['from'])
|
||||||
assert_equal('some subject', result['subject'])
|
assert_equal('some subject', result['subject'])
|
||||||
assert_equal('some body', result['body'])
|
assert_equal('some body', result['body'])
|
||||||
assert_equal('text/plain', result['content_type'])
|
assert_equal('text/plain', result['content_type'])
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: "some <b>title</b>\n äöüß",
|
title: "some <b>title</b>\n äöüß",
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer_id: 2,
|
customer: User.lookup(email: 'nicole.braun@zammad.org'),
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
|
@ -78,6 +78,8 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
article1 = ticket1.articles.last
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Zammad <zammad@localhost>', article1.from)
|
||||||
|
assert_match('nicole.braun@zammad.org', article1.to)
|
||||||
assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
|
assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
|
||||||
assert_match('Braun<br>some <b>title</b>', article1.body)
|
assert_match('Braun<br>some <b>title</b>', article1.body)
|
||||||
assert_equal('text/html', article1.content_type)
|
assert_equal('text/html', article1.content_type)
|
||||||
|
@ -118,11 +120,17 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
|
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Zammad <zammad@localhost>', article1.from)
|
||||||
|
assert_match('nicole.braun@zammad.org', article1.to)
|
||||||
|
assert_match('Thanks for your inquiry (some <b>title</b> äöüß)!', article1.subject)
|
||||||
|
assert_match('Braun<br>some <b>title</b>', article1.body)
|
||||||
|
assert_equal('text/html', article1.content_type)
|
||||||
|
|
||||||
ticket2 = Ticket.create(
|
ticket2 = Ticket.create(
|
||||||
title: "some title\n äöüß",
|
title: "some title\n äöüß",
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer_id: 2,
|
customer: User.lookup(email: 'nicole.braun@zammad.org'),
|
||||||
state: Ticket::State.lookup(name: 'open'),
|
state: Ticket::State.lookup(name: 'open'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
|
@ -182,7 +190,7 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: "some title\n äöüß",
|
title: "some title\n äöüß",
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer_id: 2,
|
customer: User.lookup(email: 'nicole.braun@zammad.org'),
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
|
@ -204,6 +212,12 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Zammad <zammad@localhost>', article1.from)
|
||||||
|
assert_match('nicole.braun@zammad.org', article1.to)
|
||||||
|
assert_match('asdasdas', article1.subject)
|
||||||
|
assert_match('dasdasdasd', article1.body)
|
||||||
|
assert_equal('text/html', article1.content_type)
|
||||||
|
|
||||||
ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
|
ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
|
||||||
ticket1.save
|
ticket1.save
|
||||||
|
@ -274,7 +288,7 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: "some title\n äöüß",
|
title: "some title\n äöüß",
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer_id: 2,
|
customer: User.lookup(email: 'nicole.braun@zammad.org'),
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
|
|
Loading…
Reference in a new issue