[Rt-commit] rt branch, 5.0/rest2-ticket-more-updates, created. rt-5.0.0-56-g32c5ecc11a

? sunnavy sunnavy at bestpractical.com
Fri Oct 16 15:44:04 EDT 2020


The branch, 5.0/rest2-ticket-more-updates has been created
        at  32c5ecc11a1891a838ef084e582605988c0d3032 (commit)

- Log -----------------------------------------------------------------
commit 274280cdc425fe1f2f87747de8e275fbcc32f7cf
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 17 02:08:38 2020 +0800

    Support to merge tickets in REST2

diff --git a/lib/RT/REST2.pm b/lib/RT/REST2.pm
index 1079f95cd6..9170b58345 100644
--- a/lib/RT/REST2.pm
+++ b/lib/RT/REST2.pm
@@ -499,6 +499,11 @@ Below are some examples using the endpoints above.
         -d '{ "Subject": "Update test", "CustomFields": {"Severity": "High"}}'
         'https://myrt.com/REST/2.0/ticket/6'
 
+    # Merge a ticket into another
+    curl -X PUT -H "Content-Type: application/json" -u 'root:password'
+        -d '{ "MergeInto": 3 }'
+        'https://myrt.com/REST/2.0/ticket/6'
+
     # Correspond a ticket
     curl -X POST -H "Content-Type: application/json" -u 'root:password'
         -d '{ "Content": "Testing a correspondence", "ContentType": "text/plain" }'
diff --git a/lib/RT/REST2/Resource/Ticket.pm b/lib/RT/REST2/Resource/Ticket.pm
index 02a020d02c..a59ed5e4f8 100644
--- a/lib/RT/REST2/Resource/Ticket.pm
+++ b/lib/RT/REST2/Resource/Ticket.pm
@@ -60,7 +60,7 @@ with (
         => { -alias => { hypermedia_links => '_default_hypermedia_links' } },
     'RT::REST2::Resource::Record::Deletable',
     'RT::REST2::Resource::Record::Writable'
-        => { -alias => { create_record => '_create_record' } },
+        => { -alias => { create_record => '_create_record', update_record => '_update_record' } },
 );
 
 sub dispatch_rules {
@@ -104,6 +104,19 @@ sub create_record {
     return ($ok, $msg);
 }
 
+sub update_record {
+    my $self = shift;
+    my $data = shift;
+
+    my @results;
+    if ( my $ticket_id = delete $data->{MergeInto} ) {
+        my ( $ok, $msg ) = $self->record->MergeInto($ticket_id);
+        push @results, $msg;
+    }
+    push @results, $self->_update_record($data);
+    return @results;
+}
+
 sub forbidden {
     my $self = shift;
     return 0 unless $self->record->id;

commit c12d03bcda405fb7c537e233fcd22f5ca75ccb6d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 17 02:37:25 2020 +0800

    Support to take/untake/steal tickets in REST2

diff --git a/lib/RT/REST2.pm b/lib/RT/REST2.pm
index 9170b58345..b0a5f33c31 100644
--- a/lib/RT/REST2.pm
+++ b/lib/RT/REST2.pm
@@ -504,6 +504,21 @@ Below are some examples using the endpoints above.
         -d '{ "MergeInto": 3 }'
         'https://myrt.com/REST/2.0/ticket/6'
 
+    # Take a ticket
+    curl -X PUT -H "Content-Type: application/json" -u 'root:password'
+        -d '{ "Take": 1 }'
+        'https://myrt.com/REST/2.0/ticket/6'
+
+    # Untake a ticket
+    curl -X PUT -H "Content-Type: application/json" -u 'root:password'
+        -d '{ "Untake": 1 }'
+        'https://myrt.com/REST/2.0/ticket/6'
+
+    # Steal a ticket
+    curl -X PUT -H "Content-Type: application/json" -u 'root:password'
+        -d '{ "Steal": 1 }'
+        'https://myrt.com/REST/2.0/ticket/6'
+
     # Correspond a ticket
     curl -X POST -H "Content-Type: application/json" -u 'root:password'
         -d '{ "Content": "Testing a correspondence", "ContentType": "text/plain" }'
diff --git a/lib/RT/REST2/Resource/Ticket.pm b/lib/RT/REST2/Resource/Ticket.pm
index a59ed5e4f8..de9cd23642 100644
--- a/lib/RT/REST2/Resource/Ticket.pm
+++ b/lib/RT/REST2/Resource/Ticket.pm
@@ -113,6 +113,14 @@ sub update_record {
         my ( $ok, $msg ) = $self->record->MergeInto($ticket_id);
         push @results, $msg;
     }
+
+    for my $action (qw/Take Untake Steal/) {
+        if ( delete $data->{$action} ) {
+            my ( $ok, $msg ) = $self->record->$action();
+            push @results, $msg;
+        }
+    }
+
     push @results, $self->_update_record($data);
     return @results;
 }

commit 70d39dd1a1b62b12745542b788bfffb648d81baa
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 17 03:00:34 2020 +0800

    Test ticket merge in REST2

diff --git a/t/rest2/tickets.t b/t/rest2/tickets.t
index 837efd2992..934c085e64 100644
--- a/t/rest2/tickets.t
+++ b/t/rest2/tickets.t
@@ -337,6 +337,18 @@ my ($ticket_url, $ticket_id);
     $content = $mech->json_response;
     is($content->{Subject}, 'Ticket update using REST');
     is($content->{Priority}, 42);
+
+    $payload = {
+        Subject => 'Ticket creation using REST',
+        Queue   => 'General',
+    };
+    $res = $mech->post_json( "$rest_base_path/ticket", $payload, 'Authorization' => $auth, );
+    is( $res->code, 201 );
+
+    $payload = { MergeInto => $ticket_id };
+    $res     = $mech->put_json( $res->header('location'), $payload, 'Authorization' => $auth, );
+    is( $res->code, 200 );
+    is_deeply( $mech->json_response, ['Merge Successful'] );
 }
 
 # Transactions
@@ -352,11 +364,11 @@ my ($ticket_url, $ticket_id);
     is($res->code, 200);
 
     my $content = $mech->json_response;
-    is($content->{count}, 3);
+    is($content->{count}, 6);
     is($content->{page}, 1);
     is($content->{per_page}, 20);
-    is($content->{total}, 3);
-    is(scalar @{$content->{items}}, 3);
+    is($content->{total}, 6);
+    is(scalar @{$content->{items}}, 6);
 
     for my $txn (@{ $content->{items} }) {
         is($txn->{type}, 'transaction');

commit 32c5ecc11a1891a838ef084e582605988c0d3032
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 17 03:11:37 2020 +0800

    Test ticket steal/take/untake in REST2

diff --git a/t/rest2/tickets.t b/t/rest2/tickets.t
index 934c085e64..c9e18063b6 100644
--- a/t/rest2/tickets.t
+++ b/t/rest2/tickets.t
@@ -338,6 +338,28 @@ my ($ticket_url, $ticket_id);
     is($content->{Subject}, 'Ticket update using REST');
     is($content->{Priority}, 42);
 
+    $payload = { 'Owner' => 'root' };
+    $res     = $mech->put_json( $ticket_url, $payload, 'Authorization' => $auth, );
+    is( $res->code, 200 );
+    is_deeply( $mech->json_response, ["Ticket $ticket_id: Owner changed from Nobody to root"] );
+
+    $user->PrincipalObj->GrantRight( Right => 'OwnTicket' );
+
+    my %result = (
+        Steal  => 'Owner changed from root to test',
+        Untake => 'Owner changed from test to Nobody',
+        Take   => 'Owner changed from Nobody to test',
+    );
+
+    for my $action (qw/Steal Untake Take/) {
+        my $payload = { $action => 1 };
+
+        # update again with no changes
+        $res = $mech->put_json( $ticket_url, $payload, 'Authorization' => $auth, );
+        is( $res->code, 200 );
+        is_deeply( $mech->json_response, [ $result{$action} ] );
+    }
+
     $payload = {
         Subject => 'Ticket creation using REST',
         Queue   => 'General',
@@ -364,11 +386,14 @@ my ($ticket_url, $ticket_id);
     is($res->code, 200);
 
     my $content = $mech->json_response;
-    is($content->{count}, 6);
+    is($content->{count}, 14);
     is($content->{page}, 1);
     is($content->{per_page}, 20);
-    is($content->{total}, 6);
-    is(scalar @{$content->{items}}, 6);
+
+    # TODO This 14 VS 15 inconsitency is because user lacks ShowOutgoingEmail.
+    # It'll be perfect if we can keep them in sync
+    is($content->{total}, 15);
+    is(scalar @{$content->{items}}, 14);
 
     for my $txn (@{ $content->{items} }) {
         is($txn->{type}, 'transaction');

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


More information about the rt-commit mailing list