diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-14 06:54:02 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-14 06:54:02 +0000 |
commit | fd450fd2da0018a6edb941e1b59fee87f6c4efec (patch) | |
tree | 8962084bc6420d81aed6f80dd343ee37a8e9800f | |
parent | 2c0ba78f7092d0af263b19daac9ac3c0becbb4eb (diff) | |
download | redmine-fd450fd2da0018a6edb941e1b59fee87f6c4efec.tar.gz redmine-fd450fd2da0018a6edb941e1b59fee87f6c4efec.zip |
Merged r9404, r9405 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9411 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/issues_controller.rb | 11 | ||||
-rw-r--r-- | app/models/issue.rb | 42 | ||||
-rw-r--r-- | app/views/issues/bulk_edit.html.erb | 7 | ||||
-rw-r--r-- | test/functional/issues_controller_test.rb | 89 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 8 |
5 files changed, 120 insertions, 37 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index dfec893d6..cffb69b61 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -225,12 +225,19 @@ class IssuesController < ApplicationController end target_projects ||= @projects - @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) + if @copy + @available_statuses = [IssueStatus.default] + else + @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) + end @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) @assignables = target_projects.map(&:assignable_users).reduce(:&) @trackers = target_projects.map(&:trackers).reduce(:&) @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) + if @copy + @attachments_present = @issues.detect {|i| i.attachments.any?}.present? + end @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) render :layout => false if request.xhr? @@ -246,7 +253,7 @@ class IssuesController < ApplicationController @issues.each do |issue| issue.reload if @copy - issue = issue.copy + issue = issue.copy({}, :attachments => params[:copy_attachments].present?) end journal = issue.init_journal(User.current, params[:notes]) issue.safe_attributes = attributes diff --git a/app/models/issue.rb b/app/models/issue.rb index ec8c45d34..d72ff4dcf 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -145,8 +145,8 @@ class Issue < ActiveRecord::Base end # Returns an unsaved copy of the issue - def copy(attributes=nil) - copy = self.class.new.copy_from(self) + def copy(attributes=nil, copy_options={}) + copy = self.class.new.copy_from(self, copy_options) copy.attributes = attributes if attributes copy end @@ -511,24 +511,28 @@ class Issue < ActiveRecord::Base # Returns an array of statuses that user is able to apply def new_statuses_allowed_to(user=User.current, include_default=false) - initial_status = nil - if new_record? - initial_status = IssueStatus.default - elsif status_id_was - initial_status = IssueStatus.find_by_id(status_id_was) + if new_record? && @copied_from + [IssueStatus.default, @copied_from.status].compact.uniq.sort + else + initial_status = nil + if new_record? + initial_status = IssueStatus.default + elsif status_id_was + initial_status = IssueStatus.find_by_id(status_id_was) + end + initial_status ||= status + + statuses = initial_status.find_new_statuses_allowed_to( + user.admin ? Role.all : user.roles_for_project(project), + tracker, + author == user, + assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id + ) + statuses << initial_status unless statuses.empty? + statuses << IssueStatus.default if include_default + statuses = statuses.compact.uniq.sort + blocked? ? statuses.reject {|s| s.is_closed?} : statuses end - initial_status ||= status - - statuses = initial_status.find_new_statuses_allowed_to( - user.admin ? Role.all : user.roles_for_project(project), - tracker, - author == user, - assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id - ) - statuses << initial_status unless statuses.empty? - statuses << IssueStatus.default if include_default - statuses = statuses.compact.uniq.sort - blocked? ? statuses.reject {|s| s.is_closed?} : statuses end def assigned_to_was diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 0263ab916..e81676ada 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -60,6 +60,13 @@ <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p> <% end %> +<% if @copy && @attachments_present %> +<p> + <label for='copy_attachments'><%= l(:label_copy_attachments) %></label> + <%= check_box_tag 'copy_attachments', '1', true %> +</p> +<% end %> + <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> </div> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 484880cc7..e039468c2 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -3057,6 +3057,19 @@ class IssuesControllerTest < ActionController::TestCase assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error] end + def test_get_bulk_copy + @request.session[:user_id] = 2 + get :bulk_edit, :ids => [1, 2, 3], :copy => '1' + assert_response :success + assert_template 'bulk_edit' + + issues = assigns(:issues) + assert_not_nil issues + assert_equal [1, 2, 3], issues.map(&:id).sort + + assert_select 'input[name=copy_attachments]' + end + def test_bulk_copy_to_another_project @request.session[:user_id] = 2 assert_difference 'Issue.count', 2 do @@ -3065,27 +3078,41 @@ class IssuesControllerTest < ActionController::TestCase end end assert_redirected_to '/projects/ecookbook/issues' + + copies = Issue.all(:order => 'id DESC', :limit => issues.size) + copies.each do |copy| + assert_equal 2, copy.project_id + end end def test_bulk_copy_should_allow_not_changing_the_issue_attributes @request.session[:user_id] = 2 - issue_before_move = Issue.find(1) - assert_difference 'Issue.count', 1 do - assert_no_difference 'Project.find(1).issues.count' do - post :bulk_update, :ids => [1], :copy => '1', - :issue => { - :project_id => '2', :tracker_id => '', :assigned_to_id => '', - :status_id => '', :start_date => '', :due_date => '' - } - end + issues = [ + Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil), + Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3) + ] + + assert_difference 'Issue.count', issues.size do + post :bulk_update, :ids => issues.map(&:id), :copy => '1', + :issue => { + :project_id => '', :tracker_id => '', :assigned_to_id => '', + :status_id => '', :start_date => '', :due_date => '' + } + end + + copies = Issue.all(:order => 'id DESC', :limit => issues.size) + issues.each do |orig| + copy = copies.detect {|c| c.subject == orig.subject} + assert_not_nil copy + assert_equal orig.project_id, copy.project_id + assert_equal orig.tracker_id, copy.tracker_id + assert_equal orig.status_id, copy.status_id + assert_equal orig.assigned_to_id, copy.assigned_to_id + assert_equal orig.priority_id, copy.priority_id end - issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) - assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id - assert_equal issue_before_move.status_id, issue_after_move.status_id - assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id end - def test_bulk_copy_should_allow_changing_the_issue_attributes + def test_bulk_copy_should_allow_changing_the_issue_attributes # Fixes random test failure with Mysql # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) # doesn't return the expected results @@ -3097,7 +3124,7 @@ class IssuesControllerTest < ActionController::TestCase post :bulk_update, :ids => [1, 2], :copy => '1', :issue => { :project_id => '2', :tracker_id => '', :assigned_to_id => '4', - :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' + :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' } end end @@ -3107,7 +3134,7 @@ class IssuesControllerTest < ActionController::TestCase copied_issues.each do |issue| assert_equal 2, issue.project_id, "Project is incorrect" assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" - assert_equal 3, issue.status_id, "Status is incorrect" + assert_equal 1, issue.status_id, "Status is incorrect" assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" end @@ -3131,6 +3158,36 @@ class IssuesControllerTest < ActionController::TestCase assert_equal 'Copying one issue', journal.notes end + def test_bulk_copy_should_allow_not_copying_the_attachments + attachment_count = Issue.find(3).attachments.size + assert attachment_count > 0 + @request.session[:user_id] = 2 + + assert_difference 'Issue.count', 1 do + assert_no_difference 'Attachment.count' do + post :bulk_update, :ids => [3], :copy => '1', + :issue => { + :project_id => '' + } + end + end + end + + def test_bulk_copy_should_allow_copying_the_attachments + attachment_count = Issue.find(3).attachments.size + assert attachment_count > 0 + @request.session[:user_id] = 2 + + assert_difference 'Issue.count', 1 do + assert_difference 'Attachment.count', attachment_count do + post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1', + :issue => { + :project_id => '' + } + end + end + end + def test_bulk_copy_to_another_project_should_follow_when_needed @request.session[:user_id] = 2 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index ddebbee19..b55b3d065 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -395,6 +395,14 @@ class IssueTest < ActiveSupport::TestCase assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) end + def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying + issue = Issue.find(1).copy + assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) + + issue = Issue.find(2).copy + assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) + end + def test_copy issue = Issue.new.copy_from(1) assert issue.copy? |