@@ -235,6 +235,9 class IssuesController < ApplicationController | |||||
235 | @trackers = target_projects.map(&:trackers).reduce(:&) |
|
235 | @trackers = target_projects.map(&:trackers).reduce(:&) | |
236 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
236 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) | |
237 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) |
|
237 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) | |
|
238 | if @copy | |||
|
239 | @attachments_present = @issues.detect {|i| i.attachments.any?}.present? | |||
|
240 | end | |||
238 |
|
241 | |||
239 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) |
|
242 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) | |
240 | render :layout => false if request.xhr? |
|
243 | render :layout => false if request.xhr? | |
@@ -250,7 +253,7 class IssuesController < ApplicationController | |||||
250 | @issues.each do |issue| |
|
253 | @issues.each do |issue| | |
251 | issue.reload |
|
254 | issue.reload | |
252 | if @copy |
|
255 | if @copy | |
253 | issue = issue.copy |
|
256 | issue = issue.copy({}, :attachments => params[:copy_attachments].present?) | |
254 | end |
|
257 | end | |
255 | journal = issue.init_journal(User.current, params[:notes]) |
|
258 | journal = issue.init_journal(User.current, params[:notes]) | |
256 | issue.safe_attributes = attributes |
|
259 | issue.safe_attributes = attributes |
@@ -145,8 +145,8 class Issue < ActiveRecord::Base | |||||
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | # Returns an unsaved copy of the issue |
|
147 | # Returns an unsaved copy of the issue | |
148 | def copy(attributes=nil) |
|
148 | def copy(attributes=nil, copy_options={}) | |
149 | copy = self.class.new.copy_from(self) |
|
149 | copy = self.class.new.copy_from(self, copy_options) | |
150 | copy.attributes = attributes if attributes |
|
150 | copy.attributes = attributes if attributes | |
151 | copy |
|
151 | copy | |
152 | end |
|
152 | end |
@@ -60,6 +60,13 | |||||
60 | <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p> |
|
60 | <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p> | |
61 | <% end %> |
|
61 | <% end %> | |
62 |
|
62 | |||
|
63 | <% if @copy && @attachments_present %> | |||
|
64 | <p> | |||
|
65 | <label for='copy_attachments'><%= l(:label_copy_attachments) %></label> | |||
|
66 | <%= check_box_tag 'copy_attachments', '1', true %> | |||
|
67 | </p> | |||
|
68 | <% end %> | |||
|
69 | ||||
63 | <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> |
|
70 | <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> | |
64 | </div> |
|
71 | </div> | |
65 |
|
72 |
@@ -3057,6 +3057,19 class IssuesControllerTest < ActionController::TestCase | |||||
3057 | assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error] |
|
3057 | assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error] | |
3058 | end |
|
3058 | end | |
3059 |
|
3059 | |||
|
3060 | def test_get_bulk_copy | |||
|
3061 | @request.session[:user_id] = 2 | |||
|
3062 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' | |||
|
3063 | assert_response :success | |||
|
3064 | assert_template 'bulk_edit' | |||
|
3065 | ||||
|
3066 | issues = assigns(:issues) | |||
|
3067 | assert_not_nil issues | |||
|
3068 | assert_equal [1, 2, 3], issues.map(&:id).sort | |||
|
3069 | ||||
|
3070 | assert_select 'input[name=copy_attachments]' | |||
|
3071 | end | |||
|
3072 | ||||
3060 | def test_bulk_copy_to_another_project |
|
3073 | def test_bulk_copy_to_another_project | |
3061 | @request.session[:user_id] = 2 |
|
3074 | @request.session[:user_id] = 2 | |
3062 | assert_difference 'Issue.count', 2 do |
|
3075 | assert_difference 'Issue.count', 2 do | |
@@ -3145,6 +3158,36 class IssuesControllerTest < ActionController::TestCase | |||||
3145 | assert_equal 'Copying one issue', journal.notes |
|
3158 | assert_equal 'Copying one issue', journal.notes | |
3146 | end |
|
3159 | end | |
3147 |
|
3160 | |||
|
3161 | def test_bulk_copy_should_allow_not_copying_the_attachments | |||
|
3162 | attachment_count = Issue.find(3).attachments.size | |||
|
3163 | assert attachment_count > 0 | |||
|
3164 | @request.session[:user_id] = 2 | |||
|
3165 | ||||
|
3166 | assert_difference 'Issue.count', 1 do | |||
|
3167 | assert_no_difference 'Attachment.count' do | |||
|
3168 | post :bulk_update, :ids => [3], :copy => '1', | |||
|
3169 | :issue => { | |||
|
3170 | :project_id => '' | |||
|
3171 | } | |||
|
3172 | end | |||
|
3173 | end | |||
|
3174 | end | |||
|
3175 | ||||
|
3176 | def test_bulk_copy_should_allow_copying_the_attachments | |||
|
3177 | attachment_count = Issue.find(3).attachments.size | |||
|
3178 | assert attachment_count > 0 | |||
|
3179 | @request.session[:user_id] = 2 | |||
|
3180 | ||||
|
3181 | assert_difference 'Issue.count', 1 do | |||
|
3182 | assert_difference 'Attachment.count', attachment_count do | |||
|
3183 | post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1', | |||
|
3184 | :issue => { | |||
|
3185 | :project_id => '' | |||
|
3186 | } | |||
|
3187 | end | |||
|
3188 | end | |||
|
3189 | end | |||
|
3190 | ||||
3148 | def test_bulk_copy_to_another_project_should_follow_when_needed |
|
3191 | def test_bulk_copy_to_another_project_should_follow_when_needed | |
3149 | @request.session[:user_id] = 2 |
|
3192 | @request.session[:user_id] = 2 | |
3150 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' |
|
3193 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' |
General Comments 0
You need to be logged in to leave comments.
Login now