]> source.dussan.org Git - redmine.git/commitdiff
Enhanced the Issue Bulk Copy feature:
authorEric Davis <edavis@littlestreamsoftware.com>
Fri, 4 Dec 2009 22:46:12 +0000 (22:46 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Fri, 4 Dec 2009 22:46:12 +0000 (22:46 +0000)
* Add a Copy option to the Context menu for multiple issues.
* Added assigned to, status, start and due date options to the move/copy form.
* Allow Issue#move_to to change attributes on the moved/copied issue.

  #4117

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3122 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb
app/models/workflow.rb
app/views/issues/context_menu.rhtml
app/views/issues/move.rhtml
test/functional/issues_controller_test.rb
test/unit/issue_test.rb

index 336f63b1698f54b1f60c99cdf55c284e5d1e74f7..a86653ed3b3f31d09738ef0d5a8865acd6e05cfc 100644 (file)
@@ -271,13 +271,12 @@ class IssuesController < ApplicationController
       redirect_to(params[:back_to] || {:controller => 'issues', :action => 'index', :project_id => @project})
       return
     end
-    # Find potential statuses the user could be allowed to switch issues to
-    @available_statuses = Workflow.find(:all, :include => :new_status,
-                                              :conditions => {:role_id => User.current.roles_for_project(@project).collect(&:id)}).collect(&:new_status).compact.uniq.sort
+    @available_statuses = Workflow.available_statuses(@project)
     @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
   end
 
   def move
+    @copy = params[:copy_options] && params[:copy_options][:copy]
     @allowed_projects = []
     # find projects to which the user is allowed to move the issue
     if User.current.admin?
@@ -289,13 +288,18 @@ class IssuesController < ApplicationController
     @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
     @target_project ||= @project    
     @trackers = @target_project.trackers
+    @available_statuses = Workflow.available_statuses(@project)
     if request.post?
       new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
       unsaved_issue_ids = []
       moved_issues = []
       @issues.each do |issue|
+        changed_attributes = {}
+        [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
+          changed_attributes[valid_attribute] = params[valid_attribute] if params[valid_attribute]
+        end
         issue.init_journal(User.current)
-        if r = issue.move_to(@target_project, new_tracker, params[:copy_options])
+        if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
           moved_issues << r
         else
           unsaved_issue_ids << issue.id
index 1facf2a56915a9fd29eb6cffb7e6f293bcf54436..dac64cbd2ad09a2746bf93c9f9605174738a898e 100644 (file)
@@ -108,7 +108,15 @@ class Issue < ActiveRecord::Base
       end
       if options[:copy]
         issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
-        issue.status = self.status
+        issue.status = if options[:attributes] && options[:attributes][:status_id]
+                         IssueStatus.find_by_id(options[:attributes][:status_id])
+                       else
+                         self.status
+                       end
+      end
+      # Allow bulk setting of attributes on the issue
+      if options[:attributes]
+        issue.attributes = options[:attributes]
       end
       if issue.save
         unless options[:copy]
index 4168fdea049aded776c28099843a19fd7d149e2b..a96abaf189324bea08b162ffd6751010585e4f06 100644 (file)
@@ -40,4 +40,15 @@ class Workflow < ActiveRecord::Base
     
     result
   end
+
+  # Find potential statuses the user could be allowed to switch issues to
+  def self.available_statuses(project, user=User.current)
+    Workflow.find(:all,
+                  :include => :new_status,
+                  :conditions => {:role_id => user.roles_for_project(project).collect(&:id)}).
+      collect(&:new_status).
+      compact.
+      uniq.
+      sort
+  end
 end
index d2c673d772b20b2e705cde7b84ca8371e13ea105..c67c1bcd540dfe0f30627cd53275f639eea9341f 100644 (file)
@@ -88,8 +88,6 @@
        </li>
        
 <% if !@issue.nil? %>
-       <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
-               :class => 'icon-copy', :disabled => !@can[:copy] %></li>
        <% if @can[:log_time] -%>
        <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue},
                :class => 'icon-time-add' %></li>
        <% end %>
 <% end %>
 
+<% if @issue.present? %>
+  <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
+               :class => 'icon-copy', :disabled => !@can[:copy] %></li>
+<% else %>
+  <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id), :copy_options => {:copy => 't'}},
+                               :class => 'icon-copy', :disabled => !@can[:move]  %></li>
+<% end %>
+
   <li><%= context_menu_link l(:button_move), {:controller => 'issues', :action => 'move', :ids => @issues.collect(&:id)},
                                :class => 'icon-move', :disabled => !@can[:move]  %></li>
   <li><%= context_menu_link l(:button_delete), {:controller => 'issues', :action => 'destroy', :ids => @issues.collect(&:id)},
index 0d4717f53424985bb916c0052c8f46c085f5126f..0d5cb130dca624c0b3ae1b77b197db0fe7381007 100644 (file)
 <p><label for="new_tracker_id"><%=l(:field_tracker)%>:</label>
 <%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
 
+<p>
+  <label><%= l(:field_assigned_to) %></label>
+  <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
+                                   content_tag('option', l(:label_nobody), :value => 'none') +
+                                   options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
+</p>
+
+<p>
+  <label><%= l(:field_status) %></label>
+  <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %>
+</p>
+
+<p>
+  <label><%= l(:field_start_date) %></label>
+  <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
+</p>
+
+<p>
+  <label><%= l(:field_due_date) %></label>
+  <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
+</p>
+
 <p><label for="copy_options_copy"><%= l(:button_copy)%></label>
-<%= check_box_tag "copy_options[copy]", "1" %></p>
+<%= check_box_tag "copy_options[copy]", "1", @copy %></p>
 </div>
 
 <%= submit_tag l(:button_move) %> 
index 93e29957e07be3f4744786e93c326bbe0fe20d31..8ebf6c02250c96de6c8f13d9edcfdb3c42e514a2 100644 (file)
@@ -1059,6 +1059,27 @@ class IssuesControllerTest < ActionController::TestCase
     assert_redirected_to 'projects/ecookbook/issues'
   end
 
+  context "#move via bulk copy" do
+    should "allow changing the issue's attributes" do
+      @request.session[:user_id] = 2
+      assert_difference 'Issue.count', 2 do
+        assert_no_difference 'Project.find(1).issues.count' do
+          post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
+        end
+      end
+
+      copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
+      assert_equal 2, copied_issues.size
+      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 '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
+    end
+  end
+  
   def test_copy_to_another_project_should_follow_when_needed
     @request.session[:user_id] = 2
     post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
@@ -1117,6 +1138,9 @@ class IssuesControllerTest < ActionController::TestCase
     assert_tag :tag => 'a', :content => 'Dave Lopper',
                             :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
                                              :class => '' }
+    assert_tag :tag => 'a', :content => 'Copy',
+                            :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
+                                             :class => 'icon-copy' }
     assert_tag :tag => 'a', :content => 'Move',
                             :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
                                              :class => 'icon-move' }
index bd37f9880811ad96937fef3331101a7d7d12e712..6213524b8a95bae0d56e506867b035e182e31f7a 100644 (file)
@@ -352,6 +352,38 @@ class IssueTest < ActiveSupport::TestCase
     # Custom field #2 is not associated with target tracker
     assert_nil copy.custom_value_for(2)
   end
+
+  context "#move_to" do
+    context "as a copy" do
+      setup do
+        @issue = Issue.find(1)
+        @copy = nil
+      end
+
+      should "allow assigned_to changes" do
+        @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
+        assert_equal 3, @copy.assigned_to_id
+      end
+
+      should "allow status changes" do
+        @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}})
+        assert_equal 2, @copy.status_id
+      end
+
+      should "allow start date changes" do
+        date = Date.today
+        @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
+        assert_equal date, @copy.start_date
+      end
+
+      should "allow due date changes" do
+        date = Date.today
+        @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}})
+
+        assert_equal date, @copy.due_date
+      end
+    end
+  end
   
   def test_recipients_should_not_include_users_that_cannot_view_the_issue
     issue = Issue.find(12)