[Rt-commit] rt branch 5.0/rest2-totaltimeworked created. rt-5.0.5-149-g018ae521a8

BPS Git Server git at git.bestpractical.com
Mon Jan 29 18:58:28 UTC 2024


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/rest2-totaltimeworked has been created
        at  018ae521a861fd5475edb223bea8fac679988db1 (commit)

- Log -----------------------------------------------------------------
commit 018ae521a861fd5475edb223bea8fac679988db1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Jan 29 13:44:37 2024 -0500

    Add TotalTimeWorked to REST2 ticket response data
    
    There is some overhead to calculate this value, especially if
    there are many linked children tickets, so include it only if
    DisplayTotalTimeWorked is enabled in the RT configuration indicating
    they are using this field.

diff --git a/lib/RT/REST2/Resource/Ticket.pm b/lib/RT/REST2/Resource/Ticket.pm
index 64b4d67647..f879e1136f 100644
--- a/lib/RT/REST2/Resource/Ticket.pm
+++ b/lib/RT/REST2/Resource/Ticket.pm
@@ -55,7 +55,8 @@ use namespace::autoclean;
 
 extends 'RT::REST2::Resource::Record';
 with (
-    'RT::REST2::Resource::Record::Readable',
+    'RT::REST2::Resource::Record::Readable'
+        => { -alias => { serialize => '_default_serialize' } },
     'RT::REST2::Resource::Record::Hypermedia'
         => { -alias => { hypermedia_links => '_default_hypermedia_links' } },
     'RT::REST2::Resource::Record::Deletable',
@@ -239,6 +240,16 @@ sub validate_input {
     return (1, "Validation passed");
 }
 
+sub serialize {
+    my $self   = shift;
+    my $data = $self->_default_serialize(@_);
+
+    if ( RT->Config->Get('DisplayTotalTimeWorked') ) {
+        $data->{'TotalTimeWorked'} = $self->record->TotalTimeWorked();
+    }
+
+    return $data;
+}
 
 __PACKAGE__->meta->make_immutable;
 
diff --git a/t/rest2/tickets.t b/t/rest2/tickets.t
index fd563c82e7..b2988b1db3 100644
--- a/t/rest2/tickets.t
+++ b/t/rest2/tickets.t
@@ -8,6 +8,9 @@ use Encode qw(decode encode);
 
 # Test using integer priorities
 RT->Config->Set(EnablePriorityAsString => 0);
+
+# Include TotalTimeWorked in response data
+RT->Config->Set(DisplayTotalTimeWorked => 1);
 my $mech = RT::Test::REST2->mech;
 
 my $auth = RT::Test::REST2->authorization_header;
@@ -42,6 +45,7 @@ my ($ticket_url, $ticket_id);
         Subject => 'Ticket creation using REST',
         Queue   => 'General',
         Content => 'Testing ticket creation using REST API.',
+        TimeWorked => 5,
     };
 
     # Rights Test - No CreateTicket
@@ -85,9 +89,11 @@ my ($ticket_url, $ticket_id);
     is($content->{Type}, 'ticket');
     is($content->{Status}, 'new');
     is($content->{Subject}, 'Ticket creation using REST');
+    is($content->{TimeWorked}, 5);
+    is($content->{TotalTimeWorked}, 5);
 
-    ok(exists $content->{$_}) for qw(AdminCc TimeEstimated Started Cc
-                                     LastUpdated TimeWorked Resolved
+    ok(exists $content->{$_}, "Found $_") for qw(AdminCc TimeEstimated Started Cc
+                                     LastUpdated Resolved
                                      Created Due Priority EffectiveId);
 
     my $links = $content->{_hyperlinks};

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list