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( NotificationFactory.send(
:recipient => user, :recipient => user,
:subject => notification[:subject], :subject => notification[:subject],
:body => notification[:body] :body => notification[:body],
:content_type => 'text/html',
) )
end end

View file

@ -294,18 +294,17 @@ returns
data[:subject] = 'Reset your #{config.product_name} password' data[:subject] = 'Reset your #{config.product_name} password'
data[:body] = 'Forgot your password? data[:body] = 'Forgot your password?
We received a request to reset the password for your #{config.product_name} account (#{user.login}). We received a request to reset the password for your #{config.product_name} account (#{user.login}).
If you want to reset your password, click on the link below (or copy and paste the URL into your browser): If you want to reset your password, click on the link below (or copy and paste the URL into your browser):
#{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name} #{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name}
This link takes you to a page where you can change your password. This link takes you to a page where you can change your password.
If you don\'t want to reset your password, please ignore this message. Your password will not be reset. 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 # prepare subject & body
[:subject, :body].each { |key| [:subject, :body].each { |key|

View file

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

View file

@ -2,6 +2,39 @@
require 'test_helper' require 'test_helper'
class NotificationFactoryTest < ActiveSupport::TestCase 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 test 'notifications base' do
ticket = Ticket.create( ticket = Ticket.create(
:title => 'some title äöüß', :title => 'some title äöüß',