diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index a3cd8fb9f..4a07bd9d3 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -282,6 +282,8 @@ class IssuesController < ApplicationController @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} end + @assignee_to_author = true if attributes['assigned_to_id'].present? && attributes['assigned_to_id'] == 'author' + @issues.each do |orig_issue| orig_issue.reload if @copy @@ -294,6 +296,9 @@ class IssuesController < ApplicationController issue = orig_issue end journal = issue.init_journal(User.current, params[:notes]) + if @assignee_to_author + attributes['assigned_to_id'] = issue.author_id + end issue.safe_attributes = attributes call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) if issue.save @@ -369,7 +374,7 @@ class IssuesController < ApplicationController # Overrides Redmine::MenuManager::MenuController::ClassMethods for # when the "New issue" tab is enabled def current_menu_item - if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym) + if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym) :new_issue else super diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 181bd86e3..19dcbbb28 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -603,8 +603,8 @@ class IssuesControllerTest < ActionController::TestCase str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') issue = Issue.generate!(:subject => str_utf8) - get :index, :project_id => 1, - :f => ['subject'], + get :index, :project_id => 1, + :f => ['subject'], :op => '=', :values => [str_utf8], :format => 'csv' assert_equal 'text/csv; header=present', @response.content_type @@ -622,8 +622,8 @@ class IssuesControllerTest < ActionController::TestCase str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') issue = Issue.generate!(:subject => str_utf8) - get :index, :project_id => 1, - :f => ['subject'], + get :index, :project_id => 1, + :f => ['subject'], :op => '=', :values => [str_utf8], :c => ['status', 'subject'], :format => 'csv', @@ -645,8 +645,8 @@ class IssuesControllerTest < ActionController::TestCase str1 = "test_index_csv_tw" issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') - get :index, :project_id => 1, - :f => ['subject'], + get :index, :project_id => 1, + :f => ['subject'], :op => '=', :values => [str1], :c => ['estimated_hours', 'subject'], :format => 'csv', @@ -662,8 +662,8 @@ class IssuesControllerTest < ActionController::TestCase str1 = "test_index_csv_fr" issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') - get :index, :project_id => 1, - :f => ['subject'], + get :index, :project_id => 1, + :f => ['subject'], :op => '=', :values => [str1], :c => ['estimated_hours', 'subject'], :format => 'csv', @@ -740,7 +740,7 @@ class IssuesControllerTest < ActionController::TestCase Setting.issue_list_default_columns = %w(subject author) get :index, :sort => 'tracker' end - + def test_index_sort_by_assigned_to get :index, :sort => 'assigned_to' assert_response :success @@ -748,7 +748,7 @@ class IssuesControllerTest < ActionController::TestCase assert_equal assignees.sort, assignees assert_select 'table.issues.sort-by-assigned-to.sort-asc' end - + def test_index_sort_by_assigned_to_desc get :index, :sort => 'assigned_to:desc' assert_response :success @@ -756,45 +756,45 @@ class IssuesControllerTest < ActionController::TestCase assert_equal assignees.sort.reverse, assignees assert_select 'table.issues.sort-by-assigned-to.sort-desc' end - + def test_index_group_by_assigned_to get :index, :group_by => 'assigned_to', :sort => 'priority' assert_response :success end - + def test_index_sort_by_author get :index, :sort => 'author' assert_response :success authors = assigns(:issues).collect(&:author) assert_equal authors.sort, authors end - + def test_index_sort_by_author_desc get :index, :sort => 'author:desc' assert_response :success authors = assigns(:issues).collect(&:author) assert_equal authors.sort.reverse, authors end - + def test_index_group_by_author get :index, :group_by => 'author', :sort => 'priority' assert_response :success end - + def test_index_sort_by_spent_hours get :index, :sort => 'spent_hours:desc' assert_response :success hours = assigns(:issues).collect(&:spent_hours) assert_equal hours.sort.reverse, hours end - + def test_index_sort_by_total_spent_hours get :index, :sort => 'total_spent_hours:desc' assert_response :success hours = assigns(:issues).collect(&:total_spent_hours) assert_equal hours.sort.reverse, hours end - + def test_index_sort_by_total_estimated_hours get :index, :sort => 'total_estimated_hours:desc' assert_response :success @@ -1141,7 +1141,7 @@ class IssuesControllerTest < ActionController::TestCase def test_index_should_not_include_new_issue_tab_for_project_without_trackers with_settings :new_item_menu_tab => '1' do Project.find(1).trackers.clear - + @request.session[:user_id] = 2 get :index, :project_id => 1 assert_select '#main-menu a.new-issue', 0 @@ -1153,7 +1153,7 @@ class IssuesControllerTest < ActionController::TestCase role = Role.find(1) role.remove_permission! :add_issues role.add_permission! :copy_issues - + @request.session[:user_id] = 2 get :index, :project_id => 1 assert_select '#main-menu a.new-issue', 0 @@ -1439,7 +1439,7 @@ class IssuesControllerTest < ActionController::TestCase def test_show_should_display_prev_next_links_with_query_and_sort_on_association @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} - + %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| @request.session['issues_index_sort'] = assoc_sort @@ -1684,7 +1684,7 @@ class IssuesControllerTest < ActionController::TestCase end def test_show_export_to_pdf - issue = Issue.find(3) + issue = Issue.find(3) assert issue.relations.select{|r| r.other_issue(issue).visible?}.present? get :show, :id => 3, :format => 'pdf' assert_response :success @@ -2152,7 +2152,7 @@ class IssuesControllerTest < ActionController::TestCase get :new, :project_id => 'invalid' assert_response 404 end - + def test_new_with_parent_id_should_only_propose_valid_trackers @request.session[:user_id] = 2 t = Tracker.find(3) @@ -2704,7 +2704,7 @@ class IssuesControllerTest < ActionController::TestCase :custom_field_values => {'2' => 'Value for field 2'}} end assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id - + assert_equal 1, ActionMailer::Base.deliveries.size end end @@ -2874,7 +2874,7 @@ class IssuesControllerTest < ActionController::TestCase get :new, :project_id => 1 assert_response :success assert_template 'new' - + issue = assigns(:issue) assert_not_nil issue.default_status @@ -3297,7 +3297,7 @@ class IssuesControllerTest < ActionController::TestCase def test_get_edit_should_display_the_time_entry_form_with_log_time_permission @request.session[:user_id] = 2 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] - + get :edit, :id => 1 assert_select 'input[name=?]', 'time_entry[hours]' end @@ -3305,7 +3305,7 @@ class IssuesControllerTest < ActionController::TestCase def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission @request.session[:user_id] = 2 Role.find_by_name('Manager').remove_permission! :log_time - + get :edit, :id => 1 assert_select 'input[name=?]', 'time_entry[hours]', 0 end @@ -3926,7 +3926,7 @@ class IssuesControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id end - + def test_put_update_should_redirect_with_previous_and_next_issue_ids_params @request.session[:user_id] = 2 @@ -3981,17 +3981,17 @@ class IssuesControllerTest < ActionController::TestCase assert_select 'select[name=?]', 'issue[project_id]' assert_select 'input[name=?]', 'issue[parent_issue_id]' - + # Project specific custom field, date type field = CustomField.find(9) assert !field.is_for_all? assert_equal 'date', field.field_format assert_select 'input[name=?]', 'issue[custom_field_values][9]' - + # System wide custom field assert CustomField.find(1).is_for_all? assert_select 'select[name=?]', 'issue[custom_field_values][1]' - + # Be sure we don't display inactive IssuePriorities assert ! IssuePriority.find(15).active? assert_select 'select[name=?]', 'issue[priority_id]' do @@ -4155,7 +4155,7 @@ class IssuesControllerTest < ActionController::TestCase :issue => {:priority_id => '', :assigned_to_id => group.id, :custom_field_values => {'2' => ''}} - + assert_response 302 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to} end @@ -4213,6 +4213,20 @@ class IssuesControllerTest < ActionController::TestCase end end + def test_bulk_update_with_author_change + @request.session[:user_id] = 2 + Issue.where(id: [1, 2]).each {|i| i.update_attributes(assigned_to_id: 8)} + post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2', assigned_to_id: 'author'} + Issue.where(id: [1, 2]).each {|i| assert_equal 2, i.assigned_to_id} + end + + def test_bulk_update_with_different_author + @request.session[:user_id] = 2 + ids = Project.find(2).issues.map(&:id) + post :bulk_update, :ids => ids, :issue => {:project_id => '2', assigned_to_id: 'author'} + Project.find(2).issues.each {|i| assert_equal i.author_id, i.assigned_to_id} + end + def test_bulk_update_project @request.session[:user_id] = 2 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} @@ -4468,7 +4482,7 @@ class IssuesControllerTest < ActionController::TestCase assert_select 'option[value="2"]' end end - + def test_bulk_copy_to_another_project @request.session[:user_id] = 2 assert_difference 'Issue.count', 2 do @@ -4521,7 +4535,7 @@ class IssuesControllerTest < ActionController::TestCase :assigned_to_id => 3) ] assert_difference 'Issue.count', issues.size do - post :bulk_update, :ids => issues.map(&:id), :copy => '1', + post :bulk_update, :ids => issues.map(&:id), :copy => '1', :issue => { :project_id => '', :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => '' @@ -4553,7 +4567,7 @@ class IssuesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 assert_difference 'Issue.count', 2 do assert_no_difference 'Project.find(1).issues.count' do - post :bulk_update, :ids => [1, 2], :copy => '1', + post :bulk_update, :ids => [1, 2], :copy => '1', :issue => { :project_id => '2', :tracker_id => '', :assigned_to_id => '2', :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'