[Rt-commit] rt branch, 4.2/record-attachments-dropping, repushed

? sunnavy sunnavy at bestpractical.com
Wed Apr 9 12:00:58 EDT 2014


The branch 4.2/record-attachments-dropping was deleted and repushed:
       was d6eee84f1d6fc4d462b65fddca3469c090a18144
       now 6b61083208d83da0599715e1268ccd8d55e33025

1:  0c2b3eb ! 1:  ff90d31 record attachments' dropping/truncation as SystemWarning txn
    @@ -6,19 +6,31 @@
     --- a/lib/RT/Attachment.pm
     +++ b/lib/RT/Attachment.pm
     @@
    +     #If it's not multipart
          else {
      
    -         my ($encoding, $type);
    +-        my ($encoding, $type);
     -        ($encoding, $content, $type, $Filename) = $self->_EncodeLOB(
    -+        ($encoding, $content, $type, $Filename, my $note_args) = $self->_EncodeLOB(
    -             $Attachment->bodyhandle->as_string,
    -             $Attachment->mime_type,
    +-            $Attachment->bodyhandle->as_string,
    +-            $Attachment->mime_type,
     -            $Filename
    -+            $Filename,
    -+            $args{'TransactionId'}
    -         );
    +-        );
    ++        my ( $encoding, $type, $note_args );
    ++
    ++        my $txn = RT::Transaction->new( RT->SystemUser );
    ++        $txn->Load($args{'TransactionId'});
    ++        if ( $txn->Type =~ /^System/ ) {
    ++            $encoding = 'none';
    ++            $type = $Attachment->mime_type;
    ++            $content  = $Attachment->bodyhandle->as_string;
    ++        }
    ++        else {
    ++            ( $encoding, $content, $type, $Filename, $note_args ) =
    ++                $self->_EncodeLOB( $Attachment->bodyhandle->as_string, $Attachment->mime_type, $Filename, );
    ++        }
      
              my $id = $self->SUPER::Create(
    +             TransactionId   => $args{'TransactionId'},
     @@
                  MessageId       => $MessageId,
              );
    @@ -44,6 +56,26 @@
     --- a/lib/RT/Record.pm
     +++ b/lib/RT/Record.pm
     @@
    + =head2 _EncodeLOB BODY MIME_TYPE FILENAME
    + 
    + Takes a potentially large attachment. Returns (ContentEncoding,
    +-EncodedBody, MimeType, Filename) based on system configuration and
    ++EncodedBody, MimeType, Filename, NoteArgs) based on system configuration and
    + selected database.  Returns a custom (short) text/plain message if
    + DropLongAttachments causes an attachment to not be stored.
    + 
    +@@
    + This function expects to receive an octet string in order to properly
    + evaluate and encode it.  It will return an octet string.
    + 
    ++NoteArgs is currently used to indicate caller that the message is too long and
    ++is truncated or dropped, which could be used to create a system warning
    ++transaction.
    ++
    + =cut
    + 
    + sub _EncodeLOB {
    +@@
              my $Body = shift;
              my $MIMEType = shift || '';
              my $Filename = shift;
    @@ -60,16 +92,9 @@
              #if the attachment is larger than the maximum size
     -        if ( ($MaxSize) and ( $MaxSize < length($Body) ) ) {
     +        my $check_size = $MaxSize && $MaxSize < length($Body);
    -+        if ( $TransactionId ) {
    -+            my $txn = RT::Transaction->new(RT->SystemUser);
    -+            $txn->Load($TransactionId);
    -+            if ( $txn->id && $txn->Type =~ /^System/ ) {
    -+                $check_size = 0; # no size limit for system txn
    -+            }
    -+        }
    ++
    ++        if ( $check_size ) {
      
    -+        if ( $check_size ) {
    -+
     +            my $size = length($Body);
                  # if we're supposed to truncate large attachments
                  if (RT->Config->Get('TruncateLongAttachments')) {
2:  d6eee84 ! 2:  6b61083 test attachment dropping/truncation
    @@ -10,8 +10,7 @@
     +use warnings;
     +use strict;
     +
    -+use RT::Test tests => 11;
    -+use Digest::SHA 'sha1_hex';
    ++use RT::Test tests => undef;
     +use File::Temp 'tempfile';
     +
     +my $content = 'a' x 1000 . 'b' x 10;
    @@ -25,6 +24,16 @@
     +RT->Config->Set( 'TruncateLongAttachments', '0' );
     +RT->Config->Set( 'DropLongAttachments',     '1' );
     +
    ++my $cf = RT::CustomField->new( RT->SystemUser );
    ++ok(
    ++    $cf->Create(
    ++        Name  => 'test truncation',
    ++        Queue => '0',
    ++        Type  => 'FreeformSingle',
    ++    ),
    ++);
    ++my $cfid = $cf->id;
    ++
     +my ( $baseurl, $m ) = RT::Test->started_ok;
     +ok $m->login, 'logged in';
     +
    @@ -37,12 +46,18 @@
     +$m->field( 'Subject', 'Attachments dropping test' );
     +$m->field( 'Attach',  $path );
     +$m->field( 'Content', 'Some content' );
    ++my $cf_content = 'cf' . 'a' x 998 . 'cfb';
    ++$m->field( "Object-RT::Ticket--CustomField-$cfid-Value", $cf_content );
     +$m->submit;
     +is( $m->status, 200, "request successful" );
     +
     +$m->content_contains( "$name was dropped", 'dropped message' );
    ++$m->content_lacks( 'cfaaaa', 'cf value was dropped' );
     +$m->follow_link_ok( { text => "Download $name" } );
     +is( $m->content, 'Large attachment dropped', 'dropped $name' );
    ++
    ++undef $m;
    ++done_testing;
     
     diff --git a/t/web/attachment_truncation.t b/t/web/attachment_truncation.t
     new file mode 100644
    @@ -52,8 +67,7 @@
     +use warnings;
     +use strict;
     +
    -+use RT::Test tests => 12;
    -+use Digest::SHA 'sha1_hex';
    ++use RT::Test tests => undef;
     +use File::Temp 'tempfile';
     +
     +my $content = 'a' x 1000 . 'b' x 10;
    @@ -64,11 +78,23 @@
     +
     +RT->Config->Set( 'MaxAttachmentSize', 1000 );
     +RT->Config->Set( 'TruncateLongAttachments', '1' );
    ++
    ++my $queue = RT::Test->load_or_create_queue( Name => 'General' );
    ++ok( $queue->id, "Loaded General queue" );
    ++
    ++my $cf = RT::CustomField->new( RT->SystemUser );
    ++ok(
    ++    $cf->Create(
    ++        Name  => 'test truncation',
    ++        Queue => '0',
    ++        Type  => 'FreeformSingle',
    ++    ),
    ++);
    ++my $cfid = $cf->id;
    ++
     +my ( $baseurl, $m ) = RT::Test->started_ok;
     +ok $m->login, 'logged in';
     +
    -+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
    -+ok( $queue->id, "Loaded General queue" );
     +$m->get_ok( $baseurl . '/Ticket/Create.html?Queue=' . $queue->id );
     +$m->content_contains( "Create a new ticket", 'ticket create page' );
     +
    @@ -76,10 +102,17 @@
     +$m->field( 'Subject', 'Attachments test' );
     +$m->field( 'Attach',  $path );
     +$m->field( 'Content', 'Some content' );
    ++my $cf_content = 'cf' . 'a' x 998 . 'cfb';
    ++$m->field( "Object-RT::Ticket--CustomField-$cfid-Value", $cf_content );
     +$m->submit;
     +is( $m->status, 200, "request successful" );
     +
     +$m->content_contains( "$name was truncated", 'truncated message' );
    ++$m->content_contains( 'cf' . 'a' x 998, 'has the first 1000 cf chars' );
    ++$m->content_lacks( 'cfb', 'lacks cf chars after that' );
     +$m->follow_link_ok( { text => "Download $name" } );
     +$m->content_contains( 'a' x 1000, 'has the first 1000 chars' );
     +$m->content_lacks( 'b', 'lacks chars after that' );
    ++
    ++undef $m;
    ++done_testing;



More information about the rt-commit mailing list