OSDN Git Service

Adds an option to enable/disable email notifications during a project copy (#4672).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 21 Mar 2010 11:17:29 +0000 (11:17 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 21 Mar 2010 11:17:29 +0000 (11:17 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3608 e93f8b46-1217-0410-a6f0-8f06a7374b81

42 files changed:
app/controllers/projects_controller.rb
app/models/mailer.rb
app/views/projects/copy.rhtml
config/locales/bg.yml
config/locales/bs.yml
config/locales/ca.yml
config/locales/cs.yml
config/locales/da.yml
config/locales/de.yml
config/locales/el.yml
config/locales/en.yml
config/locales/es.yml
config/locales/eu.yml
config/locales/fi.yml
config/locales/fr.yml
config/locales/gl.yml
config/locales/he.yml
config/locales/hr.yml
config/locales/hu.yml
config/locales/id.yml
config/locales/it.yml
config/locales/ja.yml
config/locales/ko.yml
config/locales/lt.yml
config/locales/nl.yml
config/locales/no.yml
config/locales/pl.yml
config/locales/pt-BR.yml
config/locales/pt.yml
config/locales/ro.yml
config/locales/ru.yml
config/locales/sk.yml
config/locales/sl.yml
config/locales/sr.yml
config/locales/sv.yml
config/locales/th.yml
config/locales/tr.yml
config/locales/uk.yml
config/locales/vi.yml
config/locales/zh-TW.yml
config/locales/zh.yml
test/unit/mailer_test.rb

index 8ef3d63..b6ffba5 100644 (file)
@@ -115,18 +115,20 @@ class ProjectsController < ApplicationController
         redirect_to :controller => 'admin', :action => 'projects'
       end  
     else
-      @project = Project.new(params[:project])
-      @project.enabled_module_names = params[:enabled_modules]
-      if validate_parent_id && @project.copy(@source_project, :only => params[:only])
-        @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
-        flash[:notice] = l(:notice_successful_create)
-        redirect_to :controller => 'admin', :action => 'projects'
-      elsif !@project.new_record?
-        # Project was created
-        # But some objects were not copied due to validation failures
-        # (eg. issues from disabled trackers)
-        # TODO: inform about that
-        redirect_to :controller => 'admin', :action => 'projects'
+      Mailer.with_deliveries(params[:notifications] == '1') do
+        @project = Project.new(params[:project])
+        @project.enabled_module_names = params[:enabled_modules]
+        if validate_parent_id && @project.copy(@source_project, :only => params[:only])
+          @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
+          flash[:notice] = l(:notice_successful_create)
+          redirect_to :controller => 'admin', :action => 'projects'
+        elsif !@project.new_record?
+          # Project was created
+          # But some objects were not copied due to validation failures
+          # (eg. issues from disabled trackers)
+          # TODO: inform about that
+          redirect_to :controller => 'admin', :action => 'projects'
+        end
       end
     end
   rescue ActiveRecord::RecordNotFound
index 173e33c..f39c532 100644 (file)
@@ -324,6 +324,15 @@ class Mailer < ActionMailer::Base
       deliver_reminder(assignee, issues, days) unless assignee.nil?
     end
   end
+  
+  # Activates/desactivates email deliveries during +block+
+  def self.with_deliveries(enabled = true, &block)
+    was_enabled = ActionMailer::Base.perform_deliveries
+    ActionMailer::Base.perform_deliveries = !!enabled
+    yield
+  ensure
+    ActionMailer::Base.perform_deliveries = was_enabled
+  end
 
   private
   def initialize_defaults(method_name)
index 49e2627..dfcd443 100644 (file)
@@ -21,6 +21,8 @@
   <label class="block"><%= check_box_tag 'only[]', 'boards', true %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label>
   <label class="block"><%= check_box_tag 'only[]', 'wiki', true %> <%= l(:label_wiki_page_plural) %> (<%= @source_project.wiki.nil? ? 0 : @source_project.wiki.pages.count %>)</label>
   <%= hidden_field_tag 'only[]', '' %>
+  <br />
+       <label class="block"><%= check_box_tag 'notifications', 1, params[:notifications] %> <%= l(:label_project_copy_notifications) %></label>
 </fieldset>
 
 <%= submit_tag l(:button_copy) %>
index b82bfc3..5b7f185 100644 (file)
@@ -886,3 +886,4 @@ bg:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 0dff54f..15e8a33 100644 (file)
@@ -910,3 +910,4 @@ bs:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 5c3e3f4..26b5069 100644 (file)
@@ -889,3 +889,4 @@ ca:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index c1b01ba..98c767c 100644 (file)
@@ -892,3 +892,4 @@ cs:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index c989f78..097defb 100644 (file)
@@ -912,3 +912,4 @@ da:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 7b57996..982452e 100644 (file)
@@ -909,3 +909,4 @@ de:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index c3fd80b..a2c8ecc 100644 (file)
@@ -892,3 +892,4 @@ el:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index f636c9d..4082670 100644 (file)
@@ -754,6 +754,7 @@ en:
   label_api_access_key_created_on: "API access key created {{value}} ago"
   label_profile: Profile
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
   
   button_login: Login
   button_submit: Submit
index 72ccb85..97569e3 100644 (file)
@@ -936,3 +936,4 @@ es:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 9660955..43f0a81 100644 (file)
@@ -896,3 +896,4 @@ eu:
   permission_manage_subtasks: Manage subtasks\r
   field_parent_issue: Parent task\r
   label_subtask_plural: Subtasks\r
+  label_project_copy_notifications: Send email notifications during the project copy\r
index d5dab77..714801e 100644 (file)
@@ -922,3 +922,4 @@ fi:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 35a05e6..121d1b2 100644 (file)
@@ -769,6 +769,7 @@ fr:
   label_revision_id: Revision {{value}}
   label_profile: Profil
   label_subtask_plural: Sous-tâches
+  label_project_copy_notifications: Envoyer les notifications durant la copie du projet
   
   button_login: Connexion
   button_submit: Soumettre
index 28a6ef9..3a2e7cf 100644 (file)
@@ -912,3 +912,4 @@ gl:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 42a1a72..2b40929 100644 (file)
@@ -896,3 +896,4 @@ he:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 3f6b992..adc838e 100644 (file)
@@ -899,3 +899,4 @@ hr:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 4376d96..9bc4375 100644 (file)
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 6fa2803..45aa1e3 100644 (file)
@@ -904,3 +904,4 @@ id:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 4b65da0..231ecdf 100644 (file)
@@ -899,3 +899,4 @@ it:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 1dd3d81..5cd0e10 100644 (file)
@@ -921,3 +921,4 @@ ja:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 00bb964..a3c3f6a 100644 (file)
@@ -952,3 +952,4 @@ ko:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 26b2662..dba0389 100644 (file)
@@ -960,3 +960,4 @@ lt:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 019e711..b92189d 100644 (file)
@@ -874,3 +874,4 @@ nl:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index f15a2e6..38b51ee 100644 (file)
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 18dda44..5a33535 100644 (file)
@@ -917,3 +917,4 @@ pl:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 8e831a2..7a48a6e 100644 (file)
@@ -920,3 +920,4 @@ pt-BR:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 1542146..e320b9f 100644 (file)
@@ -904,3 +904,4 @@ pt:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 862538c..778b5d0 100644 (file)
@@ -889,3 +889,4 @@ ro:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index d669181..1a35ca8 100644 (file)
@@ -1013,3 +1013,4 @@ ru:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 012960a..6a23d2d 100644 (file)
@@ -891,3 +891,4 @@ sk:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 7d59294..305105f 100644 (file)
@@ -888,3 +888,4 @@ sl:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index f02b00f..cebbbe4 100644 (file)
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 9f32395..fea2c23 100644 (file)
@@ -941,3 +941,4 @@ sv:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index ae487ae..e7bbf83 100644 (file)
@@ -889,3 +889,4 @@ th:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index b103dc3..59fae8f 100644 (file)
@@ -919,3 +919,4 @@ tr:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index e2efdef..eecd665 100644 (file)
@@ -888,3 +888,4 @@ uk:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 393559c..662a12d 100644 (file)
@@ -951,3 +951,4 @@ vi:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 80b3726..87acf24 100644 (file)
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index f7ae0b4..a878179 100644 (file)
@@ -914,3 +914,4 @@ zh:
   permission_manage_subtasks: Manage subtasks
   field_parent_issue: Parent task
   label_subtask_plural: Subtasks
+  label_project_copy_notifications: Send email notifications during the project copy
index 68b074a..0641bab 100644 (file)
@@ -338,6 +338,14 @@ class MailerTest < ActiveSupport::TestCase
     end
   end
   
+  def test_test
+    user = User.find(1)
+    valid_languages.each do |lang|
+      user.update_attribute :language, lang.to_s
+      assert Mailer.deliver_test(user)
+    end
+  end
+  
   def test_reminders
     Mailer.reminders(:days => 42)
     assert_equal 1, ActionMailer::Base.deliveries.size
@@ -365,4 +373,13 @@ class MailerTest < ActiveSupport::TestCase
     
     assert_equal :it, current_language
   end
+  
+  def test_with_deliveries_off
+    Mailer.with_deliveries false do
+      Mailer.deliver_test(User.find(1))
+    end
+    assert ActionMailer::Base.deliveries.empty?
+    # should restore perform_deliveries
+    assert ActionMailer::Base.perform_deliveries
+  end
 end