[Rt-commit] rt branch, 4.0/selfservice-attach-more, created. rt-4.0.11rc1-7-g0ba6836

? sunnavy sunnavy at bestpractical.com
Sun Mar 31 02:57:15 EDT 2013


The branch, 4.0/selfservice-attach-more has been created
        at  0ba68363661f89bc4e52a3ed69cf512dd6ca7af2 (commit)

- Log -----------------------------------------------------------------
commit 36d49987e2302f5af523a3fddea46bb173681f3b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Mar 31 13:14:59 2013 +0800

    abstract attachments handling into HTML::Mason::Commands::ProcessAttachments
    
    there is a bit difference for "delete $session{'Attachments'}" between pages,
    e.g.
    
    in create page:
    
        unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
            delete $session{'Attachments'};
        }
    
    in update pages:
    
        unless (keys %{ $session{'Attachments'} } and $ARGS{'UpdateAttach'}) {
            delete $session{'Attachments'};
        }
    
    I chose to check $ARGS{'UpdateAttach'} consistently for all the pages.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 7c78548..2b8b4c7 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2046,6 +2046,37 @@ sub _ProcessUpdateMessageRecipients {
     }
 }
 
+sub ProcessAttachments {
+    my %args = (
+        ARGSRef => {},
+        @_
+    );
+
+    my $ARGSRef = $args{ARGSRef} || {};
+    # deal with deleting uploaded attachments
+    foreach my $key ( keys %$ARGSRef ) {
+        if ( $key =~ m/^DeleteAttach-(.+)$/ ) {
+            delete $session{'Attachments'}{$1};
+        }
+        $session{'Attachments'} = { %{ $session{'Attachments'} || {} } };
+    }
+
+    # store the uploaded attachment in session
+    if ( defined $ARGSRef->{'Attach'} && length $ARGSRef->{'Attach'} )
+    {    # attachment?
+        my $attachment = MakeMIMEEntity( AttachmentFieldName => 'Attach' );
+
+        my $file_path = Encode::decode_utf8("$ARGSRef->{'Attach'}");
+        $session{'Attachments'} =
+          { %{ $session{'Attachments'} || {} }, $file_path => $attachment, };
+    }
+
+    # delete temporary storage entry to make WebUI clean
+    unless ( keys %{ $session{'Attachments'} } and $ARGSRef->{'UpdateAttach'} )
+    {
+        delete $session{'Attachments'};
+    }
+}
 
 
 =head2 MakeMIMEEntity PARAMHASH
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index 51a9c9d..18bd76f 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -228,31 +228,7 @@ map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
 
 my (@results);
 
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-        delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
-    delete $session{'Attachments'};
-}
+ProcessAttachments(ARGSRef => \%ARGS);
 
 $Page ||= 1;
 
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index ad0023f..9e708a4 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -361,31 +361,7 @@ my $ValidCFs = $m->comp(
     ARGSRef => \%ARGS
 );
 
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-	delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-	$file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
-    delete $session{'Attachments'};
-}
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my $checks_failure = 0;
 
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 01ecb90..c5bb6bb 100644
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -152,32 +152,7 @@ $CanRespond = 1 if ( $Ticket->CurrentUserHasRight('ReplyToTicket') or
 $CanComment = 1 if ( $Ticket->CurrentUserHasRight('CommentOnTicket') or
                      $Ticket->CurrentUserHasRight('ModifyTicket') );
 
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-        delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
-    delete $session{'Attachments'};
-}
-
+ProcessAttachments(ARGSRef => \%ARGS);
 
 $m->callback( TicketObj => $Ticket, ARGSRef => \%ARGS );
 my @results;
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 1e07bf8..36f325a 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -242,31 +242,7 @@ $CanComment = 1 if ( $TicketObj->CurrentUserHasRight('CommentOnTicket') or
                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
 
 
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-        delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
-    delete $session{'Attachments'};
-}
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index de3eb7f..9fd04e4 100644
--- a/share/html/m/ticket/create
+++ b/share/html/m/ticket/create
@@ -155,31 +155,7 @@ my $ValidCFs = $m->comp(
     ARGSRef => \%ARGS
 );
 
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-	delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-	$file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
-    delete $session{'Attachments'};
-}
+ProcessAttachments(ARGSRef => \%ARGS);
 
 my $checks_failure = 0;
 
@@ -344,7 +320,9 @@ $showrows->(
     loc("Attach file") =>
 
         '<input type="file" name="Attach" />
-<input type="submit" class="button" name="AddMoreAttach" value="' . loc("Add More Files") . '" />'
+<input type="submit" class="button" name="AddMoreAttach" value="' . loc("Add More Files") . '" />
+<input type="hidden" class="hidden" name="UpdateAttach" value="1" />
+'
 );
 </%perl>
 
diff --git a/share/html/m/ticket/reply b/share/html/m/ticket/reply
index 45ae6fa..d3b0f6f 100644
--- a/share/html/m/ticket/reply
+++ b/share/html/m/ticket/reply
@@ -132,6 +132,7 @@
 <div class="value">
 <input type="file" name="Attach" />
 <input type="submit" class="button" name="AddMoreAttach" value="<% loc("Add More Files") %>" />
+<input type="hidden" class="hidden" name="UpdateAttach" value="1" />
 </div>
 </div>
 
@@ -190,34 +191,7 @@ $CanRespond = 1 if ( $t->CurrentUserHasRight('ReplyToTicket') or
 $CanComment = 1 if ( $t->CurrentUserHasRight('CommentOnTicket') or
                      $t->CurrentUserHasRight('ModifyTicket') ); 
 
-
-# deal with deleting uploaded attachments
-foreach my $key (keys %ARGS) {
-    if ($key =~ m/^DeleteAttach-(.+)$/) {
-        delete $session{'Attachments'}{$1};
-    }
-    $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
-}
-
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{$session{'Attachments'} || {}},
-        $file_path => $attachment,
-    };
-}
-
-# delete temporary storage entry to make WebUI clean
-unless ( keys %{ $session{'Attachments'} }
-    && ( exists $ARGS{'AddMoreAttach'} || exists $ARGS{'SubmitTicket'} ) )
-{
-    delete $session{'Attachments'};
-}
+ProcessAttachments(ARGSRef => \%ARGS);
 
 # check email addresses for RT's
 {

commit 0ba68363661f89bc4e52a3ed69cf512dd6ca7af2
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Feb 27 20:41:35 2012 +0800

    attach more files support for self service

diff --git a/share/html/SelfService/Create.html b/share/html/SelfService/Create.html
index 43d4b7b..76126ae 100644
--- a/share/html/SelfService/Create.html
+++ b/share/html/SelfService/Create.html
@@ -91,16 +91,7 @@
         <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $queue_obj &>
     </td>
 </tr>
-<tr>
-<td class="label">
-%# FIXME: if failed customfields validation, attachement needs to be choosen
-%# again by user.
-<&|/l&>Attach file</&>:
-</td>
-<td class="value">
-<input name="Attach" type="file" />
-</td>
-</tr>
+<& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $queue_obj &>
 </table>
 <table width="100%">
 <tr>
@@ -128,10 +119,12 @@ my $ValidCFs = $m->comp(
     ARGSRef => \%ARGS
 );
 
+ProcessAttachments(ARGSRef => \%ARGS);
+
 my $skip_create = 0;
 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, results => \@results );
 
-if ( defined($ARGS{'id'}) and $ARGS{'id'} eq 'new' ) { # new ticket?
+if ( !exists $ARGS{'AddMoreAttach'} and defined($ARGS{'id'}) and $ARGS{'id'} eq 'new' ) { # new ticket?
     if ( $ValidCFs && !$skip_create ) {
         $m->comp('Display.html', %ARGS);
         $RT::Logger->crit("After display call; error is $@");
diff --git a/share/html/SelfService/Display.html b/share/html/SelfService/Display.html
index b701c49..857ebfa 100644
--- a/share/html/SelfService/Display.html
+++ b/share/html/SelfService/Display.html
@@ -100,21 +100,6 @@ my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
 
 my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
 
-# store the uploaded attachment in session
-if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
-    $session{'Attachments'} = {} unless defined $session{'Attachments'};
-
-    my $attachment = MakeMIMEEntity(
-        AttachmentFieldName => 'Attach'
-    );
-
-    my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
-    $session{'Attachments'} = {
-        %{ $session{'Attachments'} || {} },
-        $file_path => $attachment,
-    };
-}
-
 if ( defined ($id[0]) && $id[0] eq 'new' ) {
 
     # {{{ Create a new ticket
@@ -134,19 +119,12 @@ if ( defined ($id[0]) && $id[0] eq 'new' ) {
 
 
     ( $Ticket, @results ) =
-    CreateTicket( Attachments => $session{'Attachments'}, %ARGS );
+    CreateTicket( Attachments => delete $session{'Attachments'}, %ARGS );
 
     unless ( $Ticket->id ) {
         $m->comp( 'Error.html', Why => join( "\n", @results ));
               $m->abort();
         }
-
-
-        # delete temporary storage entry to make WebUI clean
-        unless ( keys %{ $session{'Attachments'} } and $ARGS{'UpdateAttach'} ) {
-            delete $session{'Attachments'};
-        }
-
     }
     else {
         unless ( $Ticket->Load( $id[0] ) ) {
@@ -172,12 +150,7 @@ if ( defined ($id[0]) && $id[0] eq 'new' ) {
         ARGSRef   => \%ARGS,
         TicketObj => $Ticket
     );
-            delete $session{'Attachments'};
-
-    # delete temporary storage entry to make WebUI clean
-    unless ( keys %{ $session{'Attachments'} } and $ARGS{'UpdateAttach'} ) {
-        delete $session{'Attachments'};
-    }
+    delete $session{'Attachments'};
 
     my @cfupdates = ProcessObjectCustomFieldUpdates(Object => $Ticket, ARGSRef => \%ARGS);
     push (@results, @cfupdates);
diff --git a/share/html/SelfService/Update.html b/share/html/SelfService/Update.html
index 4d449a0..603f1fc 100644
--- a/share/html/SelfService/Update.html
+++ b/share/html/SelfService/Update.html
@@ -51,7 +51,8 @@
 
 % $m->callback(CallbackName => 'BeforeForm', %ARGS, ARGSRef => \%ARGS, Ticket => $Ticket );
 
-<form action="Display.html" method="post" enctype="multipart/form-data">
+<form action="Update.html" method="post" enctype="multipart/form-data">
+<input type="hidden" class="hidden" name="QuoteTransaction" value="<% $ARGS{QuoteTransaction}||'' %>" />
 <input type="hidden" class="hidden" name="UpdateType" value="response" />
 <input type="hidden" class="hidden" name="id" value="<%$Ticket->Id%>" />
 <table width="100%">
@@ -68,21 +69,27 @@
             <&|/l&>Subject</&>
         </td>
         <td class="value">
-            <input name="UpdateSubject" size="60" value="<% $Ticket->Subject %>" />
+            <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || $Ticket->Subject || '' %>" />
         </td>
 
     </tr>
     <& /Ticket/Elements/AddAttachments, %ARGS, TicketObj => $Ticket &>
     <tr><td colspan="2"><& /Ticket/Elements/EditCustomFields,  TicketObj => $Ticket &></td></tr>
 </table>
-<& /Elements/MessageBox, 
-    Name => "UpdateContent", 
-    QuoteTransaction => $ARGS{QuoteTransaction} 
-    &>
+% if (exists $ARGS{UpdateContent}) {
+% # preserve QuoteTransaction so we can use it to set up sane references/in/reply to
+% my $temp = $ARGS{'QuoteTransaction'};
+% delete $ARGS{'QuoteTransaction'};
+<& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&>
+% $ARGS{'QuoteTransaction'} = $temp;
+% } else {
+% my $IncludeSignature = 1;
+<& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &>
+% }
     <br />
 
 
-<& /Elements/Submit &>
+<& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket', id => 'SubmitTicket' &>
   </form>
 
 
@@ -102,7 +109,36 @@ Abort( loc("No permission to view update ticket") )
   unless ( $Ticket->CurrentUserHasRight('ReplyToTicket')
     or $Ticket->CurrentUserHasRight('ModifyTicket') );
 
-$m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%ARGS);
+my @results;
+
+ProcessAttachments(ARGSRef => \%ARGS);
+
+my $checks_failure;
+if ( $ARGS{'SubmitTicket'} ) {
+    my $CFs = $Ticket->TransactionCustomFields;
+    my $ValidCFs = $m->comp(
+        '/Elements/ValidateCustomFields',
+        CustomFields => $CFs,
+        NamePrefix => "Object-RT::Transaction--CustomField-",
+        ARGSRef => \%ARGS
+    );
+    unless ( $ValidCFs ) {
+        $checks_failure = 1;
+        while (my $CF = $CFs->Next) {
+            my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
+            push @results, loc($CF->Name) . ': ' . $msg;
+        }
+    }
+}
+
+my $skip_update = 0;
+$m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update,
+              checks_failure => $checks_failure, results => \@results, TicketObj => $Ticket );
+
+if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
+    $m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%ARGS);
+    return $m->comp('Display.html', TicketObj => $Ticket, %ARGS);
+}
 </%INIT>
 
 <%ARGS>

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


More information about the Rt-commit mailing list