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

Dianne Skoll dianne at bestpractical.com
Mon Dec 7 14:14:08 EST 2020


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

- Log -----------------------------------------------------------------
commit 04b7939a14fe5e8ccf29d256ee3879dcd0eb619b
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..448d452 100644
--- a/lib/RT/Extension/REST2/Resource/Message.pm
+++ b/lib/RT/Extension/REST2/Resource/Message.pm
@@ -153,6 +153,16 @@ sub add_message {
     push @results, $self->_update_txn_custom_fields( $TransObj, $args{TxnCustomFields} || $args{TransactionCustomFields} );
 
     $self->created_transaction($TransObj);
+
+    # Set ticket status if we were passed a "Status":"foo" argument
+    if ($args{Status}) {
+        my ($ok, $msg) = $self->record->SetStatus($args{Status});
+        if ($ok) {
+            push(@results, $msg || "Ticket status set to " . $args{Status});
+        } else {
+            push(@results, $msg || "Setting ticket status failed for unknown reason");
+        }
+    }
     $self->response->body(JSON::to_json(\@results, { pretty => 1 }));
 
     return 1;

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

    Document the "Status" member when you post a reply or comment on a ticket.

diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index 30be01b..41d08ad 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -269,6 +269,13 @@ 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.  If you do not supply Status, then the status may be updated according
+to the normal transaction rules (for example, a reply may change a ticket
+status from "resolved" to "open", depending on how your RT is set up.)
+
 =back
 
 =head3 Add Attachments

commit ec39e82910043e46c4155efcb7dbc727cfc9534f
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..0cc633b 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 during a comment");
+
+}
+
 # Ticket Sorted Search
 {
     my $ticket2 = RT::Ticket->new($RT::SystemUser);

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


More information about the Bps-public-commit mailing list