From 95b10f3bd3883d098102176f7596ff11798a5dbb Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 12 Mar 2012 18:34:12 +0000 Subject: [PATCH] Don't use #delete on String in Mailer. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9237 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mailer.rb | 22 ++++++++++++++++------ test/functional/admin_controller_test.rb | 5 +++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index e54170604..22b99edf6 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -98,6 +98,7 @@ class Mailer < ActionMailer::Base def document_added(document) redmine_headers 'Project' => document.project.identifier recipients document.recipients + @author = User.current subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" body :document => document, :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) @@ -113,6 +114,7 @@ class Mailer < ActionMailer::Base container = attachments.first.container added_to = '' added_to_url = '' + @author = attachments.first.author case container.class.name when 'Project' added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container) @@ -142,6 +144,7 @@ class Mailer < ActionMailer::Base # Mailer.deliver_news_added(news) => sends an email to the news' project recipients def news_added(news) redmine_headers 'Project' => news.project.identifier + @author = news.author message_id news recipients news.recipients subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" @@ -158,6 +161,7 @@ class Mailer < ActionMailer::Base def news_comment_added(comment) news = comment.commented redmine_headers 'Project' => news.project.identifier + @author = comment.author message_id comment recipients news.recipients cc news.watcher_recipients @@ -176,6 +180,7 @@ class Mailer < ActionMailer::Base def message_posted(message) redmine_headers 'Project' => message.project.identifier, 'Topic-Id' => (message.parent_id || message.id) + @author = message.author message_id message references message.parent unless message.parent.nil? recipients(message.recipients) @@ -194,6 +199,7 @@ class Mailer < ActionMailer::Base def wiki_content_added(wiki_content) redmine_headers 'Project' => wiki_content.project.identifier, 'Wiki-Page-Id' => wiki_content.page.id + @author = wiki_content.author message_id wiki_content recipients wiki_content.recipients cc(wiki_content.page.wiki.watcher_recipients - recipients) @@ -213,6 +219,7 @@ class Mailer < ActionMailer::Base def wiki_content_updated(wiki_content) redmine_headers 'Project' => wiki_content.project.identifier, 'Wiki-Page-Id' => wiki_content.page.id + @author = wiki_content.author message_id wiki_content recipients wiki_content.recipients cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients) @@ -387,15 +394,18 @@ class Mailer < ActionMailer::Base # Overrides the create_mail method def create_mail - # Removes the current user from the recipients and cc + # Removes the author from the recipients and cc # if he doesn't want to receive notifications about what he does - @author ||= User.current - if @author.pref[:no_self_notified] - recipients.delete(@author.mail) if recipients - cc.delete(@author.mail) if cc + if @author && @author.logged? && @author.pref[:no_self_notified] + if recipients + recipients((recipients.is_a?(Array) ? recipients : [recipients]) - [@author.mail]) + end + if cc + cc((cc.is_a?(Array) ? cc : [cc]) - [@author.mail]) + end end - if @author.logged? + if @author && @author.logged? redmine_headers 'Sender' => @author.login end diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 2ba84179e..858a0e7bf 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -84,6 +84,11 @@ class AdminControllerTest < ActionController::TestCase end def test_test_email + user = User.find(1) + user.pref[:no_self_notified] = '1' + user.pref.save! + ActionMailer::Base.deliveries.clear + get :test_email assert_redirected_to '/settings/edit?tab=notifications' mail = ActionMailer::Base.deliveries.last