diff --git a/app/models/observer/ticket/article/communicate_email/background_job.rb b/app/models/observer/ticket/article/communicate_email/background_job.rb index a579cde48..6634be4fb 100644 --- a/app/models/observer/ticket/article/communicate_email/background_job.rb +++ b/app/models/observer/ticket/article/communicate_email/background_job.rb @@ -7,8 +7,13 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob record = Ticket::Article.find(@article_id) # build subject - ticket = Ticket.lookup(id: record.ticket_id) - subject = ticket.subject_build(record.subject) + ticket = Ticket.lookup(id: record.ticket_id) + article_count = Ticket::Article.where(ticket_id: ticket.id).count + subject = if article_count > 1 + ticket.subject_build(record.subject, true) + else + ticket.subject_build(record.subject) + end # send email if !ticket.group.email_address_id diff --git a/app/models/ticket/subject.rb b/app/models/ticket/subject.rb index fb0044219..805d30bf3 100644 --- a/app/models/ticket/subject.rb +++ b/app/models/ticket/subject.rb @@ -6,7 +6,7 @@ module Ticket::Subject build new subject with ticket number in there ticket = Ticket.find(123) - result = ticket.subject_build('some subject') + result = ticket.subject_build('some subject', is_reply_true_false) returns @@ -14,13 +14,17 @@ returns =end - def subject_build (subject) + def subject_build(subject, is_reply = false) # clena subject subject = subject_clean(subject) ticket_hook = Setting.get('ticket_hook') ticket_hook_divider = Setting.get('ticket_hook_divider') + ticket_subject_re = Setting.get('ticket_subject_re') + if is_reply && !ticket_subject_re.empty? + subject = "#{ticket_subject_re}: #{subject}" + end # none position if Setting.get('ticket_hook_position') == 'none' @@ -49,7 +53,7 @@ returns =end - def subject_clean (subject) + def subject_clean(subject) ticket_hook = Setting.get('ticket_hook') ticket_hook_divider = Setting.get('ticket_hook_divider') ticket_subject_size = Setting.get('ticket_subject_size') diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb index 1c924c470..e87d66aa1 100644 --- a/test/unit/ticket_test.rb +++ b/test/unit/ticket_test.rb @@ -263,4 +263,23 @@ class TicketTest < ActiveSupport::TestCase lookup_ticket = Ticket.find_by('pending_time <= ?', Time.zone.now) assert_nil(lookup_ticket, 'ticket.pending_time processed verify') end + + test 'ticket subject' do + + ticket1 = Ticket.create( + title: 'subject test 1', + group: Group.lookup(name: 'Users'), + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: 1, + created_by_id: 1, + ) + assert_equal('subject test 1', ticket1.title) + assert_equal("ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1')) + assert_equal("RE: ABC subject test 1 [Ticket##{ticket1.number}]", ticket1.subject_build('ABC subject test 1', true)) + ticket1.destroy + + end + end