Thanks Eric for all your help.  Worked great.

Karen

Schultz, Eric wrote:
I would like to warn the user before dropping a large 
      
attachment and 
    
give them the opportunity to make a different selection.
I saw this in an earlier email (dated 2006-02-24 from Eric Shultz 
"TruncateLongAttachments .."), where he had modified the RT 
code to do 
just that.  I've been attempting to do the same thing in 
      
Update.html, 
    
but failing.  I can't seem to determine the filesize with the 
information at hand.  Can anyone point me in the right 
direction?  Or is 
Update.html not the place to be making these changes?
      
Hi Karen.  Unfortunately, I've made a bunch of other changes to the
3.4.x code, so I can't easily provide you with just a simple patch.
What I can provide is the code I added for this 
functionality, however,
and at about what point in the file share/html/Ticket/Update.html.
Note, however, that I did not set TruncateLongAttachments in
RT_SiteConfig.pm, I set DropLongAttachments to 1.  Here are 
my changes:

#1:
-----------
  <& /Ticket/Elements/Tabs,
      Ticket => $TicketObj,
      Title=> $title &>

+ <& /Elements/ListActions, actions => [EMAIL PROTECTED] &>
+
  <FORM ACTION="" NAME="TicketUpdate"
        METHOD=POST enctype="multipart/form-data">
  <input type="hidden" name="QuoteTransaction" value="<%
$ARGS{QuoteTransaction} %>">
-----------

#2:
-----------
  <%INIT>
  my $CanRespond = 0;
  my $CanComment = 0;
  my $title;
+ my @Actions;

  my $TicketObj = LoadTicket($id);

-----------

#3:
-----------
      $session{'Attachments'} = { %{$session{'Attachments'} || {}},
                                $ARGS{'Attach'} => $attachment };
+
+     my $latest_attach = $ARGS{'Attach'};
+
+     # Check the length of all attachments put together, compensating
+     # for encoding overhead (* .75) like is done elsewhere in the
code.
+     my $total_length = 0;
+     foreach my $key (keys %{$session{'Attachments'}}) {
+       my $length = length(
${$session{'Attachments'}}{$key}->stringify_body );
+         $total_length += int($length * .75 / 1024);
+     }
+
+     # If the total of all attachments exceeds the RT config 
parameter,
+     # and we're told to drop long attachments, drop all of them.
+     # But still allow a message update.
+     my $maxsize = int($RT::MaxAttachmentSize * .75 / 1024);
+     if ($total_length > $maxsize and $RT::DropLongAttachments) {
+       $RT::Logger->warning( "Exceeded maximum attachment size. Total
length: ${total_length}k (max: ${maxsize}k)" );
+       push( @Actions, "Attachment '$latest_attach' not 
uploaded: total
size of all attachments (${total_length}k) would exceed limit
(${maxsize}k)" );
+       delete ${$session{'Attachments'}}{$latest_attach};  # remove
only the latest one that tipped the scales
+         delete $ARGS{SubmitTicket};  # don't go to the Display.html
page
+     }
  }
  # }}}

  # delete temporary storage entry to make WebUI clean
  unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
      delete $session{'Attachments'};
-----------


Let me know how that works for you.

Eric Schultz
United Online, Inc.
    


I neglected to mention that I also do pretty much the same thing in
Create.html, so people can't make a ticket with too large of an
attachment.  The only difference is I have a commitme flag:

my $commitme = 1;

If the $total_length exceeds $maxsize, I set $commitme = 0, then later I
have this:

if ( $commitme and (!exists $ARGS{'AddMoreAttach'}) && ($ARGS{'id'} eq
'new')) {

So I don't go to Display.html yet (giving them another opportunity to
attach something smaller).


Eric Schultz
United Online, Inc.

  
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com

Reply via email to