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: ''
internal: internal
in_reply_to: ''
subtype: ''
if @permissionCheck('ticket.customer')
currentStore.article.internal = ''

View file

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

View file

@ -1,5 +1,5 @@
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
@url: @apiPath + '/ticket_articles'
@configure_attributes = [

View file

@ -2,6 +2,7 @@
<input type="hidden" name="type" value="<%= @article.type %>">
<input type="hidden" name="internal" value="<%= @article.internal %>">
<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 %>">
<div class="editControls">
<div class="js-avatar"></div>

View file

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

View file

@ -9,11 +9,10 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
# build 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
subject_prefix_mode = record.preferences[:subtype]
subject = ticket.subject_build(record.subject, subject_prefix_mode)
# set retry count
if !record.preferences['delivery_retry']

View file

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

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
)
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(
title: 'Sender Format',
name: 'ticket_define_email_from',

View file

@ -300,9 +300,10 @@ class TicketTest < ActiveSupport::TestCase
)
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("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', true))
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', 'reply'))
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
Setting.set('ticket_hook_position', 'left')
@ -318,9 +319,10 @@ class TicketTest < ActiveSupport::TestCase
)
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("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', true))
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', 'reply'))
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
Setting.set('ticket_hook_position', 'none')
@ -336,9 +338,10 @@ class TicketTest < ActiveSupport::TestCase
)
assert_equal('subject test 1', ticket.title)
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', true))
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', 'reply'))
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
end