From 4da4c25ceb20cc805369c367e23c60e74adb9c00 Mon Sep 17 00:00:00 2001 From: Mischa The Evil Date: Mon, 11 May 2020 07:26:54 +0200 Subject: [PATCH] Fix #33415 by re-implementing #31589, simplified. Todo: * fix (superfluous) test code * fix (any) inconsistently named variables, labels and t9n's * fix (any) inconsistent code styles and markup --- app/models/issue.rb | 25 +++++++++---- config/locales/en.yml | 1 + test/functional/issues_controller_test.rb | 43 ++++++++++++++++++++++- test/unit/issue_test.rb | 30 ++++++++++++---- 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 487b1b552..9fb24fd1f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -971,25 +971,36 @@ class Issue < ActiveRecord::Base end # Returns true if this issue can be closed and if not, returns false and populates the reason + # This does not take the workflow transitions into account def closable? - if descendants.open.any? + open_sub_tasks = true if descendants.open.any? + open_blocking_issues = true if blocked? + + if open_sub_tasks && open_blocking_issues + @transition_warning = l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue) + return false + elsif open_sub_tasks && !open_blocking_issues @transition_warning = l(:notice_issue_not_closable_by_open_tasks) return false - end - if blocked? + elsif open_blocking_issues && !open_sub_tasks @transition_warning = l(:notice_issue_not_closable_by_blocking_issue) return false + else + return true end - return true end - # Returns true if this issue can be reopen and if not, returns false and populates the reason + # Returns true if this issue can be reopened and if not, returns false and populates the reason + # This does not take the workflow transitions into account def reopenable? - if ancestors.open(false).any? + closed_parent_issue = true if ancestors.open(false).any? + + if closed_parent_issue @transition_warning = l(:notice_issue_not_reopenable_by_closed_parent_issue) return false + else + return true end - return true end # Returns the default status of the issue based on its tracker diff --git a/config/locales/en.yml b/config/locales/en.yml index 89fd151c4..8e2b416fd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -193,6 +193,7 @@ en: notice_issue_not_closable_by_open_tasks: "This issue cannot be closed because it has at least one open subtask." notice_issue_not_closable_by_blocking_issue: "This issue cannot be closed because it is blocked by at least one open issue." notice_issue_not_reopenable_by_closed_parent_issue: "This issue cannot be reopened because its parent issue is closed." + 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." error_can_t_load_default_data: "Default configuration could not be loaded: %{value}" error_scm_not_found: "The entry or revision was not found in the repository." diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index a33605bf9..bf3f0eb86 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -5439,7 +5439,20 @@ class IssuesControllerTest < Redmine::ControllerTest end def test_get_edit_for_issue_with_transition_warning_should_show_the_warning + # Transition warning message for open issue blocked by another open issue @request.session[:user_id] = 2 + get( + :edit, + :params => { + :id => 9, + } + ) + assert_response :success + reason = l(:notice_issue_not_closable_by_blocking_issue) + assert_select 'span.icon-warning[title=?]', reason, :text => reason + + # Transition warning message for open issue with open subtask and blocked by another open issue + subissue1 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :parent_issue_id => 9, :subject => 'Open Child Issue') get( :edit, @@ -5447,9 +5460,37 @@ class IssuesControllerTest < Redmine::ControllerTest :id => 9, } ) + assert_response :success + reason = l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue) + assert_select 'span.icon-warning[title=?]', reason, :text => reason + # Transition warning message for open issue with open subtask + subissue2 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :parent_issue_id => subissue1.id, :subject => 'Open Child Issue') + + get( + :edit, + :params => { + :id => subissue1.id, + } + ) assert_response :success - reason = l(:notice_issue_not_closable_by_blocking_issue) + reason = l(:notice_issue_not_closable_by_open_tasks) + assert_select 'span.icon-warning[title=?]', reason, :text => reason + + # Transition warning message for closed subtask with closed parent issue + subissue1.update_attribute :status_id, 5 + assert subissue1.closed? + subissue3 = Issue.generate!(:project_id => 5, :author_id => 2, :tracker_id => 1, :status_id => 5, :parent_issue_id => subissue1.id, :subject => 'Closed Child Issue') + assert subissue3.closed? + + get( + :edit, + :params => { + :id => subissue3.id, + } + ) + assert_response :success + reason = l(:notice_issue_not_reopenable_by_closed_parent_issue) assert_select 'span.icon-warning[title=?]', reason, :text => reason end diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index d82f6e079..9ba409ce8 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2105,9 +2105,6 @@ class IssueTest < ActiveSupport::TestCase allowed_statuses = parent.reload.new_statuses_allowed_to(users(:users_002)) - assert !parent.closable? - assert_equal l(:notice_issue_not_closable_by_open_tasks), parent.transition_warning - assert allowed_statuses.any? assert_equal [], allowed_statuses.select(&:is_closed?) end @@ -2118,8 +2115,6 @@ class IssueTest < ActiveSupport::TestCase allowed_statuses = parent.reload.new_statuses_allowed_to(users(:users_002)) - assert parent.closable? - assert_nil parent.transition_warning assert allowed_statuses.any? assert allowed_statuses.select(&:is_closed?).any? end @@ -3298,10 +3293,28 @@ class IssueTest < ActiveSupport::TestCase assert issue10.closable? assert_nil issue10.transition_warning - # Issue blocked by another issue + # Issue blocked by another open issue issue9 = Issue.find(9) assert !issue9.closable? assert_equal l(:notice_issue_not_closable_by_blocking_issue), issue9.transition_warning + + # Issue with an open subtask and blocked by another open issue + child = issue9.generate_child!(:status_id => 1) + issue9.reload + assert !issue9.closable? + assert_equal l(:notice_issue_not_closable_by_open_tasks_and_blocking_issue), issue9.transition_warning + + # Issue with an open subtask + assert child.closable? + open_parent_issue = child.generate_child! + child.reload + assert !child.closable? + assert_equal l(:notice_issue_not_closable_by_open_tasks), child.transition_warning + + # Closed issue should be closable without a transition warning message + closed_issue = Issue.generate!(:status_id => 5) + assert closed_issue.closable? + assert_nil closed_issue.transition_warning end def test_reopenable @@ -3310,5 +3323,10 @@ class IssueTest < ActiveSupport::TestCase assert !child.reopenable? assert_equal l(:notice_issue_not_reopenable_by_closed_parent_issue), child.transition_warning + + # Open issue should be reopenable without a transition warning message + open_issue = Issue.generate!(:status_id => 1) + assert open_issue.reopenable? + assert_nil open_issue.transition_warning end end -- 2.26.0.windows.1