From 3e6f42e46d43650b6f561849d0bfaf0f0e018bf6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 11 Apr 2010 14:20:40 +0000 Subject: Backported r3608 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3642 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 26 ++++++++++++++------------ app/models/mailer.rb | 9 +++++++++ app/views/projects/copy.rhtml | 2 ++ 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ec22e2206..cb041b9ea 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -102,18 +102,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 9c409af69..e987c8a87 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -310,6 +310,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 @@ <%= hidden_field_tag 'only[]', '' %> +
+ <%= submit_tag l(:button_copy) %> -- cgit v1.2.3