[Bps-public-commit] rt-extension-rest2 branch, master, updated. 1.09-9-g9c86422

Jim Brandt jbrandt at bestpractical.com
Wed Dec 23 14:28:46 EST 2020


The branch, master has been updated
       via  9c864221c3b2f8a40488523d054f85f636a90a45 (commit)
       via  9c321437e7023d6e0bf63768bbd52e83f0a4f783 (commit)
       via  85d138bb88defa114924efb42af76ff585abba83 (commit)
       via  3251bfce1a9c3b90bd87694421c2765a2e0ac7ad (commit)
      from  f4d4e84a16904adca2afd645fcd801c732853cf7 (commit)

Summary of changes:
 lib/RT/Extension/REST2.pm                  |  6 +++
 lib/RT/Extension/REST2/Resource/Message.pm |  6 +++
 xt/tickets.t                               | 84 ++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+)

- Log -----------------------------------------------------------------
commit 3251bfce1a9c3b90bd87694421c2765a2e0ac7ad
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Mon Dec 7 14:08:56 2020 -0500

    Add ability to update status at the same time as posting a comment or reply
    
    To change the status, post the reply or comment using application/json
    data and include a "Status" element with the new desired status.

diff --git a/lib/RT/Extension/REST2/Resource/Message.pm b/lib/RT/Extension/REST2/Resource/Message.pm
index 9b05b00..f15d996 100644
--- a/lib/RT/Extension/REST2/Resource/Message.pm
+++ b/lib/RT/Extension/REST2/Resource/Message.pm
@@ -152,6 +152,12 @@ sub add_message {
     push @results, update_custom_fields($self->record, $args{CustomFields});
     push @results, $self->_update_txn_custom_fields( $TransObj, $args{TxnCustomFields} || $args{TransactionCustomFields} );
 
+    # Set ticket status if we were passed a "Status":"foo" argument
+    if ($args{Status}) {
+        my ($ok, $msg) = $self->record->SetStatus($args{Status});
+        push(@results, $msg);
+    }
+
     $self->created_transaction($TransObj);
     $self->response->body(JSON::to_json(\@results, { pretty => 1 }));
 

commit 85d138bb88defa114924efb42af76ff585abba83
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Tue Dec 15 08:32:17 2020 -0500

    Document the "Status" member for posting a comment or reply to a ticket.

diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index ec7faa3..e11acfb 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -269,6 +269,12 @@ below).
 
 The time, in minutes, you've taken to work on your response/comment, optional.
 
+=item C<Status>
+
+The new status (for example, "open", "rejected", etc.) to set the
+ticket to.  The Status value must be a valid status based on the
+lifecycle of the ticket's current queue.
+
 =back
 
 =head3 Add Attachments

commit 9c321437e7023d6e0bf63768bbd52e83f0a4f783
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Mon Dec 7 14:13:20 2020 -0500

    Add unit test for changing ticket status on comment / reply.

diff --git a/xt/tickets.t b/xt/tickets.t
index 3324f69..6c651d0 100644
--- a/xt/tickets.t
+++ b/xt/tickets.t
@@ -467,6 +467,90 @@ my ($ticket_url, $ticket_id);
     is($content->{ContentType}, 'text/html');
 }
 
+# Ticket Reply, changing status
+{
+    my $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    my $content = $mech->json_response;
+
+    my ($hypermedia) = grep { $_->{ref} eq 'correspond' } @{ $content->{_hyperlinks} };
+    ok($hypermedia, 'got correspond hypermedia');
+    like($hypermedia->{_url}, qr[$rest_base_path/ticket/$ticket_id/correspond$]);
+
+    $res = $mech->post($mech->url_for_hypermedia('correspond'),
+        'Authorization' => $auth,
+        'Content-Type' => 'application/json',
+        'Content' => '{"Subject":"I am a-changing the status!","ContentType":"text/plain","Content":"Foo","Status":"rejected"}',
+    );
+    is($res->code, 201);
+
+    cmp_deeply($mech->json_response, [re(qr/Correspondence added|Message recorded/), "Status changed from 'open' to 'rejected'"]);
+
+    like($res->header('Location'), qr{$rest_base_path/transaction/\d+$});
+    $res = $mech->get($res->header('Location'),
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    $content = $mech->json_response;
+    is($content->{Type}, 'Correspond');
+    is($content->{TimeTaken}, 0);
+    is($content->{Object}{type}, 'ticket');
+    is($content->{Object}{id}, $ticket_id);
+
+    $res = $mech->get($mech->url_for_hypermedia('attachment'),
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    $content = $mech->json_response;
+    is($content->{Content}, 'Foo'),
+    is($content->{ContentType}, 'text/plain');
+
+    # Check that ticket status was updated
+    $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    $content = $mech->json_response;
+    is($content->{Status}, 'rejected', "Ticket status really was changed");
+
+    # Try an invalid status
+    $res = $mech->post($mech->url_for_hypermedia('correspond'),
+        'Authorization' => $auth,
+        'Content-Type' => 'application/json',
+        'Content' => '{"Subject":"I am a-changing the status!","ContentType":"text/plain","Content":"Foo","Status":"bahaha-youre-so-funny"}',
+    );
+    is($res->code, 201);
+
+    cmp_deeply($mech->json_response, [re(qr/Correspondence added|Message recorded/), "Status 'bahaha-youre-so-funny' isn't a valid status for this ticket."]);
+
+    $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    $content = $mech->json_response;
+    is($content->{Status}, 'open', "Ticket status really was not changed to illegal value");
+
+    # Comment and change status
+    $res = $mech->post($mech->url_for_hypermedia('comment'),
+        'Authorization' => $auth,
+        'Content-Type' => 'application/json',
+        'Content' => '{"Subject":"I am a-changing the status in a comment!","ContentType":"text/plain","Content":"Foo","Status":"rejected"}',
+    );
+    is($res->code, 201);
+
+    cmp_deeply($mech->json_response, ['Comments added', "Status changed from 'open' to 'rejected'"]);
+
+    $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    $content = $mech->json_response;
+    is($content->{Status}, 'rejected', "Ticket status really was changed during a comment");
+
+}
+
 # Ticket Sorted Search
 {
     my $ticket2 = RT::Ticket->new($RT::SystemUser);

commit 9c864221c3b2f8a40488523d054f85f636a90a45
Merge: f4d4e84 9c32143
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Dec 23 13:59:59 2020 -0500

    Merge branch 'allow-update-of-ticket-status-on-correspond'


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


More information about the Bps-public-commit mailing list