[Rt-commit] rt branch, 4.0/rest-ticket-content-type, created. rt-4.0.6-170-g0173c52

? sunnavy sunnavy at bestpractical.com
Fri Feb 8 09:40:38 EST 2013


The branch, 4.0/rest-ticket-content-type has been created
        at  0173c523622e2e2b2011967dfe1f100896f80cc3 (commit)

- Log -----------------------------------------------------------------
commit cd14430cb56ef43a281ee7010c7929c5734c0e2c
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 2a9f643..9307778 100755
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -470,7 +470,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 = ();
@@ -484,6 +484,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());
         }
@@ -658,6 +659,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 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.
@@ -736,7 +742,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) {
@@ -769,7 +775,9 @@ sub comment {
                     while (<STDIN>) { $msg .= $_ }
                 }
             }
-
+            elsif (/-ct/) {
+                $content_type = shift @ARGV;
+            }
             elsif (/-w/) { $wtime = shift @ARGV }
         }
         elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
@@ -791,7 +799,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,
@@ -799,6 +807,7 @@ sub comment {
             Bcc        => [ @bcc ],
             Attachment => [ @files ],
             TimeWorked => $wtime || '',
+            'Content-Type' => $content_type || 'text/plain',
             Text       => $msg || '',
             Status => ''
         }
@@ -2331,6 +2340,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 35b543d..1aef718 100755
--- a/share/html/REST/1.0/Forms/ticket/comment
+++ b/share/html/REST/1.0/Forms/ticket/comment
@@ -90,7 +90,10 @@ if (!$changes{Text} && @atts == 0) {
 
 my $cgi = $m->cgi_object;
 my $ent = MIME::Entity->build(Type => "multipart/mixed");
-$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 032e6c9..7a8d2c9 100755
--- 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;
@@ -188,7 +188,8 @@ else {
                 MIME::Entity->build(
                     From => $session{CurrentUser}->EmailAddress,
                     Subject => $v{Subject},
-                    Data => $text
+                    Data => $text,
+                    'Content-Type' => $v{'Content-Type'} || 'text/plain',
                 );
         }
 
@@ -453,7 +454,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 11b3b6028caddc4c9b122a18ef6237e11faa6bd1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 13 23:59:01 2012 +0800

    doc create ticket with content-type

diff --git a/bin/rt.in b/bin/rt.in
index 9307778..99c89e2 100755
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -2303,12 +2303,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

commit d7687259b2b9db2e6b2be1184fc6cf3d241ddcdf
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 14 00:27:32 2012 +0800

    -ct fix for rt's comment cmd

diff --git a/bin/rt.in b/bin/rt.in
index 99c89e2..fab3f4a 100755
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -751,7 +751,7 @@ sub comment {
         if (/^-e$/) {
             $edit = 1;
         }
-        elsif (/^-[abcmw]$/) {
+        elsif (/^-(?:[abcmw]|ct)$/) {
             unless (@ARGV) {
                 whine "No argument specified with $_.";
                 $bad = 1; last;
@@ -764,6 +764,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;
@@ -775,9 +778,6 @@ sub comment {
                     while (<STDIN>) { $msg .= $_ }
                 }
             }
-            elsif (/-ct/) {
-                $content_type = shift @ARGV;
-            }
             elsif (/-w/) { $wtime = shift @ARGV }
         }
         elsif (!$id && m|^(?:ticket/)?($idlist)$|) {

commit 0173c523622e2e2b2011967dfe1f100896f80cc3
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/bin/rt.in b/bin/rt.in
index fab3f4a..86b4074 100755
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -659,7 +659,7 @@ 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 eq 'ticket' && $text !~ /^Content-Type:/m ) {
+    if ( $type && $type eq 'ticket' && $text !~ /^Content-Type:/m ) {
         $content_type ||= 'text/plain';
         $text .= "Content-Type: $content_type\n";
     }
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..411eb08
--- /dev/null
+++ b/t/web/command_line_ticket_content_type.t
@@ -0,0 +1,49 @@
+
+use strict;
+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