From: Jean-Philippe Lang Date: Sat, 3 Sep 2016 07:55:57 +0000 (+0000) Subject: Bulk edit form not show fields based on target tracker and status (#23755). X-Git-Tag: 3.4.0~698 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dcf2e15b0617e4e0aa2cc4b7dde2c59b688c535a;p=redmine.git Bulk edit form not show fields based on target tracker and status (#23755). git-svn-id: http://svn.redmine.org/redmine/trunk@15815 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index d3dd2d504..779e85113 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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] ||= {} diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 37bdb6d42..29b4881c7 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -43,14 +43,16 @@ <%= 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')}')") %>

<% if @available_statuses.any? %>

<%= 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')}')") %>

<% end %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index d4c693a5a..ff37229e2 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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