]> source.dussan.org Git - redmine.git/commitdiff
Fixed: when bulk editing, setting "Assigned to" to "nobody" causes an sql error with...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 26 Mar 2008 22:22:45 +0000 (22:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 26 Mar 2008 22:22:45 +0000 (22:22 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1294 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 04ff51ce9d56a452f5e95dc7d0aa02c6f37019e8..dbc3161d759aacbc279bf8e2a58dd165eebb5f78 100644 (file)
@@ -206,17 +206,17 @@ class IssuesController < ApplicationController
     if request.post?
       status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
       priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
-      assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
-      category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
-      fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
+      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])
       
       unsaved_issue_ids = []      
       @issues.each do |issue|
         journal = issue.init_journal(User.current, params[:notes])
         issue.priority = priority if priority
         issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
-        issue.category = category if category
-        issue.fixed_version = fixed_version if fixed_version
+        issue.category = category if category || params[:category_id] == 'none'
+        issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
         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?
index e3f09befa6d104e976595ba85fb920c483ca2209..31ed7ee56015a11a7221bcba1aaaa8a933b26308 100644 (file)
@@ -15,7 +15,9 @@
 <label><%= l(:field_priority) %>: 
 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label>
 <label><%= l(:field_category) %>: 
-<%= select_tag('category_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
+<%= select_tag('category_id', content_tag('option', l(:label_no_change_option), :value => '') +
+                                content_tag('option', l(:label_none), :value => 'none') +
+                                options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
 </p>
 <p>
 <label><%= l(:field_assigned_to) %>: 
@@ -23,7 +25,9 @@
                                  content_tag('option', l(:label_nobody), :value => 'none') +
                                  options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label>
 <label><%= l(:field_fixed_version) %>: 
-<%= select_tag('fixed_version_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.versions, :id, :name)) %></label>
+<%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') +
+                                   content_tag('option', l(:label_none), :value => 'none') +
+                                   options_from_collection_for_select(@project.versions, :id, :name)) %></label>
 </p>
 
 <p>
index f80110aa2993e2ca7b7cf004476bde1c421bc621..7d49f088dc74b7022bde2dd776ae872e6bfb6fd1 100644 (file)
@@ -339,6 +339,16 @@ class IssuesControllerTest < Test::Unit::TestCase
     assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
   end
 
+  def test_bulk_unassign
+    assert_not_nil Issue.find(2).assigned_to
+    @request.session[:user_id] = 2
+    # unassign issues
+    post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
+    assert_response 302
+    # check that the issues were updated
+    assert_nil Issue.find(2).assigned_to
+  end
+  
   def test_move_one_issue_to_another_project
     @request.session[:user_id] = 1
     post :move, :id => 1, :new_project_id => 2