[Rt-commit] r5138 - in rt/branches/3.5-TESTING: html/REST/1.0/Forms/ticket

kevinr at bestpractical.com kevinr at bestpractical.com
Mon May 1 15:16:53 EDT 2006


Author: kevinr
Date: Mon May  1 15:16:52 2006
New Revision: 5138

Modified:
   rt/branches/3.5-TESTING/   (props changed)
   rt/branches/3.5-TESTING/html/REST/1.0/Forms/ticket/comment

Log:
 r12274 at sad-girl-in-snow:  kevinr | 2006-04-24 20:03:15 -0400
 * Commenting via the REST interface works now!


Modified: rt/branches/3.5-TESTING/html/REST/1.0/Forms/ticket/comment
==============================================================================
--- rt/branches/3.5-TESTING/html/REST/1.0/Forms/ticket/comment	(original)
+++ rt/branches/3.5-TESTING/html/REST/1.0/Forms/ticket/comment	Mon May  1 15:16:52 2006
@@ -56,49 +56,39 @@
 use File::Temp qw(tempfile);
 
 $RT::Logger->warning("Got ticket id=$id for comment");
-my @temp = grep { !defined $_ } values(%changes);
-$RT::Logger->warning("Got args @temp.");
+$RT::Logger->warning("Got args @{[keys(%changes)]}.");
 
 my $ticket = new RT::Ticket $session{CurrentUser};
-my $status = "200 Ok";
-my $output;
-my $action;
-my $content;
-my ($c, $o, $k, $e) = ("", [], {}, "");
+my ($c, $o, $k, $e) = ("", [], {}, 0);
 
 # http://.../REST/1.0/ticket/1/comment
-$id =~ s#^/##;
-$id ||= $k->{Ticket};
-unless ($id =~ /^\d+/) {
-    $output = "Invalid ticket id: `$id'.\n";
-    $status = "400 Bad Request";
-    goto OUTPUT;
-}
-if ($k->{Ticket} && $id ne $k->{Ticket}) {
-    $output = "The submitted form and URL specify different tickets.\n";
-    $status = "400 Bad Request";
+$ticket->Load($id);
+if (!$ticket->Id) {
+    $e = 1;
+    $c = "# Ticket $id does not exist.";
     goto OUTPUT;
 }
 
-($action = $k->{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
+my $action;
+($action = $changes{Action}) =~ s/^(.)(.*)$/\U$1\L$2\E/;
 unless ($action =~ /^(?:Comment|Correspond)$/) {
-    $output = "Invalid action: `$action'.\n";
-    $status = "400 Bad Request";
+    $e = 1;
+    $c = "# Invalid action: `$action'.\n";
     goto OUTPUT;
 }
 
-my $text = $k->{Text};
-my @atts = @{ vsplit($k->{Attachment}) };
+my $text = $changes{Text};
+my @atts = @{ vsplit($changes{Attachment}) };
 
-if (!$k->{Text} && @atts == 0) {
-        $status = "400 Bad Request";
-        $output = "Empty comment with no attachments submitted.\n";
-        goto OUTPUT;
+if (!$changes{Text} && @atts == 0) {
+    $e = 1;
+    $c = "# Empty comment with no attachments submitted.";
+    goto OUTPUT;
 }
 
 my $cgi = $m->cgi_object;
 my $ent = MIME::Entity->build(Type => "multipart/mixed");
-$ent->attach(Data => $k->{Text}) if $k->{Text};
+$ent->attach(Data => $changes{Text}) if $changes{Text};
 
 my $i = 1;
 foreach my $att (@atts) {
@@ -124,41 +114,35 @@
         );
     }
     else {
-        $status = "400 Bad Request";
-        $output = "No attachment for $att.\n";
+        $e = 1;
+        $c = "# No attachment for $att.";
         goto OUTPUT;
     }
 
     $i++;
 }
 
-$ticket->Load($id);
-unless ($ticket->Id) {
-    $output = "Couldn't load ticket id: `$id'.\n";
-    $status = "404 Ticket not found";
-    goto OUTPUT;
-}
 unless ($ticket->CurrentUserHasRight('ModifyTicket') ||
         ($action eq "Comment" &&
          $ticket->CurrentUserHasRight("CommentOnTicket")) ||
         ($action eq "Correspond" &&
          $ticket->CurrentUserHasRight("ReplyToTicket")))
 {
-    $output = "You are not allowed to $action on ticket $id.\n";
-    $status = "403 Permission denied";
+    $e = 1;
+    $c = "You are not allowed to $action on ticket $id.\n";
     goto OUTPUT;
 }
 
-my $cc = join ", ", @{ vsplit($k->{Cc}) };
-my $bcc = join ", ", @{ vsplit($k->{Bcc}) };
+my $cc = join ", ", @{ vsplit($changes{Cc}) };
+my $bcc = join ", ", @{ vsplit($changes{Bcc}) };
 my ($n, $s) = $ticket->$action(MIMEObj => $ent,
                                CcMessageTo => $cc,
                                BccMessageTo => $bcc,
-                               TimeTaken => $k->{TimeWorked} || 0);
-$output = $s;
-if ($k->{Status}) {
-   my  ($status_n, $status_s) = $ticket->SetStatus($k->{'Status'} );   
-  $output .= "\n".$status_s;
+                               TimeTaken => $changes{TimeWorked} || 0);
+$c = "# ".$s;
+if ($changes{Status}) {
+   my  ($status_n, $status_s) = $ticket->SetStatus($changes{'Status'} );   
+  $c .= "\n# ".$status_s;
 }
 
 OUTPUT:


More information about the Rt-commit mailing list