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

@ -112,9 +112,10 @@ class Observer::Ticket::Notification::BackgroundJob
puts "send ticket notifiaction to agent (#{@type}/#{ticket.id}/#{user.email})"
NotificationFactory.send(
:recipient => user,
:subject => notification[:subject],
:body => notification[:body]
:recipient => user,
:subject => notification[:subject],
:body => notification[:body],
:content_type => 'text/html',
)
end

View file

@ -294,18 +294,17 @@ returns
data[:subject] = 'Reset your #{config.product_name} 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
[:subject, :body].each { |key|

View file

@ -92,9 +92,10 @@ module NotificationFactory
=begin
success = NotificationFactory.send(
:to => 'somebody@example.com',
:subject => 'sime subject',
:body => 'some body'
:recipient => User.find(123),
:subject => 'sime subject',
: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 äöüß',