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

Conflicts:
	lib/notification_factory.rb
This commit is contained in:
Martin Edenhofer 2014-10-22 23:01:37 +02:00
commit 29115451cd
2 changed files with 47 additions and 26 deletions

View file

@ -1,47 +1,57 @@
module NotificationFactory module NotificationFactory
def self.build(data) def self.build(data)
data[:string].gsub!( /\#\{(.+?)\}/ ) { |s| data[:string].gsub!( / \#\{ \s* ( .+? ) \s* \} /x ) { |placeholder|
# store possible callback to work with
# and check if it's valid for execution
original_string = $&
callback = $1
callback_valid = nil
# use quoted text # use quoted text
callback = $1 callback.gsub!( /\A ( \w+ ) \.body \z/x ) { |item|
callback.gsub!( /\.body$/ ) { |item| callback_valid = true
item = item + '.word_wrap( :line_width => 82 ).message_quote.chomp' item = item + '.word_wrap( :line_width => 82 ).message_quote.chomp'
} }
# use config params # use config params
callback.gsub!( /^config\.(.+?)$/ ) { |item| callback.gsub!( /\A config\.( [\w\.]+ ) \z/x ) { |item|
name = $1 callback_valid = true
item = "Setting.get('#{$1}')" name = $1
item = "Setting.get('#{name}')"
} }
# use object params # use object params
callback.gsub!( /^(.+?)(\..+?)$/ ) { |item| callback.gsub!( /\A ( [\w]+ )( \.[\w\.]+ ) \z/x ) { |item|
object_name = $1 object_name = $1
object_method = $2 object_method = $2
replace = nil
if data[:objects][object_name.to_sym] next if !data[:objects][object_name.to_sym]
replace = "data[:objects]['#{object_name}'.to_sym]#{object_method}"
else callback_valid = true
replace = $1 + $2 item = "data[:objects]['#{object_name}'.to_sym]#{object_method}"
end
item = replace
} }
# replace value if callback_valid
begin # replace value
s = eval callback begin
rescue Exception => e placeholder = eval callback
Rails.logger.error "can't eval #{callback}" rescue Exception => e
Rails.logger.error e.inspect Rails.logger.error "Evaluation error caused by callback '#{callback}'"
Rails.logger.error e.inspect
end
else
placeholder = original_string
end end
} }
# translate # translate
data[:string].gsub!( /i18n\((.+?)\)/ ) { |s| data[:string].gsub!( /i18n\((.+?)\)/ ) { |placeholder|
string = $1 string = $1
locale = data[:locale] || 'en' locale = data[:locale] || 'en'
s = Translation.translate( locale, string ) placeholder = Translation.translate( locale, string )
} }
return data[:string] return data[:string]
@ -49,8 +59,14 @@ module NotificationFactory
def self.send(data) def self.send(data)
sender = Setting.get('notification_sender') sender = Setting.get('notification_sender')
<<<<<<< HEAD
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}" Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}"
Channel::EmailSend.new.send( Channel::EmailSend.new.send(
=======
imap = Channel::IMAP.new
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]}"
message = imap.send(
>>>>>>> 5e22499e44225c831661087b68de154deafef5c6
{ {
# :in_reply_to => self.in_reply_to, # :in_reply_to => self.in_reply_to,
:from => sender, :from => sender,

View file

@ -36,7 +36,7 @@ class NotificationFactoryTest < ActiveSupport::TestCase
}, },
{ {
:locale => 'de', :locale => 'de',
:string => 'i18n(#{"New"}) some text', :string => 'i18n(New) some text',
:result => 'Neu some text', :result => 'Neu some text',
}, },
{ {
@ -44,6 +44,11 @@ class NotificationFactoryTest < ActiveSupport::TestCase
:string => '\'i18n(#{ticket.state.name})\' ticket state', :string => '\'i18n(#{ticket.state.name})\' ticket state',
:result => '\'neu\' ticket state', :result => '\'neu\' ticket state',
}, },
{
:locale => 'de',
:string => '\#{puts `ls`}',
:result => '\#{puts `ls`}',
},
] ]
tests.each { |test| tests.each { |test|
result = NotificationFactory.build( result = NotificationFactory.build(