diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b6c72a314..177fdeb38 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -265,6 +265,7 @@ class IssuesController < ApplicationController if @copy @attachments_present = @issues.detect {|i| i.attachments.any?}.present? @subtasks_present = @issues.detect {|i| !i.leaf?}.present? + @watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) && Watcher.where(:watchable_type => 'Issue', :watchable_id => @issues.map(&:id)).exists? end @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&) @@ -280,6 +281,7 @@ class IssuesController < ApplicationController attributes = parse_params_for_bulk_update(params[:issue]) copy_subtasks = (params[:copy_subtasks] == '1') copy_attachments = (params[:copy_attachments] == '1') + copy_watchers = (params[:copy_watchers] == '1') if @copy unless User.current.allowed_to?(:copy_issues, @projects) @@ -292,6 +294,9 @@ class IssuesController < ApplicationController unless User.current.allowed_to?(:add_issues, target_projects) raise ::Unauthorized end + unless User.current.allowed_to?(:add_issue_watchers, @projects) + copy_watchers = false + end else unless @issues.all?(&:attributes_editable?) raise ::Unauthorized @@ -313,6 +318,7 @@ class IssuesController < ApplicationController issue = orig_issue.copy({}, :attachments => copy_attachments, :subtasks => copy_subtasks, + :watchers => copy_watchers, :link => link_copy?(params[:link_copy]) ) else @@ -484,7 +490,8 @@ class IssuesController < ApplicationController @link_copy = link_copy?(params[:link_copy]) || request.get? @copy_attachments = params[:copy_attachments].present? || request.get? @copy_subtasks = params[:copy_subtasks].present? || request.get? - @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy) + @copy_watchers = User.current.allowed_to?(:add_issue_watchers, @project) + @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :watchers => @copy_watchers, :link => @link_copy) @issue.parent_issue_id = @copy_from.parent_id rescue ActiveRecord::RecordNotFound render_404 diff --git a/app/models/issue.rb b/app/models/issue.rb index f08e73d24..fc96e909c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -276,6 +276,9 @@ class Issue < ActiveRecord::Base attachement.copy(:container => self) end end + unless options[:watchers] == false + self.watcher_user_ids = issue.watcher_user_ids.dup + end @copied_from = issue @copy_options = options self diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 23817f875..7e10d03b6 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -108,19 +108,30 @@
<% end %> -<% if @copy && @attachments_present %> -<%= hidden_field_tag 'copy_attachments', '0' %> +<% if @copy && (@attachments_present || @subtasks_present || @watchers_present) %>- - <%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %> -
-<% end %> - -<% if @copy && @subtasks_present %> -<%= hidden_field_tag 'copy_subtasks', '0' %> -- - <%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %> + + <% if @attachments_present %> + + <% end %> + <% if @subtasks_present %> + + <% end %> + <% if @watchers_present %> + + <% end %>
<% end %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 6c025123d..dacbd370e 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -3065,6 +3065,16 @@ class IssuesControllerTest < Redmine::ControllerTest assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]' end + def test_new_as_copy_should_preserve_watchers + @request.session[:user_id] = 2 + user = User.generate! + Watcher.create!(:watchable => Issue.find(1), :user => user) + get :new, :project_id => 1, :copy_from => 1 + + assert_select 'input[type=checkbox][name=?][checked=checked]', 'issue[watcher_user_ids][]', 1 + assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user.id.to_s + end + def test_new_as_copy_with_invalid_issue_should_respond_with_404 @request.session[:user_id] = 2 get :new, :project_id => 1, :copy_from => 99999 @@ -4725,6 +4735,20 @@ class IssuesControllerTest < Redmine::ControllerTest assert_equal count, copy.descendants.count end + def test_bulk_copy_should_allow_copying_the_subtasks + Watcher.create!(:watchable => Issue.find(1), :user => User.find(3)) + @request.session[:user_id] = 2 + + assert_difference 'Issue.count' do + post :bulk_update, :ids => [1], :copy => '1', :copy_watchers => '1', + :issue => { + :project_id => '' + } + end + copy = Issue.order(:id => :desc).first + assert_equal 1, copy.watchers.count + end + def test_bulk_copy_should_not_copy_selected_subtasks_twice issue = Issue.generate_with_descendants! count = issue.descendants.count