]> source.dussan.org Git - redmine.git/commitdiff
Fixed MissingFeatureException: let user choose to copy attachments or not when bulk...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Apr 2012 06:21:03 +0000 (06:21 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Apr 2012 06:21:03 +0000 (06:21 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9405 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb
app/views/issues/bulk_edit.html.erb
test/functional/issues_controller_test.rb

index 84ff8fd236e5bc2b28d420e496735c53d38fe5ce..cffb69b61156a16d1621241861d21edb4638bf60 100644 (file)
@@ -235,6 +235,9 @@ class IssuesController < ApplicationController
     @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?
@@ -250,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
index 8ebc20fc00dd29ba83b7966957d721b8b88a31b0..d72ff4dcff42ad6a9bd72f4be70eba0f0e11f0d4 100644 (file)
@@ -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
index 0263ab91672af030ebfd0ec62f53b8dd8081d8b8..e81676adadf9f589c48da3c83c493feeb58f0ad3 100644 (file)
   <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>
 
index 1b0224dfbfef7f15e8540ba15ba86af1c85fe6ba..e039468c2716b4458c2ca2724517b4e4224b19e3 100644 (file)
@@ -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
@@ -3099,7 +3112,7 @@ class IssuesControllerTest < ActionController::TestCase
     end
   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
@@ -3145,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'