]> source.dussan.org Git - redmine.git/commitdiff
Merged r11526 and r11590 from trunk (#13341).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 11 Mar 2013 18:00:39 +0000 (18:00 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 11 Mar 2013 18:00:39 +0000 (18:00 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@11591 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
extra/mail_handler/rdm-mailhandler.rb
test/unit/mail_handler_test.rb

index b986384a6789bbd288962d50b7533c5c3b7242e7..6581c8f28fb6b58747f0bf64f400d088558b6e60 100644 (file)
@@ -39,6 +39,7 @@ class MailHandler < ActionMailer::Base
     @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
 
     @@handler_options[:no_account_notice] = (@@handler_options[:no_account_notice].to_s == '1')
+    @@handler_options[:no_notification] = (@@handler_options[:no_notification].to_s == '1')
     @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1')
 
     email.force_encoding('ASCII-8BIT') if email.respond_to?(:force_encoding)
@@ -437,6 +438,7 @@ class MailHandler < ActionMailer::Base
     password_length = [Setting.password_min_length.to_i, 10].max
     user.password = Redmine::Utils.random_hex(password_length / 2 + 1)
     user.language = Setting.default_language
+    user.mail_notification = 'only_my_events'
 
     unless user.valid?
       user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
@@ -457,6 +459,9 @@ class MailHandler < ActionMailer::Base
     end
     if addr.present?
       user = self.class.new_user_from_attributes(addr, name)
+      if @@handler_options[:no_notification]
+        user.mail_notification = 'none'
+      end
       if user.save
         user
       else
index 26f61ba87dd2cf4ad02816c53ab2acb1784848ba..f46c882b1dc44f2ecdf603e529248c4cc0e53d99 100644 (file)
@@ -26,7 +26,7 @@ class RedmineMailHandler
   VERSION = '0.2.3'
 
   attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check,
-    :url, :key, :no_check_certificate, :no_account_notice
+    :url, :key, :no_check_certificate, :no_account_notice, :no_notification
 
   def initialize
     self.issue_attributes = {}
@@ -62,6 +62,8 @@ class RedmineMailHandler
                                               "GROUP can be a comma separated list of groups") { |v| self.default_group = v}
       opts.on("--no-account-notice",          "don't send account information to the newly",
                                               "created user") { |v| self.no_account_notice = '1'}
+      opts.on("--no-notification",            "disable email notifications for the created",
+                                              "user") { |v| self.no_notification = '1'}
       opts.separator("")
       opts.separator("Issue attributes control options:")
       opts.on("-p", "--project PROJECT",      "identifier of the target project") {|v| self.issue_attributes['project'] = v}
@@ -104,6 +106,7 @@ class RedmineMailHandler
                            'unknown_user' => unknown_user,
                            'default_group' => default_group,
                            'no_account_notice' => no_account_notice,
+                           'no_notification' => no_notification,
                            'no_permission_check' => no_permission_check}
     issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
 
index 08271560808e3177620ebda664cc26d48a9def2a..6b95288935562a770932840ec74b058112fe5adc 100644 (file)
@@ -336,6 +336,19 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_include 'Ticket by unknown user', email.subject
   end
 
+  def test_created_user_should_have_mail_notification_to_none_with_no_notification_option
+    assert_difference 'User.count' do
+      submit_email(
+        'ticket_by_unknown_user.eml',
+        :issue => {:project => 'ecookbook'},
+        :unknown_user => 'create',
+        :no_notification => '1'
+      )
+    end
+    user = User.order('id DESC').first
+    assert_equal 'none', user.mail_notification
+  end
+
   def test_add_issue_without_from_header
     Role.anonymous.add_permission!(:add_issues)
     assert_equal false, submit_email('ticket_without_from_header.eml')
@@ -755,6 +768,7 @@ class MailHandlerTest < ActiveSupport::TestCase
       assert_equal expected[0], user.login
       assert_equal expected[1], user.firstname
       assert_equal expected[2], user.lastname
+      assert_equal 'only_my_events', user.mail_notification
     end
   end