diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-21 11:17:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-21 11:17:29 +0000 |
commit | 79b4f681760e9d674e5b959abcb3087fee009008 (patch) | |
tree | 8d97b3c0a653e8f58bf7febb93e0d4e405043fed /app | |
parent | 5225fb70f533c992bd50435096ebd2bfb1c3e942 (diff) | |
download | redmine-79b4f681760e9d674e5b959abcb3087fee009008.tar.gz redmine-79b4f681760e9d674e5b959abcb3087fee009008.zip |
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
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects_controller.rb | 26 | ||||
-rw-r--r-- | app/models/mailer.rb | 9 | ||||
-rw-r--r-- | app/views/projects/copy.rhtml | 2 |
3 files changed, 25 insertions, 12 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8ef3d63d7..b6ffba56a 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 173e33c40..f39c53209 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 49e262786..dfcd44339 100644 --- a/app/views/projects/copy.rhtml +++ b/app/views/projects/copy.rhtml @@ -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) %> |