Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Felix Niklas 2015-10-08 14:18:11 +02:00
commit 8af48d557e
8 changed files with 202 additions and 38 deletions

View file

@ -190,7 +190,7 @@ class App.TicketZoomArticleActions extends App.Controller
articleNew.cc = addAddresses(articleNew.cc, article.cc)
# get current body
body = @el.closest('[data-name="body"]').html() || ''
body = @el.closest('.ticketZoom').find('.article-add [data-name="body"]').html() || ''
# check if quote need to be added
selectedText = App.ClipBoard.getSelected()

View file

@ -95,28 +95,28 @@ class App.TicketZoomArticleNew extends App.Controller
@bind(
'ui::ticket::setArticleType'
(data) =>
if data.ticket.id is @ticket.id
#@setArticleType(data.type.name)
return if data.ticket.id isnt @ticket.id
#@setArticleType(data.type.name)
@openTextarea(null, true)
for key, value of data.article
if key is 'body'
@$('[data-name="' + key + '"]').html(value)
else
@$('[name="' + key + '"]').val(value)
@openTextarea(null, true)
for key, value of data.article
if key is 'body'
@$('[data-name="' + key + '"]').html(value)
else
@$('[name="' + key + '"]').val(value)
# preselect article type
@setArticleType( 'email' )
# preselect article type
@setArticleType('email')
)
# reset new article screen
@bind(
'ui::ticket::taskReset'
(data) =>
if data.ticket_id is @ticket.id
@type = 'note'
@defaults = {}
@render()
return if data.ticket_id isnt @ticket.id
@type = 'note'
@defaults = {}
@render()
)
isIE10: ->

View file

@ -1,6 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Observer::Ticket::Article::EmailSignatureDetection < ActiveRecord::Observer
require 'signature_detection'
class Observer::Ticket::Article::SignatureDetection < ActiveRecord::Observer
observe 'ticket::_article'
def before_create(record)
@ -17,6 +19,9 @@ class Observer::Ticket::Article::EmailSignatureDetection < ActiveRecord::Observe
type = Ticket::Article::Type.lookup( id: record.type_id )
return if type['name'] != 'email'
# add queue job to update current signature of user id
Delayed::Job.enqueue( Observer::Ticket::Article::SignatureDetection::BackgroundJob.new( record.created_by_id ) )
# user
user = User.lookup(id: record.created_by_id)
return if !user
@ -24,6 +29,5 @@ class Observer::Ticket::Article::EmailSignatureDetection < ActiveRecord::Observe
return if !user.preferences[:signature_detection]
record.preferences[:signature_detection] = SignatureDetection.find_signature_line(user.preferences[:signature_detection], record.body)
end
end

View file

@ -0,0 +1,9 @@
class Observer::Ticket::Article::SignatureDetection::BackgroundJob
def initialize(id)
@user_id = id
end
def perform
SignatureDetection.rebuild_user(@user_id)
end
end

View file

@ -30,7 +30,7 @@ module Zammad
'observer::_ticket::_article::_communicate_email',
'observer::_ticket::_article::_communicate_facebook',
'observer::_ticket::_article::_communicate_twitter',
'observer::_ticket::_article::_email_signature_detection',
'observer::_ticket::_article::_signature_detection',
'observer::_ticket::_notification',
'observer::_ticket::_reset_new_state',
'observer::_ticket::_escalation_calculation',

View file

@ -139,6 +139,7 @@ returns
article = ticket.articles.first
article_bodies.push article.body
}
find_signature( article_bodies )
end
@ -146,7 +147,7 @@ returns
rebuild signature for each user
SignatureDetection.rebuild_all
SignatureDetection.rebuild_all_user
returns
@ -154,15 +155,64 @@ returns
=end
def self.rebuild_all
def self.rebuild_all_user
User.select('id').where(active: true).each {|local_user|
signature_detection = by_user_id(local_user.id)
next if !signature_detection
user = User.find(local_user.id)
next if user.preferences[:signature_detection] == signature_detection
user.preferences[:signature_detection] = signature_detection
user.save
rebuild_user(local_user.id)
}
true
end
=begin
rebuild signature for user
SignatureDetection.rebuild_user
returns
true/false
=end
def self.rebuild_user(user_id)
signature_detection = by_user_id(user_id)
return if !signature_detection
user = User.find(user_id)
return if user.preferences[:signature_detection] == signature_detection
user.preferences[:signature_detection] = signature_detection
user.save
true
end
=begin
rebuild signature for all articles
SignatureDetection.rebuild_all_articles
returns
true/false
=end
def self.rebuild_all_articles
Ticket::Article.all.each {|article|
user = User.find(article.created_by_id)
next if !user.preferences[:signature_detection]
signature_line = find_signature_line(user.preferences[:signature_detection], article.body)
next if !signature_line
next if article.preferences[:signature_detection] == signature_line
article.preferences[:signature_detection] = signature_line
article.save
}
true
end

View file

@ -0,0 +1,63 @@
# encoding: utf-8
require 'browser_test_helper'
class AgentTicketActionLevel7Test < TestCase
def test_reply_message_keep_body
# merge ticket with closed tab
@browser = browser_instance
login(
username: 'agent1@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all()
# create new ticket
ticket1 = ticket_create(
data: {
customer: 'nico',
group: 'Users',
title: 'some subject 123äöü - reply test',
body: 'some body 123äöü - reply test',
},
)
sleep 1
# fill body
ticket_update(
data: {
body: 'keep me',
},
do_not_submit: true,
)
# click reply
click( css: '.content.active [data-type="reply"]' )
# check body
watch_for(
css: '.content.active .js-reset',
value: '(Discard your unsaved changes.|Verwerfen der)',
no_quote: true,
)
# check body
ticket_verify(
data: {
body: 'keep me',
},
)
# click reply
click( css: '.content.active [data-type="reply"]' )
# check body
watch_for(
css: '.content.active .js-reset',
value: '(Discard your unsaved changes.|Verwerfen der)',
no_quote: true,
)
end
end

View file

@ -16,14 +16,9 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase
fixture_files.keys.each do |filepath|
file_content = ''
file = File.new("#{Rails.root}/test/fixtures/#{filepath}", 'r')
while (line = file.gets)
file_content += line
end
file.close
file_content = file.read
fixture_files[filepath][:content] = file_content
fixture_files_string_list.push(file_content)
end
@ -51,14 +46,9 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase
fixture_files.keys.each do |filepath|
file_content = ''
file = File.new("#{Rails.root}/test/fixtures/#{filepath}", 'r')
while (line = file.gets)
file_content += line
end
file.close
file_content = file.read
fixture_files[filepath][:content] = file_content
fixture_files_string_list.push(file_content)
end
@ -74,4 +64,52 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase
end
end
test 'test case III - sender a - full cycle' do
raw_email_header = "From: Bob.Smith@music.com\nTo: test@zammad.org\nSubject: test\n\n"
# process email I
file = File.open("#{Rails.root}/test/fixtures/email_signature_detection/client_a_1.txt", 'rb')
raw_email = raw_email_header + file.read
ticket1, article1, user1, mail = Channel::EmailParser.new.process({}, raw_email)
assert(ticket1)
assert(article1)
# process email II
file = File.open("#{Rails.root}/test/fixtures/email_signature_detection/client_a_2.txt", 'rb')
raw_email = raw_email_header + file.read
ticket2, article2, user2, mail = Channel::EmailParser.new.process({}, raw_email)
assert(ticket2)
assert(article2)
# process background jobs (user signature detection & article signature detection)
Delayed::Worker.new.work_off
# check if user2 has a signature_detection value
user2 = User.find(user2.id)
assert(user2.preferences[:signature_detection])
# process email III
file = File.open("#{Rails.root}/test/fixtures/email_signature_detection/client_a_3.txt", 'rb')
raw_email = raw_email_header + file.read
ticket3, article3, user3, mail = Channel::EmailParser.new.process({}, raw_email)
assert(ticket3)
assert(article3)
# check if article3 has a signature_detection value
assert_equal(article3.preferences[:signature_detection], 6)
# relbuild all
SignatureDetection.rebuild_all_articles
article1 = Ticket::Article.find(article1.id)
assert_equal(article1.preferences[:signature_detection], 10)
article2 = Ticket::Article.find(article2.id)
assert_equal(article2.preferences[:signature_detection], 20)
article3 = Ticket::Article.find(article3.id)
assert_equal(article3.preferences[:signature_detection], 6)
end
end