From bcc9007196828635abf4ce0e0260766241e7b9d5 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Lang
Date: Sun, 25 Jan 2009 16:04:28 +0000
Subject: [PATCH] Ability to bulk edit custom fields of type 'list' (#461).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2316 e93f8b46-1217-0410-a6f0-8f06a7374b81
---
app/controllers/issues_controller.rb | 3 +++
app/views/issues/bulk_edit.rhtml | 7 ++++++
test/functional/issues_controller_test.rb | 29 +++++++++++++++++++++--
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 62e5e5787..cc9f70e4b 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -232,6 +232,7 @@ class IssuesController < ApplicationController
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
+ custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
unsaved_issue_ids = []
@issues.each do |issue|
@@ -243,6 +244,7 @@ class IssuesController < ApplicationController
issue.start_date = params[:start_date] unless params[:start_date].blank?
issue.due_date = params[:due_date] unless params[:due_date].blank?
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
+ issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
# Don't save any change to the issue if the user is not authorized to apply the requested status
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
@@ -264,6 +266,7 @@ class IssuesController < ApplicationController
# Find potential statuses the user could be allowed to switch issues to
@available_statuses = Workflow.find(:all, :include => :new_status,
:conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq.sort
+ @custom_fields = @project.issue_custom_fields.select {|f| f.field_format == 'list'}
end
def move
diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml
index b916cf092..d56dfc022 100644
--- a/app/views/issues/bulk_edit.rhtml
+++ b/app/views/issues/bulk_edit.rhtml
@@ -38,6 +38,13 @@
+
+<% @custom_fields.each do |custom_field| %>
+
+<%= select_tag "custom_field_values[#{custom_field.id}]", options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values) %>
+
+<% end %>
+
<%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index b3978c39c..daca0eb41 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -629,11 +629,36 @@ class IssuesControllerTest < Test::Unit::TestCase
def test_bulk_edit
@request.session[:user_id] = 2
# update issues priority
- post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
+ post :bulk_edit, :ids => [1, 2], :priority_id => 7,
+ :assigned_to_id => '',
+ :custom_field_values => {'2' => ''},
+ :notes => 'Bulk editing'
assert_response 302
# check that the issues were updated
assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
- assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
+
+ issue = Issue.find(1)
+ journal = issue.journals.find(:first, :order => 'created_on DESC')
+ assert_equal '125', issue.custom_value_for(2).value
+ assert_equal 'Bulk editing', journal.notes
+ assert_equal 1, journal.details.size
+ end
+
+ def test_bulk_edit_custom_field
+ @request.session[:user_id] = 2
+ # update issues priority
+ post :bulk_edit, :ids => [1, 2], :priority_id => '',
+ :assigned_to_id => '',
+ :custom_field_values => {'2' => '777'},
+ :notes => 'Bulk editing custom field'
+ assert_response 302
+
+ issue = Issue.find(1)
+ journal = issue.journals.find(:first, :order => 'created_on DESC')
+ assert_equal '777', issue.custom_value_for(2).value
+ assert_equal 1, journal.details.size
+ assert_equal '125', journal.details.first.old_value
+ assert_equal '777', journal.details.first.value
end
def test_bulk_unassign