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
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
config/locales/en.yml
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."
test/functional/issues_controller_test.rb
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,
......
: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
test/unit/issue_test.rb
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
......
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
......
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
......
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
(3-3/3)