]> source.dussan.org Git - redmine.git/commitdiff
Bulk edit form not show fields based on target tracker and status (#23755).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Sep 2016 07:55:57 +0000 (07:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Sep 2016 07:55:57 +0000 (07:55 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15815 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index d3dd2d5046e8d8f01fdbf0e43610e6a786101b1b..779e8511386b236770fadcd09e1f7a7eeb9c930e 100644 (file)
@@ -218,24 +218,41 @@ class IssuesController < ApplicationController
       end
     end
 
+    edited_issues = Issue.where(:id => @issues.map(&:id)).to_a
+
     @allowed_projects = Issue.allowed_target_projects
     if params[:issue]
       @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
       if @target_project
         target_projects = [@target_project]
+        edited_issues.each {|issue| issue.project = @target_project}
       end
     end
     target_projects ||= @projects
 
+    @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
+    if params[:issue]
+      @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s}
+      if @target_tracker
+        edited_issues.each {|issue| issue.tracker = @target_tracker}
+      end
+    end
+
     if @copy
       # Copied issues will get their default statuses
       @available_statuses = []
     else
-      @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
+      @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&)
     end
-    @custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&)
+    if params[:issue]
+      @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s}
+      if @target_status
+        edited_issues.each {|issue| issue.status = @target_status}
+      end
+    end
+
+    @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&)
     @assignables = target_projects.map(&:assignable_users).reduce(:&)
-    @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
     @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
     @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
     if @copy
@@ -243,7 +260,7 @@ class IssuesController < ApplicationController
       @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
     end
 
-    @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
+    @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&)
 
     @issue_params = params[:issue] || {}
     @issue_params[:custom_field_values] ||= {}
index 37bdb6d42ce3563cabd2a09eda755558181c255e..29b4881c7edd25ed97b3679e6811a3c370c49e15 100644 (file)
   <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
   <%= select_tag('issue[tracker_id]',
                  content_tag('option', l(:label_no_change_option), :value => '') +
-                   options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id])) %>
+                   options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id]),
+                   :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
 </p>
 <% if @available_statuses.any? %>
 <p>
   <label for='issue_status_id'><%= l(:field_status) %></label>
   <%= select_tag('issue[status_id]',
                  content_tag('option', l(:label_no_change_option), :value => '') +
-                   options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id])) %>
+                   options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id]),
+                   :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
 </p>
 <% end %>
 
index d4c693a5a3ff3544c7ac337fb693c477192ede00..ff37229e28df0378f9d5141cb2f42121be843423 100644 (file)
@@ -3996,6 +3996,20 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_select 'input[name=?]', "issue[custom_field_values][#{field2.id}]", 0
   end
 
+  def test_bulk_edit_should_propose_target_tracker_custom_fields
+    IssueCustomField.delete_all
+    field1 = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
+    field2 = IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
+    @request.session[:user_id] = 2
+
+    issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
+    get :bulk_edit, :ids => issue_ids, :issue => {:tracker_id => 2}
+    assert_response :success
+
+    assert_select 'input[name=?]', "issue[custom_field_values][#{field1.id}]", 0
+    assert_select 'input[name=?]', "issue[custom_field_values][#{field2.id}]"
+  end
+
   def test_bulk_update
     @request.session[:user_id] = 2
     # update issues priority