mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Option to copy watchers when copying issues (#10460).
git-svn-id: http://svn.redmine.org/redmine/trunk@16509 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8ea86a8249
commit
1cd985dd6b
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -108,19 +108,30 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if @copy && @attachments_present %>
|
||||
<%= hidden_field_tag 'copy_attachments', '0' %>
|
||||
<% if @copy && (@attachments_present || @subtasks_present || @watchers_present) %>
|
||||
<p>
|
||||
<label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
|
||||
<%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if @copy && @subtasks_present %>
|
||||
<%= hidden_field_tag 'copy_subtasks', '0' %>
|
||||
<p>
|
||||
<label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
|
||||
<%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %>
|
||||
<label><%= l(:button_copy) %></label>
|
||||
<% if @attachments_present %>
|
||||
<label class="block">
|
||||
<%= hidden_field_tag 'copy_attachments', '0' %>
|
||||
<%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %>
|
||||
<%= l(:label_attachment_plural) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% if @subtasks_present %>
|
||||
<label class="block">
|
||||
<%= hidden_field_tag 'copy_subtasks', '0' %>
|
||||
<%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %>
|
||||
<%= l(:label_subtask_plural) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% if @watchers_present %>
|
||||
<label class="block">
|
||||
<%= hidden_field_tag 'copy_watchers', '0' %>
|
||||
<%= check_box_tag 'copy_watchers', '1', params[:copy_watchers] != '0' %>
|
||||
<%= l(:label_issue_watchers) %>
|
||||
</label>
|
||||
<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user