mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-25 08:37:14 +00:00
Limit total_estimated_hours to visible issues (#31778).
Patch by Gregor Schmidt. git-svn-id: http://svn.redmine.org/redmine/trunk@18356 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
be7d39a4d3
commit
8a9123de04
@ -1077,7 +1077,7 @@ class Issue < ActiveRecord::Base
|
|||||||
if leaf?
|
if leaf?
|
||||||
estimated_hours
|
estimated_hours
|
||||||
else
|
else
|
||||||
@total_estimated_hours ||= self_and_descendants.sum(:estimated_hours)
|
@total_estimated_hours ||= self_and_descendants.visible.sum(:estimated_hours)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -40,8 +40,8 @@ class IssueQuery < Query
|
|||||||
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
||||||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours", :totalable => true),
|
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours", :totalable => true),
|
||||||
QueryColumn.new(:total_estimated_hours,
|
QueryColumn.new(:total_estimated_hours,
|
||||||
:sortable => "COALESCE((SELECT SUM(estimated_hours) FROM #{Issue.table_name} subtasks" +
|
:sortable => -> { "COALESCE((SELECT SUM(estimated_hours) FROM #{Issue.table_name} subtasks" +
|
||||||
" WHERE subtasks.root_id = #{Issue.table_name}.root_id AND subtasks.lft >= #{Issue.table_name}.lft AND subtasks.rgt <= #{Issue.table_name}.rgt), 0)",
|
" WHERE #{Issue.visible_condition(User.current).gsub(/\bissues\b/, 'subtasks')} AND subtasks.root_id = #{Issue.table_name}.root_id AND subtasks.lft >= #{Issue.table_name}.lft AND subtasks.rgt <= #{Issue.table_name}.rgt), 0)" },
|
||||||
:default_order => 'desc'),
|
:default_order => 'desc'),
|
||||||
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
|
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
|
||||||
TimestampQueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc', :groupable => true),
|
TimestampQueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc', :groupable => true),
|
||||||
|
|||||||
@ -338,7 +338,7 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parent_total_estimated_hours_should_be_sum_of_descendants
|
def test_parent_total_estimated_hours_should_be_sum_of_visible_descendants
|
||||||
parent = Issue.generate!
|
parent = Issue.generate!
|
||||||
parent.generate_child!(:estimated_hours => nil)
|
parent.generate_child!(:estimated_hours => nil)
|
||||||
assert_equal 0, parent.reload.total_estimated_hours
|
assert_equal 0, parent.reload.total_estimated_hours
|
||||||
@ -346,6 +346,9 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
|
|||||||
assert_equal 5, parent.reload.total_estimated_hours
|
assert_equal 5, parent.reload.total_estimated_hours
|
||||||
parent.generate_child!(:estimated_hours => 7)
|
parent.generate_child!(:estimated_hours => 7)
|
||||||
assert_equal 12, parent.reload.total_estimated_hours
|
assert_equal 12, parent.reload.total_estimated_hours
|
||||||
|
|
||||||
|
parent.generate_child!(:estimated_hours => 9, :is_private => true)
|
||||||
|
assert_equal 12, parent.reload.total_estimated_hours
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_issue_with_closed_parent_should_not_validate
|
def test_open_issue_with_closed_parent_should_not_validate
|
||||||
|
|||||||
@ -1624,6 +1624,39 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
assert_equal values.sort, values
|
assert_equal values.sort, values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sort_by_total_for_estimated_hours
|
||||||
|
# Prepare issues
|
||||||
|
parent = issues(:issues_001)
|
||||||
|
child = issues(:issues_002)
|
||||||
|
private_child = issues(:issues_003)
|
||||||
|
other = issues(:issues_007)
|
||||||
|
|
||||||
|
User.current = users(:users_001)
|
||||||
|
|
||||||
|
parent.safe_attributes = {:estimated_hours => 1}
|
||||||
|
child.safe_attributes = {:estimated_hours => 2, :parent_issue_id => 1}
|
||||||
|
private_child.safe_attributes = {:estimated_hours => 4, :parent_issue_id => 1, :is_private => true}
|
||||||
|
other.safe_attributes = {:estimated_hours => 5}
|
||||||
|
|
||||||
|
[parent, child, private_child, other].each(&:save!)
|
||||||
|
|
||||||
|
|
||||||
|
q = IssueQuery.new(
|
||||||
|
:name => '_',
|
||||||
|
:filters => { 'issue_id' => {:operator => '=', :values => ['1,7']} },
|
||||||
|
:sort_criteria => [['total_estimated_hours', 'asc']]
|
||||||
|
)
|
||||||
|
|
||||||
|
# With private_child, `parent' is "bigger" than `other'
|
||||||
|
ids = q.issue_ids
|
||||||
|
assert_equal [7, 1], ids, "Private issue was not used to calculate sort order"
|
||||||
|
|
||||||
|
# Without the invisible private_child, `other' is "bigger" than `parent'
|
||||||
|
User.current = User.anonymous
|
||||||
|
ids = q.issue_ids
|
||||||
|
assert_equal [1, 7], ids, "Private issue was used to calculate sort order"
|
||||||
|
end
|
||||||
|
|
||||||
def test_set_totalable_names
|
def test_set_totalable_names
|
||||||
q = IssueQuery.new
|
q = IssueQuery.new
|
||||||
q.totalable_names = ['estimated_hours', :spent_hours, '']
|
q.totalable_names = ['estimated_hours', :spent_hours, '']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user