Project

General

Profile

Defect #33415 » 0001-Fix-33415-by-re-implementing-31589-simplified.patch

Replaces 0001-Fix-33415-by-re-implementing-31589.patch & 0001-POC-fix-for-33415.patch - Mischa The Evil, 2020-05-19 06:10

View differences:

app/models/issue.rb
971 971
  end
972 972

  
973 973
  # Returns true if this issue can be closed and if not, returns false and populates the reason
974
  # This does not take the workflow transitions into account
974 975
  def closable?
975
    if descendants.open.any?
976
    open_sub_tasks = true if descendants.open.any?
977
    open_blocking_issues = true if blocked?
978

  
979
    if open_sub_tasks && open_blocking_issues
980
      @transition_warning = l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue)
981
      return false
982
    elsif open_sub_tasks && !open_blocking_issues
976 983
      @transition_warning = l(:notice_issue_not_closable_by_open_tasks)
977 984
      return false
978
    end
979
    if blocked?
985
    elsif open_blocking_issues && !open_sub_tasks
980 986
      @transition_warning = l(:notice_issue_not_closable_by_blocking_issue)
981 987
      return false
988
    else
989
      return true
982 990
    end
983
    return true
984 991
  end
985 992

  
986
  # Returns true if this issue can be reopen and if not, returns false and populates the reason
993
  # Returns true if this issue can be reopened and if not, returns false and populates the reason
994
  # This does not take the workflow transitions into account
987 995
  def reopenable?
988
    if ancestors.open(false).any?
996
    closed_parent_issue = true if ancestors.open(false).any?
997

  
998
    if closed_parent_issue
989 999
      @transition_warning = l(:notice_issue_not_reopenable_by_closed_parent_issue)
990 1000
      return false
1001
    else
1002
      return true
991 1003
    end
992
    return true
993 1004
  end
994 1005

  
995 1006
  # Returns the default status of the issue based on its tracker
config/locales/en.yml
193 193
  notice_issue_not_closable_by_open_tasks: "This issue cannot be closed because it has at least one open subtask."
194 194
  notice_issue_not_closable_by_blocking_issue: "This issue cannot be closed because it is blocked by at least one open issue."
195 195
  notice_issue_not_reopenable_by_closed_parent_issue: "This issue cannot be reopened because its parent issue is closed."
196
  notice_issue_not_closable_by_open_tasks_and_blocking_issue: "This issue cannot be closed because it has at least one open subtask and it is blocked by at least one open issue."
196 197

  
197 198
  error_can_t_load_default_data: "Default configuration could not be loaded: %{value}"
198 199
  error_scm_not_found: "The entry or revision was not found in the repository."
test/functional/issues_controller_test.rb
5439 5439
  end
5440 5440

  
5441 5441
  def test_get_edit_for_issue_with_transition_warning_should_show_the_warning
5442
    # Transition warning message for open issue blocked by another open issue
5442 5443
    @request.session[:user_id] = 2
5444
    get(
5445
      :edit,
5446
      :params => {
5447
        :id => 9,
5448
      }
5449
    )
5450
    assert_response :success
5451
    reason = l(:notice_issue_not_closable_by_blocking_issue)
5452
    assert_select 'span.icon-warning[title=?]', reason, :text => reason
5453

  
5454
    # Transition warning message for open issue with open subtask and blocked by another open issue
5455
    subissue1 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :parent_issue_id => 9, :subject => 'Open Child Issue')
5443 5456

  
5444 5457
    get(
5445 5458
      :edit,
......
5447 5460
        :id => 9,
5448 5461
      }
5449 5462
    )
5463
    assert_response :success
5464
    reason = l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue)
5465
    assert_select 'span.icon-warning[title=?]', reason, :text => reason
5450 5466

  
5467
    # Transition warning message for open issue with open subtask
5468
    subissue2 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :parent_issue_id => subissue1.id, :subject => 'Open Child Issue')
5469
    
5470
    get(
5471
      :edit,
5472
      :params => {
5473
        :id => subissue1.id,
5474
      }
5475
    )
5451 5476
    assert_response :success
5452
    reason = l(:notice_issue_not_closable_by_blocking_issue)
5477
    reason = l(:notice_issue_not_closable_by_open_tasks)
5478
    assert_select 'span.icon-warning[title=?]', reason, :text => reason
5479

  
5480
    # Transition warning message for closed subtask with closed parent issue
5481
    subissue1.update_attribute :status_id, 5
5482
    assert subissue1.closed?
5483
    subissue3 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :status_id => 5, :parent_issue_id => subissue1.id, :subject => 'Closed Child Issue')
5484
    assert subissue3.closed?
5485

  
5486
    get(
5487
      :edit,
5488
      :params => {
5489
        :id => subissue3.id,
5490
      }
5491
    )
5492
    assert_response :success
5493
    reason = l(:notice_issue_not_reopenable_by_closed_parent_issue)
5453 5494
    assert_select 'span.icon-warning[title=?]', reason, :text => reason
5454 5495
  end
5455 5496

  
test/unit/issue_test.rb
2105 2105

  
2106 2106
    allowed_statuses = parent.reload.new_statuses_allowed_to(users(:users_002))
2107 2107

  
2108
    assert !parent.closable?
2109
    assert_equal l(:notice_issue_not_closable_by_open_tasks), parent.transition_warning
2110

  
2111 2108
    assert allowed_statuses.any?
2112 2109
    assert_equal [], allowed_statuses.select(&:is_closed?)
2113 2110
  end
......
2118 2115

  
2119 2116
    allowed_statuses = parent.reload.new_statuses_allowed_to(users(:users_002))
2120 2117

  
2121
    assert parent.closable?
2122
    assert_nil parent.transition_warning
2123 2118
    assert allowed_statuses.any?
2124 2119
    assert allowed_statuses.select(&:is_closed?).any?
2125 2120
  end
......
3298 3293
    assert issue10.closable?
3299 3294
    assert_nil issue10.transition_warning
3300 3295

  
3301
    # Issue blocked by another issue
3296
    # Issue blocked by another open issue
3302 3297
    issue9 = Issue.find(9)
3303 3298
    assert !issue9.closable?
3304 3299
    assert_equal l(:notice_issue_not_closable_by_blocking_issue), issue9.transition_warning
3300

  
3301
    # Issue with an open subtask and blocked by another open issue
3302
    child = issue9.generate_child!(:status_id => 1)
3303
    issue9.reload
3304
    assert !issue9.closable?
3305
    assert_equal l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue), issue9.transition_warning
3306

  
3307
    # Issue with an open subtask
3308
    assert child.closable?
3309
    open_parent_issue = child.generate_child!
3310
    child.reload
3311
    assert !child.closable?
3312
    assert_equal l(:notice_issue_not_closable_by_open_tasks), child.transition_warning
3313

  
3314
    # Closed issue should be closable without a transition warning message
3315
    closed_issue = Issue.generate!(:status_id => 5)
3316
    assert closed_issue.closable?
3317
    assert_nil closed_issue.transition_warning
3305 3318
  end
3306 3319

  
3307 3320
  def test_reopenable
......
3310 3323

  
3311 3324
    assert !child.reopenable?
3312 3325
    assert_equal l(:notice_issue_not_reopenable_by_closed_parent_issue), child.transition_warning
3326

  
3327
    # Open issue should be reopenable without a transition warning message
3328
    open_issue = Issue.generate!(:status_id => 1)
3329
    assert open_issue.reopenable?
3330
    assert_nil open_issue.transition_warning
3313 3331
  end
3314 3332
end
(3-3/3)