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

? sunnavy sunnavy at bestpractical.com
Mon Jul 14 15:54:39 EDT 2014


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

1:  ff90d31 ! 1:  78f7d02 record attachments' dropping/truncation as txns
    @@ -1,6 +1,6 @@
     Author: sunnavy <sunnavy at bestpractical.com>
     
    -    record attachments' dropping/truncation as SystemWarning txn
    +    record attachments' dropping/truncation as txns
     
     diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
     --- a/lib/RT/Attachment.pm
    @@ -19,7 +19,7 @@
     +
     +        my $txn = RT::Transaction->new( RT->SystemUser );
     +        $txn->Load($args{'TransactionId'});
    -+        if ( $txn->Type =~ /^System/ ) {
    ++        if ( $txn->Type =~ /SystemError|Attachment(?:Truncate|Drop)/ ) {
     +            $encoding = 'none';
     +            $type = $Attachment->mime_type;
     +            $content  = $Attachment->bodyhandle->as_string;
    @@ -38,13 +38,7 @@
     -        unless ($id) {
     +        if ($id) {
     +            if ($note_args) {
    -+                my $object = $self->TransactionObj->Object;
    -+                if ( $object && $object->can('_RecordNote') ) {
    -+                    $object->_RecordNote(%$note_args);
    -+                }
    -+                else {
    -+                    $RT::Logger->error( ref($object) . " doesn't support _RecordNote" );
    -+                }
    ++                $self->TransactionObj->Object->_NewTransaction( %$note_args );
     +            }
     +        }
     +        else {
    @@ -69,83 +63,73 @@
      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.
    ++is truncated or dropped. It's a hashref which is expected to be passed to
    ++L<RT::Record/_NewTransaction>.
     +
      =cut
      
      sub _EncodeLOB {
     @@
    -         my $Body = shift;
    -         my $MIMEType = shift || '';
    -         my $Filename = shift;
    -+        my $TransactionId = shift;
    +     my $Filename = shift;
      
    -         my $ContentEncoding = 'none';
    -+        my $note_args;
    +     my $ContentEncoding = 'none';
    ++    my $note_args;
      
    -         #get the max attachment length from RT
    -         my $MaxSize = RT->Config->Get('MaxAttachmentSize');
    +     #get the max attachment length from RT
    +     my $MaxSize = RT->Config->Get('MaxAttachmentSize');
     @@
    -         }
    +     #if the attachment is larger than the maximum size
    +     if ( ($MaxSize) and ( $MaxSize < length($Body) ) ) {
      
    -         #if the attachment is larger than the maximum size
    --        if ( ($MaxSize) and ( $MaxSize < length($Body) ) ) {
    -+        my $check_size = $MaxSize && $MaxSize < length($Body);
    ++        my $size = length $Body;
    +         # if we're supposed to truncate large attachments
    +         if (RT->Config->Get('TruncateLongAttachments')) {
    + 
    ++            $RT::Logger->info("$self: Truncated an attachment of size $size");
     +
    -+        if ( $check_size ) {
    +             # truncate the attachment to that length.
    +             $Body = substr( $Body, 0, $MaxSize );
    ++            $note_args = {
    ++                Type           => 'AttachmentTruncate',
    ++                Data           => defined $Filename ? $Filename : 'Content',
    ++                OldValue       => $size,
    ++                NewValue       => $MaxSize,
    ++                ActivateScrips => 0,
    ++            };
      
    -+            my $size = length($Body);
    -             # if we're supposed to truncate large attachments
    -             if (RT->Config->Get('TruncateLongAttachments')) {
    -+                $RT::Logger->info("$self: Truncated an attachment of size $size");
    -+                my $note = ( defined $Filename ? $Filename : 'content' )
    -+                  . " was truncated because its size($size) exceeds max size setting($MaxSize).";
    - 
    -                 # truncate the attachment to that length.
    -                 $Body = substr( $Body, 0, $MaxSize );
    - 
    -+                $note_args = {
    -+                    NoteType => 'SystemWarning',
    -+                    Content => $note,
    -+                };
    -+
    -             }
    - 
    -             # elsif we're supposed to drop large attachments on the floor,
    -             elsif (RT->Config->Get('DropLongAttachments')) {
    - 
    -                 # drop the attachment on the floor
    --                $RT::Logger->info( "$self: Dropped an attachment of size "
    --                                   . length($Body));
    -+                $RT::Logger->info("$self: Dropped an attachment of size $size");
    -                 $RT::Logger->info( "It started: " . substr( $Body, 0, 60 ) );
    --                $Filename .= ".txt" if $Filename;
    --                return ("none", "Large attachment dropped", "text/plain", $Filename );
    -+
    -+                my $note =
    -+                    ( defined $Filename ? $Filename : 'content' )
    -+                  . " was dropped because its size($size) exceeds max size setting($MaxSize).";
    -+
    -+                $note_args = {
    -+                    NoteType => 'SystemWarning',
    -+                    Content => $note,
    -+                };
    -+
    -+                $Filename .= ".txt" if $Filename && $Filename !~ /\.txt$/;
    -+                return ( "none", "Large attachment dropped", "plain/text", $Filename, $note_args );
    -             }
              }
      
     @@
    +         elsif (RT->Config->Get('DropLongAttachments')) {
    + 
    +             # drop the attachment on the floor
    +-            $RT::Logger->info( "$self: Dropped an attachment of size "
    +-                               . length($Body));
    ++            $RT::Logger->info( "$self: Dropped an attachment of size $size" );
    +             $RT::Logger->info( "It started: " . substr( $Body, 0, 60 ) );
    +-            $Filename .= ".txt" if $Filename;
    +-            return ("none", "Large attachment dropped", "text/plain", $Filename );
    ++            $note_args = {
    ++                Type           => 'AttachmentDrop',
    ++                Data           => defined $Filename ? $Filename : 'Content',
    ++                OldValue       => $size,
    ++                NewValue       => $MaxSize,
    ++                ActivateScrips => 0,
    ++            };
    ++            $Filename .= ".txt" if $Filename && $Filename !~ /\.txt$/;
    ++            return ("none", "Large attachment dropped", "text/plain", $Filename, $note_args );
              }
    +     }
    + 
    +@@
    +     }
      
      
    --        return ($ContentEncoding, $Body, $MIMEType, $Filename );
    -+        return ($ContentEncoding, $Body, $MIMEType, $Filename, $note_args );
    - 
    +-    return ($ContentEncoding, $Body, $MIMEType, $Filename );
    ++    return ($ContentEncoding, $Body, $MIMEType, $Filename, $note_args );
      }
      
    + =head2 _DecodeLOB C<ContentType>, C<ContentEncoding>, C<Content>
     
     diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
     --- a/lib/RT/Transaction.pm
    @@ -154,9 +138,15 @@
              my $self = shift;
              return ("System error"); #loc()
          },
    -+    SystemWarning => sub {
    ++    AttachmentTruncate => sub {
     +        my $self = shift;
    -+        return ("System warning"); #loc()
    ++        return ( "[_1] truncated because its size ([_2] bytes) exceeded configured maximum size setting ([_3] bytes).",
    ++            $self->Data // loc( "Content" ), $self->OldValue, $self->NewValue ); #loc()
    ++    },
    ++    AttachmentDrop => sub {
    ++        my $self = shift;
    ++        return ( "[_1] dropped because its size ([_2] bytes) exceeded configured maximum size setting ([_3] bytes).",
    ++            $self->Data // loc( "Content" ), $self->OldValue, $self->NewValue ); #loc()
     +    },
          "Forward Transaction" => sub {
              my $self = shift;
2:  6b61083 ! 2:  fd5c6fa test attachment dropping/truncation
    @@ -51,7 +51,7 @@
     +$m->submit;
     +is( $m->status, 200, "request successful" );
     +
    -+$m->content_contains( "$name was dropped", 'dropped message' );
    ++$m->content_contains( "$name dropped because its size (1010 bytes) exceeded configured maximum size setting (1000 bytes).", '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' );
    @@ -107,7 +107,7 @@
     +$m->submit;
     +is( $m->status, 200, "request successful" );
     +
    -+$m->content_contains( "$name was truncated", 'truncated message' );
    ++$m->content_contains( "$name truncated because its size (1010 bytes) exceeded configured maximum size setting (1000 bytes).", '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" } );
    @@ -116,3 +116,4 @@
     +
     +undef $m;
     +done_testing;
    +
-:  ------- > 3:  4e962ae make attachment truncate/drop and error txns more noticeable



More information about the rt-commit mailing list