]> source.dussan.org Git - redmine.git/commitdiff
Merged r17199 from trunk to 3.4-stable (#28110).
authorGo MAEDA <maeda@farend.jp>
Sun, 18 Feb 2018 04:33:30 +0000 (04:33 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 18 Feb 2018 04:33:30 +0000 (04:33 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17200 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 23d3992f1e99a1dd64e5b571336826e387b4477d..e1a3d860c08ac2acc1149ff017a49725fba24ca0 100644 (file)
@@ -367,7 +367,12 @@ class IssuesController < ApplicationController
       when 'destroy'
         # nothing to do
       when 'nullify'
+        if Setting.timelog_required_fields.include?('issue_id')
+          flash.now[:error] = l(:field_issue) + " " + ::I18n.t('activerecord.errors.messages.blank')
+          return
+        else
         time_entries.update_all(:issue_id => nil)
+        end
       when 'reassign'
         reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id])
         if reassign_to.nil?
index 9b08c3698457aec2f9f6caf37f3477fa20bf7995..61b841a62dd6b2ebff38f83a97f7873e026b2986 100644 (file)
@@ -6,7 +6,9 @@
 <p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
 <p>
 <label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
+<% unless Setting.timelog_required_fields.include?('issue_id') %>
 <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
+<% end %>
 <% if @project %>
 <label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("#reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
 <%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("#todo_reassign").attr("checked", true);' %>
index 40055cb200127643fd66836b99088f89b1277625..4adf06b31c4365610cf9427893a2ce05ff15453e 100644 (file)
@@ -6212,6 +6212,27 @@ class IssuesControllerTest < Redmine::ControllerTest
   def test_destroy_issues_with_time_entries_should_show_the_reassign_form
     @request.session[:user_id] = 2
 
+    with_settings :timelog_required_fields => [] do
+      assert_no_difference 'Issue.count' do
+        delete :destroy, :params => {
+            :ids => [1, 3]
+          }
+      end
+    end
+    assert_response :success
+
+    assert_select 'form' do
+      assert_select 'input[name=_method][value=delete]'
+      assert_select 'input[name=todo][value=destroy]'
+      assert_select 'input[name=todo][value=nullify]'
+      assert_select 'input[name=todo][value=reassign]'
+    end
+  end
+
+  def test_destroy_issues_with_time_entries_should_not_show_the_nullify_option_when_issue_is_required_for_time_entries
+    with_settings :timelog_required_fields => ['issue_id'] do
+      @request.session[:user_id] = 2
+
     assert_no_difference 'Issue.count' do
       delete :destroy, :params => {
           :ids => [1, 3]
@@ -6221,6 +6242,10 @@ class IssuesControllerTest < Redmine::ControllerTest
 
     assert_select 'form' do
       assert_select 'input[name=_method][value=delete]'
+        assert_select 'input[name=todo][value=destroy]'
+        assert_select 'input[name=todo][value=nullify]', 0
+        assert_select 'input[name=todo][value=reassign]'
+      end
     end
   end
 
@@ -6259,6 +6284,7 @@ class IssuesControllerTest < Redmine::ControllerTest
   def test_destroy_issues_and_assign_time_entries_to_project
     @request.session[:user_id] = 2
 
+    with_settings :timelog_required_fields => [] do
     assert_difference 'Issue.count', -2 do
       assert_no_difference 'TimeEntry.count' do
         delete :destroy, :params => {
@@ -6267,6 +6293,7 @@ class IssuesControllerTest < Redmine::ControllerTest
           }
       end
     end
+    end
     assert_redirected_to :action => 'index', :project_id => 'ecookbook'
     assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
     assert_nil TimeEntry.find(1).issue_id
@@ -6345,6 +6372,23 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_select '#flash_error', :text => I18n.t(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
   end
 
+  def test_destroy_issues_and_nullify_time_entries_should_fail_when_issue_is_required_for_time_entries
+    @request.session[:user_id] = 2
+
+    with_settings :timelog_required_fields => ['issue_id'] do
+      assert_no_difference 'Issue.count' do
+        assert_no_difference 'TimeEntry.count' do
+          delete :destroy, :params => {
+              :ids => [1, 3],
+              :todo => 'nullify'
+            }
+        end
+      end
+    end
+    assert_response :success
+    assert_select '#flash_error', :text => 'Issue cannot be blank'
+  end
+
   def test_destroy_issues_from_different_projects
     @request.session[:user_id] = 2