[Bps-public-commit] rt-extension-rest2 branch, create-ticket-with-content, created. 1.03-6-gddfa860

Jim Brandt jbrandt at bestpractical.com
Thu May 2 17:32:39 EDT 2019


The branch, create-ticket-with-content has been created
        at  ddfa86031109c50e87b671667980a8c671f3d1d5 (commit)

- Log -----------------------------------------------------------------
commit 6b6b3749a86483d86579f91aa8d536d0867188d9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Mar 20 00:09:31 2018 +0800

    Support to create ticket with content
    
    Previously on ticket create, we can set ticket's fields like subject,
    people, dates, custom fields, etc. But sadly we can't add content, this
    commit is to fix this, so we can really do:
    
        curl -X POST -H "Content-Type: application/json" -u 'root:password'
            -d '{ "Queue": "General", "Subject": "Create ticket test",
                "Content": "Testing a create",
                "CustomFields": {"Severity": "Low"}}'
            'https://myrt.com/REST/2.0/ticket'
    
    To add content on ticket create, we need to build a MIME object to feed
    RT::Ticket::Create, and the following fields will be used to build the
    MIME object:ContentType and Content, which
    HTML::Mason::Commands::MakeMIMEEntity supports now.

diff --git a/lib/RT/Extension/REST2/Resource/Ticket.pm b/lib/RT/Extension/REST2/Resource/Ticket.pm
index aa19a89..3f2f751 100644
--- a/lib/RT/Extension/REST2/Resource/Ticket.pm
+++ b/lib/RT/Extension/REST2/Resource/Ticket.pm
@@ -43,6 +43,14 @@ sub create_record {
         Object => $queue,
     ) and $queue->Disabled != 1;
 
+    if ( defined $data->{Content} ) {
+        $data->{MIMEObj} = HTML::Mason::Commands::MakeMIMEEntity(
+            Interface => 'REST',
+            Body      => delete $data->{Content},
+            Type      => delete $data->{ContentType} || 'text/plain',
+        );
+    }
+
     my ($ok, $txn, $msg) = $self->_create_record($data);
     return ($ok, $msg);
 }

commit d0210c3d96a1c97557a2f6bd49ab4fba4cb877c9
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu May 2 17:03:05 2019 -0400

    Correct create ticket example to use Requestor, Cc

diff --git a/README b/README
index 042cb5c..93eaf95 100644
--- a/README
+++ b/README
@@ -260,17 +260,26 @@ USAGE
         # Create a ticket, setting some custom fields
         curl -X POST -H "Content-Type: application/json" -u 'root:password'
             -d '{ "Queue": "General", "Subject": "Create ticket test",
-                "From": "user1 at example.com", "To": "rt at example.com",
+                "Requestor": "user1 at example.com", "Cc": "user2 at example.com",
                 "Content": "Testing a create",
                 "CustomFields": {"Severity": "Low"}}'
             'https://myrt.com/REST/2.0/ticket'
 
         # Update a ticket, with a custom field update
         curl -X PUT -H "Content-Type: application/json" -u 'root:password'
-            -d '{ "Subject": "Update test", "Content": "Testing an update",
-                "CustomFields": {"Severity": "High"}}'
+            -d '{ "Subject": "Update test", "CustomFields": {"Severity": "High"}}'
             '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" }'
+            'https://myrt.com/REST/2.0/ticket/6/correspond'
+
+        # Comment a ticket
+        curl -X POST -H "Content-Type: text/plain" -u 'root:password'
+            -d 'Testing a comment'
+            'https://myrt.com/REST/2.0/ticket/6/comment'
+
    Transactions
         GET /transactions?query=<JSON>
         POST /transactions
diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index e720a66..58e729c 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -296,7 +296,7 @@ Below are some examples using the endpoints above.
     # Create a ticket, setting some custom fields
     curl -X POST -H "Content-Type: application/json" -u 'root:password'
         -d '{ "Queue": "General", "Subject": "Create ticket test",
-            "From": "user1 at example.com", "To": "rt at example.com",
+            "Requestor": "user1 at example.com", "Cc": "user2 at example.com",
             "Content": "Testing a create",
             "CustomFields": {"Severity": "Low"}}'
         'https://myrt.com/REST/2.0/ticket'

commit ddfa86031109c50e87b671667980a8c671f3d1d5
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu May 2 17:32:09 2019 -0400

    Remove unimplemented From and To from tests

diff --git a/t/tickets.t b/t/tickets.t
index ae151c1..a961a32 100644
--- a/t/tickets.t
+++ b/t/tickets.t
@@ -24,7 +24,6 @@ my $user = RT::Extension::REST2::Test->user;
     my $res = $mech->post_json("$rest_base_path/ticket",
         {
             Subject => 'Ticket creation using REST',
-            From    => 'test at bestpractical.com',
         },
         'Authorization' => $auth,
     );
@@ -37,8 +36,6 @@ my ($ticket_url, $ticket_id);
 {
     my $payload = {
         Subject => 'Ticket creation using REST',
-        From    => 'test at bestpractical.com',
-        To      => 'rt at localhost',
         Queue   => 'General',
         Content => 'Testing ticket creation using REST API.',
     };

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


More information about the Bps-public-commit mailing list