[Rt-commit] rt branch, 4.0/backport-content-type-in-rest, created. rt-4.0.13-85-g1b9e7cf

Ruslan Zakirov ruz at bestpractical.com
Mon Jun 24 16:41:27 EDT 2013


The branch, 4.0/backport-content-type-in-rest has been created
        at  1b9e7cf38a7bb0b86894e6e0c0af3b0e355cbe1d (commit)

- Log -----------------------------------------------------------------
commit f0ad8f58162e985687df8ec7d3d069b70c1b2e42
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 13 06:53:52 2012 +0800

    REST: allow to set content-type for create/commenting ticket

diff --git a/bin/rt.in b/bin/rt.in
index 4a3eada..a344e11 100644
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -472,7 +472,7 @@ sub show {
 sub edit {
     my ($action) = @_;
     my (%data, $type, @objects);
-    my ($cl, $text, $edit, $input, $output);
+    my ($cl, $text, $edit, $input, $output, $content_type);
 
     use vars qw(%set %add %del);
     %set = %add = %del = ();
@@ -486,6 +486,7 @@ sub edit {
         if    (/^-e$/) { $edit = 1 }
         elsif (/^-i$/) { $input = 1 }
         elsif (/^-o$/) { $output = 1 }
+        elsif (/^-ct$/) { $content_type = shift @ARGV }
         elsif (/^-t$/) {
             $bad = 1, last unless defined($type = get_type_argument());
         }
@@ -660,6 +661,11 @@ sub edit {
 EDIT:
     # We'll let the user edit the form before sending it to the server,
     # unless we have enough information to submit it non-interactively.
+    if ( $type && $type eq 'ticket' && $text !~ /^Content-Type:/m ) {
+        $content_type ||= 'text/plain';
+        $text .= "Content-Type: $content_type\n";
+    }
+
     if ($edit || (!$input && !$cl)) {
         my $newtext = vi($text);
         # We won't resubmit a bad form unless it was changed.
@@ -738,7 +744,7 @@ sub setcommand {
 
 sub comment {
     my ($action) = @_;
-    my (%data, $id, @files, @bcc, @cc, $msg, $wtime, $edit);
+    my (%data, $id, @files, @bcc, @cc, $msg, $content_type, $wtime, $edit);
     my $bad = 0;
 
     while (@ARGV) {
@@ -747,7 +753,7 @@ sub comment {
         if (/^-e$/) {
             $edit = 1;
         }
-        elsif (/^-[abcmw]$/) {
+        elsif (/^-(?:[abcmw]|ct)$/) {
             unless (@ARGV) {
                 whine "No argument specified with $_.";
                 $bad = 1; last;
@@ -760,6 +766,9 @@ sub comment {
                 }
                 push @files, shift @ARGV;
             }
+            elsif (/-ct/) {
+                $content_type = shift @ARGV;
+            }
             elsif (/-([bc])/) {
                 my $a = $_ eq "-b" ? \@bcc : \@cc;
                 @$a = split /\s*,\s*/, shift @ARGV;
@@ -771,7 +780,6 @@ sub comment {
                     while (<STDIN>) { $msg .= $_ }
                 }
             }
-
             elsif (/-w/) { $wtime = shift @ARGV }
         }
         elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
@@ -793,7 +801,7 @@ sub comment {
 
     my $form = [
         "",
-        [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Text" ],
+        [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Content-Type", "Text" ],
         {
             Ticket     => $id,
             Action     => $action,
@@ -801,6 +809,7 @@ sub comment {
             Bcc        => [ @bcc ],
             Attachment => [ @files ],
             TimeWorked => $wtime || '',
+            'Content-Type' => $content_type || 'text/plain',
             Text       => $msg || '',
             Status => ''
         }
@@ -2273,12 +2282,14 @@ Text:
         -S var=val
                 Submits the specified variable with the request.
         -t type Specifies object type.
+        -ct content-type Specifies content type of message(tickets only).
 
     Examples:
 
         # Interactive (starts $EDITOR with a form).
         rt edit ticket/3
         rt create -t ticket
+        rt create -t ticket -ct text/html
 
         # Non-interactive.
         rt edit ticket/1-3 add cc=foo at example.com set priority=3 due=tomorrow
@@ -2310,6 +2321,7 @@ Text:
     Options:
 
         -m <text>       Specify comment text.
+        -ct <content-type> Specify content-type of comment text.
         -a <file>       Attach a file to the comment. (May be used more
                         than once to attach multiple files.)
         -c <addrs>      A comma-separated list of Cc addresses.
diff --git a/share/html/REST/1.0/Forms/ticket/comment b/share/html/REST/1.0/Forms/ticket/comment
index b50135f..2618e66 100644
--- a/share/html/REST/1.0/Forms/ticket/comment
+++ b/share/html/REST/1.0/Forms/ticket/comment
@@ -94,7 +94,11 @@ my $ent = MIME::Entity->build(
     Type => "multipart/mixed",
     'X-RT-Interface' => 'REST',
 );
-$ent->attach(Data => $changes{Text}) if $changes{Text};
+$ent->attach(
+    'Content-Type' => $changes{'Content-Type'} || 'text/plain',
+    Data => $changes{Text},
+) if $changes{Text};
+
 
 my $i = 1;
 foreach my $att (@atts) {
diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index a48876b..f6501ea 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -67,7 +67,7 @@ my @dates  = qw(Created Starts Started Due Resolved Told LastUpdated);
 my @people = qw(Requestors Cc AdminCc);
 my @create = qw(Queue Requestor Subject Cc AdminCc Owner Status Priority
                 InitialPriority FinalPriority TimeEstimated TimeWorked
-                TimeLeft Starts Started Due Resolved);
+                TimeLeft Starts Started Due Resolved Content-Type);
 my @simple = qw(Subject Status Priority Disabled TimeEstimated TimeWorked
                 TimeLeft InitialPriority FinalPriority);
 my %dates  = map {lc $_ => $_} @dates;
@@ -190,6 +190,7 @@ else {
                     Subject => $v{Subject},
                     Data => $text,
                     'X-RT-Interface' => 'REST',
+                    'Content-Type' => $v{'Content-Type'} || 'text/plain',
                 );
         }
 
@@ -454,7 +455,7 @@ else {
                 }
             }
         }
-        elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
+        elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator' && $key ne 'content-type' ) {
             $n = 0;
             $s = "Unknown field.";
         }

commit 1b9e7cf38a7bb0b86894e6e0c0af3b0e355cbe1d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 14 11:27:18 2012 +0800

    command line test of content-type in ticket creating/commenting

diff --git a/t/web/command_line_ticket_content_type.t b/t/web/command_line_ticket_content_type.t
new file mode 100644
index 0000000..afdd529
--- /dev/null
+++ b/t/web/command_line_ticket_content_type.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+use Test::Expect;
+use RT::Test tests => 22, actual_server => 1;
+my ( $baseurl, $m ) = RT::Test->started_ok;
+$m->login();
+
+my $rt_tool_path = "$RT::BinPath/rt";
+
+$ENV{'RTUSER'}   = 'root';
+$ENV{'RTPASSWD'} = 'password';
+$ENV{'RTSERVER'} = RT->Config->Get('WebBaseURL');
+$ENV{'RTCONFIG'} = '/dev/null';
+
+# create a ticket
+expect_run(
+    command => "$rt_tool_path shell",
+    prompt  => 'rt> ',
+    quit    => 'quit',
+);
+
+for my $content_type ( 'text/plain', 'text/html' ) {
+    expect_send(
+        qq{create -t ticket -ct $content_type set subject='new ticket' text=foo},
+        "creating a ticket with content-type $content_type"
+    );
+
+    expect_like( qr/Ticket \d+ created/, "created the ticket" );
+    expect_handle->before() =~ /Ticket (\d+) created/;
+    my $id = $1;
+    ok( $id, "got ticket $id" );
+
+    $m->goto_ticket($id);
+    $m->follow_link_ok( { text => 'with headers', n => 1 } );
+    $m->content_contains( "Content-Type: $content_type", 'content-type' );
+
+    expect_send(
+        qq{comment ticket/$id -ct $content_type -m bar},
+        "commenting a ticket with content-type $content_type"
+    );
+    expect_like( qr/Message recorded/, "commented the ticket" );
+
+    $m->goto_ticket($id);
+    $m->follow_link_ok( { text => 'with headers', n => 2 } );
+    $m->content_contains( "Content-Type: $content_type", 'content-type' );
+}
+
+expect_quit();
+1;    # needed to avoid a weird exit value from expect_quit

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


More information about the Rt-commit mailing list