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

? sunnavy sunnavy at bestpractical.com
Mon Mar 19 12:48:47 EDT 2018


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

- Log -----------------------------------------------------------------
commit ffd6a4076ac05897cc24feb3a6fbaeb3c4914c4c
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",
                "From": "user1 at example.com", "To": "rt at example.com",
                "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: Subject, From, To, Cc, Date, 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..6bf92b9 100644
--- a/lib/RT/Extension/REST2/Resource/Ticket.pm
+++ b/lib/RT/Extension/REST2/Resource/Ticket.pm
@@ -43,6 +43,17 @@ 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',
+            ( map { $_ => delete $data->{$_} } grep { defined $data->{$_} } qw/From To Date/ ),
+            # Keep Subject and Cc since they are valid parameters of RT::Ticket::Create
+            ( map { $_ => $data->{$_} } grep        { defined $data->{$_} } qw/Subject Cc/ ),
+        );
+    }
+
     my ($ok, $txn, $msg) = $self->_create_record($data);
     return ($ok, $msg);
 }

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


More information about the Bps-public-commit mailing list