Fixed non html notifications.

This commit is contained in:
Martin Edenhofer 2015-01-07 13:11:30 +01:00
parent 4d9ff76cff
commit b864dd2c45
4 changed files with 53 additions and 14 deletions

View file

@ -114,7 +114,8 @@ class Observer::Ticket::Notification::BackgroundJob
NotificationFactory.send(
:recipient => user,
:subject => notification[:subject],
:body => notification[:body]
:body => notification[:body],
:content_type => 'text/html',
)
end

View file

@ -304,8 +304,7 @@ returns
If you don\'t want to reset your password, please ignore this message. Your password will not be reset.
Your #{config.product_name} Team
'
Your #{config.product_name} Team'
# prepare subject & body
[:subject, :body].each { |key|

View file

@ -92,9 +92,10 @@ module NotificationFactory
=begin
success = NotificationFactory.send(
:to => 'somebody@example.com',
:recipient => User.find(123),
:subject => 'sime subject',
:body => 'some body'
:body => 'some body',
:content_type => '', # optional, e. g. 'text/html'
)
=end
@ -103,6 +104,11 @@ module NotificationFactory
sender = Setting.get('notification_sender')
Rails.logger.info "NOTICE: SEND NOTIFICATION TO: #{data[:recipient][:email]} (from #{sender})"
content_type = 'text/plain'
if data[:content_type]
content_type = data[:content_type]
end
Channel::EmailSend.send(
{
# :in_reply_to => self.in_reply_to,
@ -110,7 +116,7 @@ module NotificationFactory
:to => data[:recipient][:email],
:subject => data[:subject],
:body => data[:body],
:content_type => 'text/html',
:content_type => content_type,
},
true
)

View file

@ -2,6 +2,39 @@
require 'test_helper'
class NotificationFactoryTest < ActiveSupport::TestCase
test 'notifications send' do
result = NotificationFactory.send(
:recipient => User.find(2),
:subject => 'sime subject',
:body => 'some body',
:content_type => '',
)
assert_match('some body', result.to_s)
assert_match('text/plain', result.to_s)
assert_no_match('text/html', result.to_s)
result = NotificationFactory.send(
:recipient => User.find(2),
:subject => 'sime subject',
:body => 'some body',
:content_type => 'text/plain',
)
assert_match('some body', result.to_s)
assert_match('text/plain', result.to_s)
assert_no_match('text/html', result.to_s)
result = NotificationFactory.send(
:recipient => User.find(2),
:subject => 'sime subject',
:body => 'some <span>body</span>',
:content_type => 'text/html',
)
assert_match('some body', result.to_s)
assert_match('text/plain', result.to_s)
assert_match('<span>body</span>', result.to_s)
assert_match('text/html', result.to_s)
end
test 'notifications base' do
ticket = Ticket.create(
:title => 'some title äöüß',