[Bps-public-commit] rt-extension-rest2 branch, allow-update-of-ticket-status-on-correspond, created. 1.09-8-g22e5f7a

Dianne Skoll dianne at bestpractical.com
Tue Dec 15 08:38:15 EST 2020


The branch, allow-update-of-ticket-status-on-correspond has been created
        at  22e5f7a038cd8df941ccd47fa6550c6a0ae8f103 (commit)

- Log -----------------------------------------------------------------
commit f71193245366e9ee130bef8d0becbae2bd2e7c5c
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..654cd8a 100644
--- a/lib/RT/Extension/REST2/Resource/Message.pm
+++ b/lib/RT/Extension/REST2/Resource/Message.pm
@@ -152,7 +152,14 @@ 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 }));
 
     return 1;

commit de4eee5d6fd62ec50afc454e6e8338296d752876
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 22e5f7a038cd8df941ccd47fa6550c6a0ae8f103
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);

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


More information about the Bps-public-commit mailing list