Project

General

Profile

Defect #28110 » do_not_allow_nullify_time_entries_when_issue_is_required_for_time_entries.patch

Marius BĂLTEANU, 2018-01-31 22:56

View differences:

app/controllers/issues_controller.rb
367 367
      when 'destroy'
368 368
        # nothing to do
369 369
      when 'nullify'
370
        if Setting.timelog_required_fields.include?('issue_id')
371
          flash.now[:error] = l(:field_issue) + " " + ::I18n.t('activerecord.errors.messages.blank')
372
          return
373
        else
370 374
          time_entries.update_all(:issue_id => nil)
375
        end
371 376
      when 'reassign'
372 377
        reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id])
373 378
        if reassign_to.nil?
app/views/issues/destroy.html.erb
6 6
<p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
7 7
<p>
8 8
<label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
9
<% unless Setting.timelog_required_fields.include?('issue_id') %>
9 10
  <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
11
<% end %>
10 12
<% if @project %>
11 13
<label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("#reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
12 14
<%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("#todo_reassign").attr("checked", true);' %>
test/functional/issues_controller_test.rb
6234 6234
  def test_destroy_issues_with_time_entries_should_show_the_reassign_form
6235 6235
    @request.session[:user_id] = 2
6236 6236

  
6237
    with_settings :timelog_required_fields => [] do
6238
      assert_no_difference 'Issue.count' do
6239
        delete :destroy, :params => {
6240
            :ids => [1, 3]
6241
          }
6242
      end
6243
    end
6244
    assert_response :success
6245

  
6246
    assert_select 'form' do
6247
      assert_select 'input[name=_method][value=delete]'
6248
      assert_select 'input[name=todo][value=destroy]'
6249
      assert_select 'input[name=todo][value=nullify]'
6250
      assert_select 'input[name=todo][value=reassign]'
6251
    end
6252
  end
6253

  
6254
  def test_destroy_issues_with_time_entries_should_not_show_the_nullify_option_when_issue_is_required_for_time_entries
6255
    with_settings :timelog_required_fields => ['issue_id'] do
6256
      @request.session[:user_id] = 2
6257

  
6237 6258
      assert_no_difference 'Issue.count' do
6238 6259
        delete :destroy, :params => {
6239 6260
            :ids => [1, 3]
......
6243 6264

  
6244 6265
      assert_select 'form' do
6245 6266
        assert_select 'input[name=_method][value=delete]'
6267
        assert_select 'input[name=todo][value=destroy]'
6268
        assert_select 'input[name=todo][value=nullify]', 0
6269
        assert_select 'input[name=todo][value=reassign]'
6270
      end
6246 6271
    end
6247 6272
  end
6248 6273

  
......
6281 6306
  def test_destroy_issues_and_assign_time_entries_to_project
6282 6307
    @request.session[:user_id] = 2
6283 6308

  
6309
    with_settings :timelog_required_fields => [] do
6284 6310
      assert_difference 'Issue.count', -2 do
6285 6311
        assert_no_difference 'TimeEntry.count' do
6286 6312
          delete :destroy, :params => {
......
6289 6315
            }
6290 6316
        end
6291 6317
      end
6318
    end
6292 6319
    assert_redirected_to :action => 'index', :project_id => 'ecookbook'
6293 6320
    assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
6294 6321
    assert_nil TimeEntry.find(1).issue_id
......
6367 6394
    assert_select '#flash_error', :text => I18n.t(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
6368 6395
  end
6369 6396

  
6397
  def test_destroy_issues_and_nullify_time_entries_should_fail_when_issue_is_required_for_time_entries
6398
    @request.session[:user_id] = 2
6399

  
6400
    with_settings :timelog_required_fields => ['issue_id'] do
6401
      assert_no_difference 'Issue.count' do
6402
        assert_no_difference 'TimeEntry.count' do
6403
          delete :destroy, :params => {
6404
              :ids => [1, 3],
6405
              :todo => 'nullify'
6406
            }
6407
        end
6408
      end
6409
    end
6410
    assert_response :success
6411
    assert_select '#flash_error', :text => 'Issue cannot be blank'
6412
  end
6413

  
6370 6414
  def test_destroy_issues_from_different_projects
6371 6415
    @request.session[:user_id] = 2
6372 6416

  
(3-3/4)