Fixes #1730 When forwarding a message, prefix FWD is added

This commit is contained in:
Mantas 2018-05-18 13:59:08 +03:00 committed by Mantas Masalskis
parent 9cdb0d5ce4
commit ada6efa3bc
10 changed files with 115 additions and 42 deletions

View file

@ -605,6 +605,7 @@ class App.TicketZoom extends App.Controller
body: '' body: ''
internal: internal internal: internal
in_reply_to: '' in_reply_to: ''
subtype: ''
if @permissionCheck('ticket.customer') if @permissionCheck('ticket.customer')
currentStore.article.internal = '' currentStore.article.internal = ''

View file

@ -157,6 +157,8 @@ class EmailReply extends App.Controller
type = App.TicketArticleType.findByAttribute(name:'email') type = App.TicketArticleType.findByAttribute(name:'email')
articleNew.subtype = 'reply'
App.Event.trigger('ui::ticket::setArticleType', { App.Event.trigger('ui::ticket::setArticleType', {
ticket: ticket ticket: ticket
type: type type: type
@ -187,12 +189,14 @@ class EmailReply extends App.Controller
if ui.Config.get('ui_ticket_zoom_article_email_subject') if ui.Config.get('ui_ticket_zoom_article_email_subject')
if _.isEmpty(article.subject) if _.isEmpty(article.subject)
articleNew.subject = "FW: #{ticket.title}" articleNew.subject = ticket.title
else else
articleNew.subject = "FW: #{article.subject}" articleNew.subject = article.subject
type = App.TicketArticleType.findByAttribute(name:'email') type = App.TicketArticleType.findByAttribute(name:'email')
articleNew.subtype = 'forward'
App.Event.trigger('ui::ticket::setArticleType', { App.Event.trigger('ui::ticket::setArticleType', {
ticket: ticket ticket: ticket
type: type type: type

View file

@ -1,5 +1,5 @@
class App.TicketArticle extends App.Model class App.TicketArticle extends App.Model
@configure 'TicketArticle', 'from', 'to', 'cc', 'subject', 'body', 'content_type', 'ticket_id', 'type_id', 'sender_id', 'internal', 'in_reply_to', 'form_id', 'time_unit', 'preferences', 'updated_at' @configure 'TicketArticle', 'from', 'to', 'cc', 'subject', 'body', 'content_type', 'ticket_id', 'type_id', 'sender_id', 'internal', 'in_reply_to', 'form_id', 'subtype', 'time_unit', 'preferences', 'updated_at'
@extend Spine.Model.Ajax @extend Spine.Model.Ajax
@url: @apiPath + '/ticket_articles' @url: @apiPath + '/ticket_articles'
@configure_attributes = [ @configure_attributes = [

View file

@ -2,6 +2,7 @@
<input type="hidden" name="type" value="<%= @article.type %>"> <input type="hidden" name="type" value="<%= @article.type %>">
<input type="hidden" name="internal" value="<%= @article.internal %>"> <input type="hidden" name="internal" value="<%= @article.internal %>">
<input type="hidden" name="form_id" value="<%= @form_id %>"> <input type="hidden" name="form_id" value="<%= @form_id %>">
<input type="hidden" name="subtype" value="<%= @article.subtype %>">
<input type="hidden" name="in_reply_to" value="<%= @article.in_reply_to %>"> <input type="hidden" name="in_reply_to" value="<%= @article.in_reply_to %>">
<div class="editControls"> <div class="editControls">
<div class="js-avatar"></div> <div class="js-avatar"></div>

View file

@ -8,6 +8,7 @@ module CreatesTicketArticles
# create article if given # create article if given
form_id = params[:form_id] form_id = params[:form_id]
params.delete(:form_id) params.delete(:form_id)
subtype = params.delete(:subtype)
# check min. params # check min. params
raise Exceptions::UnprocessableEntity, 'Need at least article: { body: "some text" }' if !params[:body] raise Exceptions::UnprocessableEntity, 'Need at least article: { body: "some text" }' if !params[:body]
@ -59,6 +60,10 @@ module CreatesTicketArticles
o_id: form_id, o_id: form_id,
) )
end end
# set subtype of present
article.preferences[:subtype] = subtype if subtype.present?
article.save! article.save!
# store inline attachments # store inline attachments

View file

@ -9,11 +9,10 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
# build subject # build subject
ticket = Ticket.lookup(id: record.ticket_id) ticket = Ticket.lookup(id: record.ticket_id)
article_count = Ticket::Article.where(ticket_id: ticket.id).count article_count = Ticket::Article.where(ticket_id: ticket.id).count
subject = if article_count > 1
ticket.subject_build(record.subject, true) subject_prefix_mode = record.preferences[:subtype]
else
ticket.subject_build(record.subject) subject = ticket.subject_build(record.subject, subject_prefix_mode)
end
# set retry count # set retry count
if !record.preferences['delivery_retry'] if !record.preferences['delivery_retry']

View file

@ -6,7 +6,8 @@ module Ticket::Subject
build new subject with ticket number in there build new subject with ticket number in there
ticket = Ticket.find(123) ticket = Ticket.find(123)
result = ticket.subject_build('some subject', is_reply_true_false) prefix_mode = :reply # :forward, nil
result = ticket.subject_build('some subject', prefix_mode)
returns returns
@ -14,36 +15,25 @@ returns
=end =end
def subject_build(subject, is_reply = false) def subject_build(subject, prefix_mode = nil)
# clena subject # clena subject
subject = subject_clean(subject) subject_parts = [subject_clean(subject)]
ticket_hook = Setting.get('ticket_hook') # add hook
ticket_hook_divider = Setting.get('ticket_hook_divider') case Setting.get('ticket_hook_position')
ticket_subject_re = Setting.get('ticket_subject_re') when 'left'
subject_parts.unshift subject_build_hook
# none position when 'right'
if Setting.get('ticket_hook_position') == 'none' subject_parts.push subject_build_hook
if is_reply && ticket_subject_re.present?
subject = "#{ticket_subject_re}: #{subject}"
end
return subject
end end
# right position # add prefix
if Setting.get('ticket_hook_position') == 'right' subject_parts
if is_reply && ticket_subject_re.present? .unshift(subject_build_prefix(prefix_mode))
subject = "#{ticket_subject_re}: #{subject}" .compact!
end
return "#{subject} [#{ticket_hook}#{ticket_hook_divider}#{number}]"
end
# left position subject_parts.join ' '
if is_reply && ticket_subject_re.present?
return "#{ticket_subject_re}: [#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}"
end
"[#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}"
end end
=begin =begin
@ -85,4 +75,24 @@ returns
subject.strip! subject.strip!
subject subject
end end
private
def subject_build_hook
ticket_hook = Setting.get('ticket_hook')
ticket_hook_divider = Setting.get('ticket_hook_divider')
"[#{ticket_hook}#{ticket_hook_divider}#{number}]"
end
def subject_build_prefix(prefix_mode)
prefix = case prefix_mode
when 'reply'
Setting.get('ticket_subject_re')
when 'forward'
Setting.get('ticket_subject_fwd')
end
prefix.present? ? "#{prefix}:" : nil
end
end end

View file

@ -0,0 +1,28 @@
class EmailForwardPrefixSettingIssue1730 < ActiveRecord::Migration[5.1]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'Ticket Subject Forward',
name: 'ticket_subject_fwd',
area: 'Email::Base',
description: 'The text at the beginning of the subject in an email forward, e. g. FWD.',
options: {
form: [
{
display: '',
null: true,
name: 'ticket_subject_fwd',
tag: 'input',
},
],
},
state: 'FWD',
preferences: {
permission: ['admin.channel_email'],
},
frontend: false
)
end
end

View file

@ -2308,6 +2308,28 @@ Setting.create_if_not_exists(
frontend: false frontend: false
) )
Setting.create_if_not_exists(
title: 'Ticket Subject Forward',
name: 'ticket_subject_fwd',
area: 'Email::Base',
description: 'The text at the beginning of the subject in an email forward, e. g. FWD.',
options: {
form: [
{
display: '',
null: true,
name: 'ticket_subject_fwd',
tag: 'input',
},
],
},
state: 'FWD',
preferences: {
permission: ['admin.channel_email'],
},
frontend: false
)
Setting.create_if_not_exists( Setting.create_if_not_exists(
title: 'Sender Format', title: 'Sender Format',
name: 'ticket_define_email_from', name: 'ticket_define_email_from',

View file

@ -300,9 +300,10 @@ class TicketTest < ActiveSupport::TestCase
) )
assert_equal('subject test 1', ticket.title) assert_equal('subject test 1', ticket.title)
assert_equal("ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1')) assert_equal("ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1'))
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1', true)) assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1', 'reply'))
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build(' ABC subject test 1', true)) assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build(' ABC subject test 1', 'reply'))
assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', true)) assert_equal("RE: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', 'reply'))
assert_equal("FWD: ABC subject test 1 [Ticket##{ticket.number}]", ticket.subject_build('ABC subject test 1 ', 'forward'))
ticket.destroy ticket.destroy
Setting.set('ticket_hook_position', 'left') Setting.set('ticket_hook_position', 'left')
@ -318,9 +319,10 @@ class TicketTest < ActiveSupport::TestCase
) )
assert_equal('subject test 1', ticket.title) assert_equal('subject test 1', ticket.title)
assert_equal("[Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1')) assert_equal("[Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1'))
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1', true)) assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1', 'reply'))
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build(' ABC subject test 1', true)) assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build(' ABC subject test 1', 'reply'))
assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', true)) assert_equal("RE: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', 'reply'))
assert_equal("FWD: [Ticket##{ticket.number}] ABC subject test 1", ticket.subject_build('ABC subject test 1 ', 'forward'))
ticket.destroy ticket.destroy
Setting.set('ticket_hook_position', 'none') Setting.set('ticket_hook_position', 'none')
@ -336,9 +338,10 @@ class TicketTest < ActiveSupport::TestCase
) )
assert_equal('subject test 1', ticket.title) assert_equal('subject test 1', ticket.title)
assert_equal('ABC subject test 1', ticket.subject_build('ABC subject test 1')) assert_equal('ABC subject test 1', ticket.subject_build('ABC subject test 1'))
assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1', true)) assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1', 'reply'))
assert_equal('RE: ABC subject test 1', ticket.subject_build(' ABC subject test 1', true)) assert_equal('RE: ABC subject test 1', ticket.subject_build(' ABC subject test 1', 'reply'))
assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', true)) assert_equal('RE: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', 'reply'))
assert_equal('FWD: ABC subject test 1', ticket.subject_build('ABC subject test 1 ', 'forward'))
ticket.destroy ticket.destroy
end end