]> source.dussan.org Git - redmine.git/commitdiff
Add total estimated hours, spent hours, total spent hours for issues to issue list...
authorGo MAEDA <maeda@farend.jp>
Sun, 27 Jun 2021 07:18:58 +0000 (07:18 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 27 Jun 2021 07:18:58 +0000 (07:18 +0000)
Patch by Felix Schäfer and Takenori TAKAKI.

git-svn-id: http://svn.redmine.org/redmine/trunk@21051 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/views/issues/index.api.rsb
test/integration/api_test/issues_test.rb

index 0278b30888abb530eaeb148063d4bb274dde4120..62124db427b80d7b4982c6f4ce90a61ebef44070 100644 (file)
@@ -60,6 +60,10 @@ class IssuesController < ApplicationController
           @issue_count = @query.issue_count
           @issues = @query.issues(:offset => @offset, :limit => @limit)
           Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
+          if User.current.allowed_to?(:view_time_entries, nil, :global => true)
+            Issue.load_visible_spent_hours(@issues)
+            Issue.load_visible_total_spent_hours(@issues)
+          end
         end
         format.atom do
           @issues = @query.issues(:limit => Setting.feeds_limit.to_i)
index 4bba32549f5d40ae2fb444f884944f9ffc1a8e46..da60ea5c677cd05e3c3352d9df0c98ab060d4ecd 100644 (file)
@@ -19,6 +19,11 @@ api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l
       api.done_ratio  issue.done_ratio
       api.is_private  issue.is_private
       api.estimated_hours issue.estimated_hours
+      api.total_estimated_hours issue.total_estimated_hours
+      if User.current.allowed_to?(:view_time_entries, issue.project)
+        api.spent_hours(issue.spent_hours)
+        api.total_spent_hours(issue.total_spent_hours)
+      end
 
       render_api_custom_values issue.visible_custom_field_values, api
 
index 7a57d39feb5114c379d8fdf0c612fb73b855ecec..4435df6fd8ff54da23ab1a420df0e13fff8ebf46 100644 (file)
@@ -141,6 +141,34 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     assert_select 'issues>issue>is_private', :text => 'false'
   end
 
+  def test_index_should_include_spent_hours
+    Issue.delete_all
+    parent = Issue.generate!(:estimated_hours => 2.0)
+    child = Issue.generate!(:parent_id => parent.id, :estimated_hours => 3.0)
+    TimeEntry.create!(:project => parent.project, :issue => parent, :user => parent.author, :spent_on => parent.author.today,
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+    TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+
+    get '/issues.xml'
+
+    assert_select 'issues issue', 2
+    assert_select 'issues>issue>spent_hours', '2.5'
+    assert_select 'issues>issue>total_spent_hours', '5.0'
+  end
+
+  def test_index_should_not_include_spent_hours
+    r = Role.anonymous
+    r.permissions.delete(:view_time_entries)
+    r.permissions_will_change!
+    r.save
+
+    get '/issues.xml'
+
+    assert_select 'issues>issue>spent_hours', false
+    assert_select 'issues>issue>total_spent_hours', false
+  end
+
   def test_index_should_allow_timestamp_filtering
     Issue.delete_all
     Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z"))