[Rt-commit] [rtir] 01/02: RT 4.2 introduced improved attachment handling

Kevin Falcone falcone at bestpractical.com
Mon Apr 14 13:00:51 EDT 2014


This is an automated email from the git hooks/post-receive script.

falcone pushed a commit to branch 3.2/attachment-handling
in repository rtir.

commit 3f423a632369056b11d883b9363fc5505a54ef08
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Mon Apr 14 11:16:29 2014 -0400

    RT 4.2 introduced improved attachment handling
    
    The largest change was that rather than using $session{'Attachments'} RT
    now uses a per-form token to store attachments.  The old code which
    would delete from session{'Attachments'} and manually pass to
    ProcessUpdateMessage is unnecessary, as is the manual session frobbing
    perpetrated by RTIR/Create.html:ProcessAttachments.  We can just delete
    that code and make RTIR use the core ProcessAttachments code.
    
    The only complexity comes on bulk-update pages where we now pass
    KeepAttachments and then manually delete the relevant attachments after
    we're done.
    
    This code does not touch the attachment handling in ScriptedActions.
    
    This core code change also seems to clear the way for our "Create
    Incident AND Launch Investigation" workflow to support attachments on
    both tickets being created.  Ticket #29745 has been created to track
    this possible feature.
---
 html/RTIR/Create.html                      | 44 ++----------------------------
 html/RTIR/Display.html                     |  5 ++--
 html/RTIR/Edit.html                        |  2 --
 html/RTIR/Incident/BulkAbandon.html        |  7 +++--
 html/RTIR/Incident/Create.html             |  3 +-
 html/RTIR/Incident/Display.html            |  5 ++--
 html/RTIR/Incident/Reply/index.html        |  8 ++++--
 html/RTIR/Investigation/Elements/Create    |  2 --
 html/RTIR/Update.html                      |  4 +--
 lib/RT/Condition/RTIR_LinkingToIncident.pm | 17 ++++++++----
 t/009-attachments-processing.t             |  2 +-
 11 files changed, 32 insertions(+), 67 deletions(-)

diff --git a/html/RTIR/Create.html b/html/RTIR/Create.html
index f3f6019..9bd79ce 100644
--- a/html/RTIR/Create.html
+++ b/html/RTIR/Create.html
@@ -65,6 +65,7 @@
 <form action="<% RT->Config->Get('WebPath') %>/RTIR/Split.html" method="post" enctype="multipart/form-data" name="TicketCreate">
 % }
 <input type="hidden" name="id" value="new" />
+<input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
 <input type="hidden" name="Queue" value="<% $Queue %>" />
 % if ( $Split ) {
 <input type="hidden" name="Split" value="<% $SplitObj->id %>" />
@@ -404,7 +405,7 @@ if ( @Incident > 1 && !$children_config->{'Multiple'} ) {
 
 $Subject ||= $IncidentObj[0]->Subject if @IncidentObj;
 
-push @results, $m->comp( 'SELF:ProcessAttachments', %ARGS );
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my $gnupg_widget = $m->comp('/Elements/Crypt/SignEncryptWidget:new', Arguments => \%ARGS );
 $m->comp( '/Elements/Crypt/SignEncryptWidget:Process',
@@ -503,44 +504,3 @@ $QuoteTransaction => undef
 
 $Split            => undef
 </%ARGS>
-
-<%METHOD ProcessAttachments>
-<%ARGS>
- at DeleteAttachments => ()
-$Attachment => '';
-</%ARGS>
-<%INIT>
-
-my @results;
-
-# deal with deleting uploaded attachments
-foreach (
-    grep $_ && exists $session{'Attachments'}{ $_ },
-    @DeleteAttachments,
-    map { /^DeleteAttach-(.*)$/; $1 } keys %ARGS,
-) {
-    delete $session{'Attachments'}{ $_ };
-    push @results, loc("Deleted attachment '[_1]'", $_ );
-    $session{'i'}++;
-}
-
-# store the uploaded attachment in session
-foreach my $field ( 'Attach', 'Attachment' ) {
-    next unless $ARGS{ $field };
-
-    my $filename = "$ARGS{ $field }";
-    $filename =~ s{^.*[\\/]}{};
-
-    my $entity = MakeMIMEEntity(
-        AttachmentFieldName => $field,
-    );
-    $session{'Attachments'}{ $filename } = $entity;
-    push @results, loc("Added attachment '[_1]'", $filename );
-    $session{'i'}++;
-}
-
-delete $session{'Attachments'} if $session{'Attachments'} && !%{ $session{'Attachments'} };
-
-return @results;
-</%INIT>
-</%METHOD>
diff --git a/html/RTIR/Display.html b/html/RTIR/Display.html
index 1af9079..86c8e61 100644
--- a/html/RTIR/Display.html
+++ b/html/RTIR/Display.html
@@ -164,7 +164,7 @@ if ( $id eq 'new' ) {
     unless ($QueueObj->CurrentUserHasRight('CreateTicket')) {
         Abort('You have no permission to create tickets in that queue.');
     }
-    ($Ticket, @results) = CreateTicket( %ARGS, Attachments => delete $session{'Attachments'} );
+    ($Ticket, @results) = CreateTicket( %ARGS );
 } elsif( $id ) {
     
     $m->callback(
@@ -195,8 +195,7 @@ if ( $id eq 'new' ) {
         }
     }
 
-    $ARGS{UpdateAttachments} = delete $session{'Attachments'};
-    push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS );
+    push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS, Actions => \@results );
 
     push @results, ProcessTicketBasics(  TicketObj => $Ticket, ARGSRef => \%ARGS );
 
diff --git a/html/RTIR/Edit.html b/html/RTIR/Edit.html
index 303d710..1c3a681 100644
--- a/html/RTIR/Edit.html
+++ b/html/RTIR/Edit.html
@@ -214,8 +214,6 @@ if ( $SaveChanges && !$checks_failure && !$OnlySearchForPeople ) {
 
     push @results, ProcessTicketDates(    TicketObj => $Ticket, ARGSRef => \%ARGS );
 
-    # XXX: edit page has no message box or attachments form
-    $ARGS{UpdateAttachments} = delete $session{'Attachments'};
     push @results, ProcessUpdateMessage(  TicketObj => $Ticket, ARGSRef=>\%ARGS );
     push @results, ProcessTicketBasics(   TicketObj => $Ticket, ARGSRef => \%ARGS );
 
diff --git a/html/RTIR/Incident/BulkAbandon.html b/html/RTIR/Incident/BulkAbandon.html
index 8b872dc..a63724b 100644
--- a/html/RTIR/Incident/BulkAbandon.html
+++ b/html/RTIR/Incident/BulkAbandon.html
@@ -106,10 +106,9 @@ my $Status = 'abandoned';
 
 my ( @results );
 
-$m->comp( '/RTIR/Create.html:ProcessAttachments', %ARGS );
+ProcessAttachments( ARGSRef => \%ARGS );
 
 if ( $ARGS{'BulkAbandon'} ) {
-    $ARGS{'UpdateAttachments'} = delete $session{'Attachments'};
 
     my @tempresults;
     foreach my $id ( @SelectedTickets ) {
@@ -133,10 +132,12 @@ if ( $ARGS{'BulkAbandon'} ) {
             );
             while ( my $child = $children->Next ) {
                 push @tempresults, ProcessUpdateMessage(
-                    TicketObj => $child, ARGSRef => \%ARGS,
+                    TicketObj => $child, ARGSRef => \%ARGS, KeepAttachments => 1
                 );
             }
         }
+        # manually clear this out since we told ProcessUpdateMessage to KeepAttachments
+        delete $session{'Attachments'}{ $ARGS{'Token'} };
 
         # process status updates
         {
diff --git a/html/RTIR/Incident/Create.html b/html/RTIR/Incident/Create.html
index 9f11a67..0c30a81 100644
--- a/html/RTIR/Incident/Create.html
+++ b/html/RTIR/Incident/Create.html
@@ -72,6 +72,7 @@ if ( $ChildObj && !$ChildObj->CurrentUserHasRight('ModifyTicket') ) {
 % }
 
 <input type="hidden" name="id"           value="new" />
+<input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
 <input type="hidden" name="Queue"        value="<% $QueueObj->Name       || '' %>" />
 % if ( $ChildObj ) {
 <input type="hidden" name="Child"        value="<% $Child %>" />
@@ -308,7 +309,7 @@ $m->callback(
 my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
 $QueueObj->Load( 'Incidents' ) || Abort( loc("Queue could not be loaded.") );
 
-$m->comp( '/RTIR/Create.html:ProcessAttachments', %ARGS );
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my $checks_failure = 0;
 
diff --git a/html/RTIR/Incident/Display.html b/html/RTIR/Incident/Display.html
index ca8bbbc..e4215dc 100644
--- a/html/RTIR/Incident/Display.html
+++ b/html/RTIR/Incident/Display.html
@@ -203,7 +203,7 @@ if ( $id eq 'new' ) {
     unless( $QueueObj->Name eq 'Incidents' ) {
         return $m->comp('/RTIR/Display.html', %ARGS );
     }
-    ($TicketObj, @results) = CreateTicket( %ARGS, Attachments => delete $session{'Attachments'} );
+    ($TicketObj, @results) = CreateTicket( %ARGS );
     $new_ticket = 1;
 } else {
     $TicketObj = LoadTicket( $id );
@@ -264,8 +264,7 @@ if ( $ARGS{'BulkArticles'} && @SelectedTickets ) {
 }
 
 unless( $new_ticket ) {
-    $ARGS{UpdateAttachments} = delete $session{'Attachments'};
-    push @results, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    push @results, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $TicketObj, Actions => \@results );
 }
 
 MaybeRedirectForResults(
diff --git a/html/RTIR/Incident/Reply/index.html b/html/RTIR/Incident/Reply/index.html
index ca3253d..a42bdcc 100644
--- a/html/RTIR/Incident/Reply/index.html
+++ b/html/RTIR/Incident/Reply/index.html
@@ -59,6 +59,7 @@
 
 <form action="index.html" name="TicketUpdate" method="post" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<% $id %>" />
+<input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
 <input type="hidden" name="Status" value="<% $Status %>" />
 <input type="hidden" name="All" value="<% $All %>" />
 <input type="hidden" name="Query" value="<% $Query %>" />
@@ -132,7 +133,7 @@ $m->callback( %ARGS, CallbackName => 'Initial', Ticket => $IncidentObj );
 
 $Status = '' if $Status && $Status eq $IncidentObj->Status;
 
-$m->comp( '/RTIR/Create.html:ProcessAttachments', %ARGS );
+ProcessAttachments( ARGSRef => \%ARGS );
 
 my $checks_failure = 0;
 
@@ -164,14 +165,13 @@ if ( $SubmitTicket && $gnupg_widget ) {
 }
 
 if ( $SubmitTicket && !$checks_failure ) {
-    $ARGS{'UpdateAttachments'} = delete $session{'Attachments'};
 
     my $incident_cycle = $IncidentObj->QueueObj->Lifecycle;
     foreach my $Ticket ( @selected_children ) {
         my $id = $Ticket->id;
 
         push @results, map { loc("Ticket [_1]: [_2]", $id, $_) }
-            ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS );
+            ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS, KeepAttachments => 1 );
 
         my %additional = (
             Status => RT::IR->MapStatus( $Status, $incident_cycle => $Ticket ),
@@ -184,6 +184,8 @@ if ( $SubmitTicket && !$checks_failure ) {
             );
         }
     }
+    # manually clear this out since we told ProcessUpdateMessage to KeepAttachments
+    delete $session{'Attachments'}{ $ARGS{'Token'} };
 
     my $update_incident_state = 1;
     if ( $Status && $incident_cycle->IsInactive( $Status ) ) {
diff --git a/html/RTIR/Investigation/Elements/Create b/html/RTIR/Investigation/Elements/Create
index 88f4149..169dab3 100644
--- a/html/RTIR/Investigation/Elements/Create
+++ b/html/RTIR/Investigation/Elements/Create
@@ -305,11 +305,9 @@ if ( ($DefaultsNamePrefix||'') ne $NamePrefix ) {
 }
 
 my ($Ticket, @results) = CreateTicket(
-    Attachments => $session{'Attachments'},
     %ARGS,
 );
 
-delete $session{'Attachments'} if $Ticket;
 return ($Ticket, @results);
 </%INIT>
 </%METHOD>
diff --git a/html/RTIR/Update.html b/html/RTIR/Update.html
index 3025b85..c52a99c 100644
--- a/html/RTIR/Update.html
+++ b/html/RTIR/Update.html
@@ -53,6 +53,7 @@
 
 <form action="Update.html" name="TicketUpdate" method="post" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<% $id %>" />
+<input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
 <input type="hidden" name="QuoteTransaction" value="<% $ARGS{'QuoteTransaction'} || '' %>" />
 <input type="hidden" name="Status" value="<% $Status || '' %>" />
 <input type="hidden" name="Action" value="<% $Action || '' %>" />
@@ -181,8 +182,7 @@ $CanRespond = 1 if ( $Ticket->CurrentUserHasRight('ReplyToTicket') or
 $CanComment = 1 if ( $Ticket->CurrentUserHasRight('CommentOnTicket') or
                      $Ticket->CurrentUserHasRight('ModifyTicket') ); 
 
-
-$m->comp( '/RTIR/Create.html:ProcessAttachments', %ARGS );
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my (@results, $checks_failure);
 
diff --git a/lib/RT/Condition/RTIR_LinkingToIncident.pm b/lib/RT/Condition/RTIR_LinkingToIncident.pm
index 99da652..d93e03a 100644
--- a/lib/RT/Condition/RTIR_LinkingToIncident.pm
+++ b/lib/RT/Condition/RTIR_LinkingToIncident.pm
@@ -68,11 +68,18 @@ sub IsApplicable {
 
     my $field = $self->TransactionObj->Field;
     if ( $type eq 'AddLink' && $field eq 'MemberOf' ) {
-        my ($status, $msg, $parent) = $self->TicketObj->__GetTicketFromURI(
-            URI => $self->TransactionObj->NewValue
-        );
-        unless ( $parent && $parent->id ) {
-            RT->Logger->error( "Couldn't load linked ticket #". $self->TransactionObj->NewValue );
+        my $uri = RT::URI->new($self->TicketObj->CurrentUser);
+        my ($status, $msg) = $uri->FromURI( $self->TransactionObj->NewValue );
+        unless ( $status ) {
+            RT->Logger->debug("Couldn't load link ". $self->transactionObj->NewValue . "$msg");
+        }
+
+        # don't bother running on something that can't be a ticket
+        return unless $uri->IsLocal;
+
+        my $parent = $uri->Object;
+        unless ( $parent && $parent->id && $parent->isa('RT::Ticket') ) {
+            RT->Logger->error( "Couldn't load linked ticket #". $self->TransactionObj->NewValue ." $msg");
             return 0;
         }
         return $parent->QueueObj->Name eq 'Incidents';
diff --git a/t/009-attachments-processing.t b/t/009-attachments-processing.t
index b537263..395e985 100644
--- a/t/009-attachments-processing.t
+++ b/t/009-attachments-processing.t
@@ -96,7 +96,7 @@ $agent->goto_create_rtir_ticket('Incident Reports');
     $agent->content_like( qr/\Q$filename/, "has file name on the page");
 
     $agent->form_number(3);
-    $agent->tick('DeleteAttach-'. $filename, 1);
+    $agent->tick('DeleteAttach', $filename);
     $agent->click('AddMoreAttach');
     is($agent->status, 200, "request successful");
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list