From: Jean-Philippe Lang Date: Sun, 21 Mar 2010 11:17:29 +0000 (+0000) Subject: Adds an option to enable/disable email notifications during a project copy (#4672). X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=79b4f681760e9d674e5b959abcb3087fee009008;p=redminele%2Fredmine.git Adds an option to enable/disable email notifications during a project copy (#4672). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3608 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8ef3d63d..b6ffba56 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 173e33c4..f39c5320 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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) diff --git a/app/views/projects/copy.rhtml b/app/views/projects/copy.rhtml index 49e26278..dfcd4433 100644 --- a/app/views/projects/copy.rhtml +++ b/app/views/projects/copy.rhtml @@ -21,6 +21,8 @@ <%= hidden_field_tag 'only[]', '' %> +
+ <%= submit_tag l(:button_copy) %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index b82bfc39..5b7f1850 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -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 diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 0dff54fb..15e8a339 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -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 diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 5c3e3f42..26b50691 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -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 diff --git a/config/locales/cs.yml b/config/locales/cs.yml index c1b01bac..98c767cf 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -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 diff --git a/config/locales/da.yml b/config/locales/da.yml index c989f78a..097defb8 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -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 diff --git a/config/locales/de.yml b/config/locales/de.yml index 7b579960..982452e5 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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 diff --git a/config/locales/el.yml b/config/locales/el.yml index c3fd80bc..a2c8ecc4 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f636c9d9..40826709 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 72ccb859..97569e3d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 96609555..43f0a81b 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -896,3 +896,4 @@ eu: 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 diff --git a/config/locales/fi.yml b/config/locales/fi.yml index d5dab779..714801ed 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 35a05e6a..121d1b21 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 28a6ef90..3a2e7cfd 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -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 diff --git a/config/locales/he.yml b/config/locales/he.yml index 42a1a72f..2b40929c 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -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 diff --git a/config/locales/hr.yml b/config/locales/hr.yml index 3f6b9923..adc838e3 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -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 diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 4376d96a..9bc4375b 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -917,3 +917,4 @@ 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 diff --git a/config/locales/id.yml b/config/locales/id.yml index 6fa28038..45aa1e3b 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -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 diff --git a/config/locales/it.yml b/config/locales/it.yml index 4b65da00..231ecdfc 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -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 diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 1dd3d81e..5cd0e107 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -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 diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 00bb9643..a3c3f6a1 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -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 diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 26b26626..dba03890 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -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 diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 019e7114..b92189da 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -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 diff --git a/config/locales/no.yml b/config/locales/no.yml index f15a2e6a..38b51eeb 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -887,3 +887,4 @@ 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 diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 18dda44c..5a335358 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -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 diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 8e831a24..7a48a6e6 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -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 diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 1542146f..e320b9ff 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -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 diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 862538c4..778b5d07 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -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 diff --git a/config/locales/ru.yml b/config/locales/ru.yml index d669181f..1a35ca80 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -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 diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 012960a8..6a23d2d7 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -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 diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 7d59294b..305105fa 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -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 diff --git a/config/locales/sr.yml b/config/locales/sr.yml index f02b00f5..cebbbe4f 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -907,3 +907,4 @@ 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 diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 9f323954..fea2c237 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -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 diff --git a/config/locales/th.yml b/config/locales/th.yml index ae487ae6..e7bbf83f 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -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 diff --git a/config/locales/tr.yml b/config/locales/tr.yml index b103dc3e..59fae8f0 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -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 diff --git a/config/locales/uk.yml b/config/locales/uk.yml index e2efdefa..eecd665f 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -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 diff --git a/config/locales/vi.yml b/config/locales/vi.yml index 393559cf..662a12db 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -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 diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 80b3726f..87acf241 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -983,3 +983,4 @@ 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 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index f7ae0b45..a8781794 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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 diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 68b074a9..0641bab7 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -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