[Rt-commit] rt branch, 3.999-trunk, updated. a0e0d6694a9649a09c7cc5997022b33c31d00f29

? sunnavy sunnavy at bestpractical.com
Fri Apr 2 04:38:20 EDT 2010


The branch, 3.999-trunk has been updated
       via  a0e0d6694a9649a09c7cc5997022b33c31d00f29 (commit)
       via  81d74a5cd9047ec9ae66302404da1e69ac1ac4bc (commit)
       via  45ba79d6a19342421ee087496f045ef32bfa8a6e (commit)
      from  27d49b2b6f5098a5f0c9a44f08e99b62a67681bd (commit)

Summary of changes:
 lib/RT/Action/EditTicketCFs.pm           |   31 ++++++++++++++-------------
 lib/RT/Action/WithCustomFields.pm        |    2 +-
 lib/RT/Dispatcher.pm                     |   15 ++++++++----
 lib/RT/Interface/Web.pm                  |   34 +++++++++--------------------
 share/html/REST/1.0/Forms/ticket/comment |   19 ++++------------
 share/html/REST/1.0/ticket/comment       |   21 +++++-------------
 share/html/REST/1.0/ticket/link          |    4 +-
 share/html/REST/1.0/ticket/merge         |    4 +-
 8 files changed, 53 insertions(+), 77 deletions(-)

- Log -----------------------------------------------------------------
commit 45ba79d6a19342421ee087496f045ef32bfa8a6e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 2 16:15:51 2010 +0800

    use clickable instead of redirect

diff --git a/lib/RT/Dispatcher.pm b/lib/RT/Dispatcher.pm
index a9de0c4..a99b8d8 100644
--- a/lib/RT/Dispatcher.pm
+++ b/lib/RT/Dispatcher.pm
@@ -796,7 +796,6 @@ before 'prefs' => run {
 };
 
 before qr{^/Search/Build.html} => run {
-    my $querystring = '';
     my $selected_clauses = Jifty->web->request->argument('clauses') || 0;
     my ( $saved_search, $current_search, $results ) = RT::Interface::Web::QueryBuilder->setup_query();
 
@@ -829,14 +828,20 @@ before qr{^/Search/Build.html} => run {
     #  Push the updates into the session so we don't lose 'em
     Jifty->web->session->set( 'CurrentSearchHash', { %$saved_search, %$current_search, } );
 
+    my $query;
     if ( Jifty->web->request->argument('new_query') ) {
-        $querystring = 'new_query=1';
+        $query = { new_query => 1 };
     } elsif ( $current_search->{'query'} ) {
-        $querystring = RT::Interface::Web->format_query_params(%$current_search);
+        $query = $current_search;
     }
+    my $querystring = RT::Interface::Web->format_query_params(%$query);
 
-    Jifty->web->redirect( Jifty->web->url . "Search/Results.html?" . $querystring )
-        if ( Jifty->web->request->argument('do_search') );
+    my $clickable = Jifty::Web::Form::Clickable->new(
+        url => Jifty->web->url . 'Search/Results.html',
+        parameters => $query,
+    );
+    Jifty->web->redirect($clickable)
+      if ( Jifty->web->request->argument('do_search') );
 
     set current_search    => $current_search;
     set current_format    => $current_format;

commit 81d74a5cd9047ec9ae66302404da1e69ac1ac4bc
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 2 16:17:51 2010 +0800

    tiny args fix

diff --git a/lib/RT/Action/WithCustomFields.pm b/lib/RT/Action/WithCustomFields.pm
index 0529ce4..04faf89 100644
--- a/lib/RT/Action/WithCustomFields.pm
+++ b/lib/RT/Action/WithCustomFields.pm
@@ -12,7 +12,7 @@ sub _add_custom_fields {
     my @args = $self->_setup_custom_fields( cfs => $cfs );
 
     for my $args ( @args ) {
-        $self->$method( $args );
+        $self->$method( %$args );
     }
 }
 

commit a0e0d6694a9649a09c7cc5997022b33c31d00f29
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 2 16:37:19 2010 +0800

    remove old cgi thing

diff --git a/lib/RT/Action/EditTicketCFs.pm b/lib/RT/Action/EditTicketCFs.pm
index 4fabbd6..8dc5497 100644
--- a/lib/RT/Action/EditTicketCFs.pm
+++ b/lib/RT/Action/EditTicketCFs.pm
@@ -78,21 +78,22 @@ sub take_action {
 
             if ( $cf->type eq 'Binary' || $cf->type eq 'Image' ) {
                 next unless $new_values;
-                my $cgi_object  = Jifty->handler->cgi;
-                my $upload_info = $cgi_object->uploadInfo($new_values);
-                my $filename    = "$new_values";
-                $filename =~ s#^.*[\\/]##;
-                binmode($new_values);
-
-                my ( $val, $msg ) = $ticket->add_custom_field_value(
-                    field         => $cfid,
-                    value         => $filename,
-                    large_content => do { local $/; scalar <$new_values> },
-                    content_type  => $upload_info->{'Content-Type'},
-                );
-                Jifty->log->error($msg) unless $val;
-                push @{ $self->result->content('detailed_messages')
-                      ->{ $cf->name } }, $msg;
+                for my $upload (
+                    ref $new_values eq 'ARRAY'
+                    ? @$new_values
+                    : $new_values
+                  )
+                {
+                    my ( $val, $msg ) = $ticket->add_custom_field_value(
+                        field         => $cfid,
+                        value         => $upload->filename,
+                        large_content => $upload->filehandle,
+                        content_type  => $upload->content_type,
+                    );
+                    Jifty->log->error($msg) unless $val;
+                    push @{ $self->result->content('detailed_messages')
+                          ->{ $cf->name } }, $msg;
+                }
             }
             else {
 
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index c3f6bf6..10fa0b9 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -582,26 +582,18 @@ sub make_mime_entity {
 
     if ( $args{'attachment_field_name'} ) {
 
-        my $cgi_object = Jifty->handler->cgi;
-
-        if ( my $filehandle = $cgi_object->upload( $args{'attachment_field_name'} ) ) {
-
+        if ( my $upload = Jifty->web->request->uploads->{
+                $args{'attachment_field_name'} } ) {
             my ( @content, $buffer );
-            while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) {
+            open my $fh, '<', $upload->path;
+            binmode $fh;
+            while ( my $bytesread = read( $fh, $buffer, 4096 ) ) {
                 push @content, $buffer;
             }
 
-            my $uploadinfo = $cgi_object->uploadInfo($filehandle);
-
-            # Prefer the cached name first over CGI.pm stringification.
-            my $filename = $RT::Mason::CGI::Filename;
-            $filename = "$filehandle" unless defined($filename);
-            $filename = Encode::decode_utf8($filename);
-            $filename =~ s{^.*[\\/]}{};
-            
-
+            my $filename = Encode::decode_utf8( $upload->basename );
             $Message->attach(
-                Type     => $uploadinfo->{'Content-Type'},
+                Type     => $upload->content_type,
                 Filename => $filename,
                 Data     => \@content,
             );
@@ -1272,18 +1264,14 @@ Returns C<undef> if no files were uploaded in the C<$arg> field.
 
 sub _uploaded_file {
     my $arg         = shift;
-    my $cgi_object  = Jifty->handler->cgi;
-    my $fh          = $cgi_object->upload($arg) or return undef;
-    my $upload_info = $cgi_object->uploadInfo($fh);
-
-    my $filename = "$fh";
-    $filename =~ s#^.*[\\/]##;
+    my $upload = Jifty->web->request->uploads->{$arg} or return;
+    open my $fh, '<', $upload->path or return;
     binmode($fh);
 
     return {
-        value         => $filename,
+        value         => $upload->basename,
         large_content => do { local $/; scalar <$fh> },
-        content_type  => $upload_info->{'Content-Type'},
+        content_type  => $upload->content_type,
     };
 }
 
diff --git a/share/html/REST/1.0/Forms/ticket/comment b/share/html/REST/1.0/Forms/ticket/comment
index abf309a..a16169b 100755
--- a/share/html/REST/1.0/Forms/ticket/comment
+++ b/share/html/REST/1.0/Forms/ticket/comment
@@ -89,7 +89,6 @@ if (!$changes{Text} && @atts == 0) {
     goto OUTPUT;
 }
 
-my $cgi = Jifty->handler->cgi;
 my $ent = MIME::Entity->build(Type => "multipart/mixed");
 $ent->attach(Data => $changes{Text}) if $changes{Text};
 
@@ -99,20 +98,12 @@ foreach my $att (@atts) {
     my $file = $att;
     $file =~ s#^.*[\\/]##;
 
-    my $fh = $cgi->upload("attachment_$i");
-    if ($fh) {
-        my $buf;
-        my ($w, $tmp) = tempfile();
-        my $info = $cgi->uploadInfo($fh);
-
-        while (sysread($fh, $buf, 8192)) {
-            syswrite($w, $buf);
-        }
-
+    my $upload = Jifty->web->request->uploads->{"attachment_$i"};
+    if ($upload) {
         $ent->attach(
-            Path => $tmp,
-            type => $info->{'Content-Type'} || guess_media_type($tmp),
-            Filename => $file,
+            Path => $upload->path,
+            Type => $upload->content_type || guess_media_type($upload->path),
+            Filename => $upload->basename,
             Disposition => "attachment"
         );
     }
diff --git a/share/html/REST/1.0/ticket/comment b/share/html/REST/1.0/ticket/comment
index 1664298..431da3a 100755
--- a/share/html/REST/1.0/ticket/comment
+++ b/share/html/REST/1.0/ticket/comment
@@ -57,7 +57,7 @@ use RT::Interface::REST;
 use File::Temp qw(tempfile);
 
 my $ticket = RT::Model::Ticket->new( current_user => Jifty->web->current_user );
-my $object = $r->path_info;
+my $object = Jifty->web->request->path_info;
 my $status = "200 Ok";
 my $output;
 my $action;
@@ -105,7 +105,6 @@ if (!$k->{Text} && @atts == 0) {
         goto OUTPUT;
 }
 
-my $cgi = Jifty->handler->cgi;
 my $ent = MIME::Entity->build(Type => "multipart/mixed");
 $ent->attach(Data => $k->{Text}) if $k->{Text};
 
@@ -115,20 +114,12 @@ foreach my $att (@atts) {
     my $file = $att;
     $file =~ s#^.*[\\/]##;
 
-    my $fh = $cgi->upload("attachment_$i");
-    if ($fh) {
-        my $buf;
-        my ($w, $tmp) = tempfile();
-        my $info = $cgi->uploadInfo();
-
-        while (sysread($fh, $buf, 8192)) {
-            syswrite($w, $buf);
-        }
-
+    my $upload = Jifty->web->request->uploads->{"attachment_$i"};
+    if ($upload) {
         $ent->attach(
-            Path => $tmp,
-            type => $info->{'Content-Type'} || guess_media_type($tmp),
-            Filename => $file,
+            Path => $upload->path,
+            Type => $upload->content_type || guess_media_type($upload->path),
+            Filename => $upload->basename,
             Disposition => "attachment"
         );
     }
diff --git a/share/html/REST/1.0/ticket/link b/share/html/REST/1.0/ticket/link
index b3c5853..feacddd 100755
--- a/share/html/REST/1.0/ticket/link
+++ b/share/html/REST/1.0/ticket/link
@@ -58,7 +58,7 @@ use RT::Interface::REST;
 my $output;
 my $status = "200 Ok";
 my $ticket = RT::Model::Ticket->new( current_user => Jifty->web->current_user );
-my $object = $r->path_info;
+my $object = Jifty->web->request->path_info;
 
 my @fields = qw(DependsOn DependedOnBy RefersTo ReferredToBy HasMember MemberOf);
 my %fields = map { lc $_ => $_ } @fields;
@@ -82,7 +82,7 @@ if ($id && $object && $id != $object) {
 $id ||= $object;
 unless ($id =~ /^\d+$/ && $to =~ /^\d+$/) {
     my $bad = ($id !~ /^\d+$/) ? $id : $to;
-    $output = $r->path_info. "\n";
+    $output = Jifty->web->request->path_info. "\n";
     $output .= "Invalid ticket id: '$bad'.\n";
     $status = "400 Bad Request";
     goto OUTPUT;
diff --git a/share/html/REST/1.0/ticket/merge b/share/html/REST/1.0/ticket/merge
index 3aa909e..72d0fca 100755
--- a/share/html/REST/1.0/ticket/merge
+++ b/share/html/REST/1.0/ticket/merge
@@ -57,7 +57,7 @@ use RT::Interface::REST;
 my $output;
 my $status = "200 Ok";
 my $ticket = RT::Model::Ticket->new( current_user => Jifty->web->current_user );
-my $object = $r->path_info;
+my $object = Jifty->web->request->path_info;
 
 # http://.../REST/1.0/ticket/merge/1
 
@@ -70,7 +70,7 @@ if ($id && $object && $id != $object) {
 $id ||= $object;
 unless ($id =~ /^\d+$/ && $into =~ /^\d+$/) {
     my $bad = ($id !~ /^\d+$/) ? $id : $into;
-    $output = $r->path_info. "\n";
+    $output = Jifty->web->request->path_info. "\n";
     $output .= "Invalid ticket id: `$bad'.\n";
     $status = "400 Bad Request";
     goto OUTPUT;

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


More information about the Rt-commit mailing list