From b864dd2c45ce0b1c5b3ca191529014c5da033590 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 7 Jan 2015 13:11:30 +0100 Subject: [PATCH] Fixed non html notifications. --- .../ticket/notification/background_job.rb | 7 ++-- app/models/user.rb | 13 ++++---- lib/notification_factory.rb | 14 +++++--- test/unit/notification_factory_test.rb | 33 +++++++++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index 7fe9edfe4..30d94d5cd 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index c1aafd077..d8f566fc0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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| diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index 5913d634d..c91cf15de 100644 --- a/lib/notification_factory.rb +++ b/lib/notification_factory.rb @@ -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 ) diff --git a/test/unit/notification_factory_test.rb b/test/unit/notification_factory_test.rb index ad82e4ade..d335ed138 100644 --- a/test/unit/notification_factory_test.rb +++ b/test/unit/notification_factory_test.rb @@ -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 body', + :content_type => 'text/html', + ) + assert_match('some body', result.to_s) + assert_match('text/plain', result.to_s) + assert_match('body', result.to_s) + assert_match('text/html', result.to_s) + end + test 'notifications base' do ticket = Ticket.create( :title => 'some title äöüß',