
sunnavy at bestpractical
Jul 4, 2012, 9:46 AM
Post #1 of 1
(114 views)
Permalink
|
|
rt branch, 4.2/custom-ticket-forward, created. rt-4.0.6-336-g60627db
|
|
The branch, 4.2/custom-ticket-forward has been created at 60627dbbd937ddf2ee4039af467271b40b523c5d (commit) - Log ----------------------------------------------------------------- commit 053de934ee19a396f31942dbb363cbd3c30409a5 Author: sunnavy <sunnavy [at] bestpractical> Date: Wed Jul 4 04:50:31 2012 +0800 customize forward message in ticket forward page to archive this, we added a textarea filled with default forward message which is extracted from the corresponding template. diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm index 86d0abd..6579023 100644 --- a/lib/RT/Interface/Email.pm +++ b/lib/RT/Interface/Email.pm @@ -625,7 +625,14 @@ Forwards transaction with all attachments as 'message/rfc822'. sub ForwardTransaction { my $txn = shift; - my %args = ( To => '', Cc => '', Bcc => '', @_ ); + my %args = ( + Content => undef, + ContentType => 'text/plain', + To => '', + Cc => '', + Bcc => '', + @_ + ); my $entity = $txn->ContentAsMIME; @@ -652,7 +659,14 @@ Forwards a ticket's Create and Correspond Transactions and their Attachments as sub ForwardTicket { my $ticket = shift; - my %args = ( To => '', Cc => '', Bcc => '', @_ ); + my %args = ( + Content => undef, + ContentType => 'text/plain', + To => '', + Cc => '', + Bcc => '', + @_ + ); my $txns = $ticket->Transactions; $txns->Limit( @@ -698,11 +712,15 @@ Forwards an Entity representing Ticket or Transaction as 'message/rfc822'. Entit sub SendForward { my (%args) = ( - Entity => undef, - Ticket => undef, + Content => undef, + ContentType => 'text/plain', + Entity => undef, + Ticket => undef, Transaction => undef, - Template => 'Forward', - To => '', Cc => '', Bcc => '', + Template => 'Forward', + To => '', + Cc => '', + Bcc => '', @_ ); @@ -717,7 +735,8 @@ sub SendForward { return (0, $ticket->loc("Couldn't send email")); } - my ($template, $msg) = PrepareEmailUsingTemplate( + my $mail; + my ( $template, $msg ) = PrepareEmailUsingTemplate( Template => $args{'Template'}, Arguments => { Ticket => $ticket, @@ -725,26 +744,48 @@ sub SendForward { }, ); - my $mail; - if ( $template ) { + if ($template) { $mail = $template->MIMEObj; - } else { + } + else { $RT::Logger->warning($msg); } - unless ( $mail ) { - $RT::Logger->warning("Couldn't generate email using template '$args{Template}'"); - my $description; - unless ( $args{'Transaction'} ) { - $description = 'This is forward of ticket #'. $ticket->id; - } else { - $description = 'This is forward of transaction #' - . $txn->id ." of a ticket #". $txn->ObjectId; + if ( $args{'Content'} ) { + if ($mail) { + my $io = $mail->bodyhandle->open("w"); + $io->print( $args{'Content'} ); + $io->close; + $mail->head->set( 'Content-Type' => $args{'ContentType'} ); + } + else { + $mail = MIME::Entity->build( + Type => $args{'ContentType'}, + Data => $args{'Content'}, + ); + } + } + else { + unless ($mail) { + $RT::Logger->warning( + "Couldn't generate email using template '$args{Template}'"); + + my $description; + unless ( $args{'Transaction'} ) { + $description = 'This is forward of ticket #' . $ticket->id; + } + else { + $description = + 'This is forward of transaction #' + . $txn->id + . " of a ticket #" + . $txn->ObjectId; + } + $mail = MIME::Entity->build( + Type => 'text/plain', + Data => $description, + ); } - $mail = MIME::Entity->build( - Type => 'text/plain', - Data => $description, - ); } $mail->head->set( $_ => EncodeToMIME( String => $args{$_} ) ) @@ -801,6 +842,44 @@ sub GetForwardFrom { } } +=head2 GetForwardDefaultContent Ticket => undef, Transaction => undef + +Resolve the Content to use in forward mail + +=cut + +sub GetDefaultForwardContent { + my %args = ( Ticket => undef, Transaction => undef, @_ ); + my $txn = $args{Transaction}; + my $ticket = $args{Ticket} || $txn->Object; + + my ( $template, $msg ) = PrepareEmailUsingTemplate( + Template => $txn ? 'Forward' : 'Forward Ticket', + Arguments => { + Ticket => $ticket, + Transaction => $txn, + }, + ); + + if ($template) { + return $template->MIMEObj->stringify_body(); + } + else { + $RT::Logger->warning($msg); + + if ($txn) { + return 'This is forward of ticket #' . $ticket->id; + } + else { + return + 'This is forward of transaction #' + . $txn->id + . " of a ticket #" + . $txn->ObjectId; + } + } +} + =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0 Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well diff --git a/share/html/Ticket/Forward.html b/share/html/Ticket/Forward.html index 8aa75c7..63f7d02 100644 --- a/share/html/Ticket/Forward.html +++ b/share/html/Ticket/Forward.html @@ -72,6 +72,13 @@ <tr><td align="right"><&|/l&>Bcc</&>:</td> <td><input name="Bcc" size="60" value="<% $ARGS{'Bcc'} || '' %>" /></td></tr> +<tr> +<td><&|/l&>Content</&>:</td> +<td> +<& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &> +</td> +</tr> + </table> <& /Elements/Submit, Label => loc('Forward Message and Return'), Name => 'ForwardAndReturn' &> @@ -119,6 +126,11 @@ my $subject = $TicketObj->Subject; $subject = RT::Interface::Email::AddSubjectTag( $subject, $TicketObj ) unless RT->Config->Get('ForwardFromUser'); +$ARGS{Content} ||= RT::Interface::Email::GetDefaultForwardContent( + Ticket => $TicketObj, + $txn ? ( Transaction => $txn ) : (), +); + </%INIT> <%ARGS> commit 60627dbbd937ddf2ee4039af467271b40b523c5d Author: sunnavy <sunnavy [at] bestpractical> Date: Thu Jul 5 00:20:38 2012 +0800 list attachments to be forward diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm index 6579023..8bc68e6 100644 --- a/lib/RT/Interface/Email.pm +++ b/lib/RT/Interface/Email.pm @@ -880,6 +880,36 @@ sub GetDefaultForwardContent { } } +=head2 GetForwardAttachments Ticket => undef, Transaction => undef + +Resolve the Attachments to forward + +=cut + +sub GetForwardAttachments { + my %args = ( Ticket => undef, Transaction => undef, @_ ); + my $txn = $args{Transaction}; + my $ticket = $args{Ticket} || $txn->Object; + + my $attachments = RT::Attachments->new( $ticket->CurrentUser ); + if ($txn) { + $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id ); + } + else { + my $txns = $ticket->Transactions; + $txns->Limit( + FIELD => 'Type', + VALUE => $_, + ) for qw(Create Correspond); + + while ( my $txn = $txns->Next ) { + $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id ); + } + } + return $attachments; +} + + =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0 Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well diff --git a/share/html/Ticket/Forward.html b/share/html/Ticket/Forward.html index 63f7d02..f337bfb 100644 --- a/share/html/Ticket/Forward.html +++ b/share/html/Ticket/Forward.html @@ -81,6 +81,8 @@ </table> +<& /Ticket/Elements/ShowAttachments, Attachments => $attachments &> + <& /Elements/Submit, Label => loc('Forward Message and Return'), Name => 'ForwardAndReturn' &> <& /Elements/Submit, Label => loc('Forward Message'), Name => 'Forward' &> </form> @@ -131,6 +133,11 @@ $ARGS{Content} ||= RT::Interface::Email::GetDefaultForwardContent( $txn ? ( Transaction => $txn ) : (), ); +my $attachments = RT::Interface::Email::GetForwardAttachments( + Ticket => $TicketObj, + $txn ? ( Transaction => $txn ) : (), +); + </%INIT> <%ARGS> ----------------------------------------------------------------------- _______________________________________________ Rt-commit mailing list Rt-commit [at] lists http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit
|