[Rt-commit] rt branch, 4.2/rest-ticket-content-type, created. rt-4.0.6-338-g53fcbf5
? sunnavy
sunnavy at bestpractical.com
Fri Feb 8 09:39:21 EST 2013
The branch, 4.2/rest-ticket-content-type has been created
at 53fcbf5767725b37575695f4a92165a468e9721c (commit)
- Log -----------------------------------------------------------------
commit 9d8a7e68d5184aaebbc9316d1cb7cac337fa25e1
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 e54a07a..19622dc 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 fe74779..48cdd94 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;
@@ -177,7 +177,8 @@ else {
MIME::Entity->build(
From => $session{CurrentUser}->EmailAddress,
Subject => $v{Subject},
- Data => $text
+ Data => $text,
+ 'Content-Type' => $v{'Content-Type'} || 'text/plain',
);
}
@@ -442,7 +443,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 d0b44927739f97d5502a6281c89e5ec21e73ba79
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 19622dc..11e21b1 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 cbe383b4c8da003b897e01fa5166ed85f06fcb38
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 11e21b1..c97922a 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 53fcbf5767725b37575695f4a92165a468e9721c
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 c97922a..da5f0c4 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