Skip to content

Commit

Permalink
Merge branch '5.0/rest2-totaltimeworked' into 5.0-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Jan 30, 2024
2 parents a9eae99 + 018ae52 commit 5afd223
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/RT/REST2/Resource/Ticket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 8 additions & 2 deletions t/rest2/tickets.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 5afd223

Please sign in to comment.