[Rt-commit] rt branch, 4.4/preview-batch, created. rt-4.2.5-190-g5cf9d5d

Alex Vandiver alexmv at bestpractical.com
Wed Jul 30 14:12:43 EDT 2014


The branch, 4.4/preview-batch has been created
        at  5cf9d5d19e2de2eab6698317659ebb7f2ff9da1e (commit)

- Log -----------------------------------------------------------------
commit 55d5a91856b6318f95532cd73140e1b137c495db
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 11 15:28:54 2014 -0400

    Sync the ckeditor output before updating messages
    
    This allows the updates to the content to be respected in the data seen
    by Scrips.

diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 73c7318..039efec 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -214,6 +214,7 @@
 <script type="text/javascript">
 jQuery( function() {
    var updateScrips = function() {
+       CKEDITOR.instances['UpdateContent'].updateElement();
        var syncCheckboxes = function(ev) {
            jQuery("input[name=TxnSendMailTo]").filter( function() { return this.value == ev.target.value; } ).prop("checked",jQuery(ev.target).prop('checked'));
        };
@@ -227,6 +228,7 @@ jQuery( function() {
        );
    };
    updateScrips();
+   CKEDITOR.instances['UpdateContent'].on('blur', updateScrips );
    jQuery("#ticket-update-metadata :input, input[name^=UpdateCc], input[name^=UpdateBcc]").change( updateScrips );
 });
 </script>

commit e8d4433ce415c9d1429e611ce6f5db90f14809ef
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 11 15:15:23 2014 -0400

    Roll back on failure to Comment, as Correspond does

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f039357..0f1b511 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1461,8 +1461,9 @@ sub Comment {
     }
 
     my @results = $self->_RecordNote(%args);
-    if ($args{'DryRun'}) {
-        $RT::Handle->Rollback();
+
+    if ( not $results[0] or $args{'DryRun'}) {
+        $RT::Handle->RollBack();
     } else {
         $RT::Handle->Commit();
     }

commit c8a24b11f0d73bda663931942912eb207d55284d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 11 15:20:08 2014 -0400

    DryRun now wraps in a rollback, and records all transactions
    
    DryRun was previously limited to only running correspond or comment
    transactions.  Change it to take a block of actions to run, which it
    wraps in a transaction and rolls back at the end.  By additionally
    tracking all transaction objects are created on the ticket, more changes
    can be simulated, and TransactionBatch changes can be found.
    
    Note that only transactionbatch scrips directly triggered by user
    changes are visible -- as scrips are not committed, TransactionBatch
    changes which would be recorded because of those indirect changes will
    not be visible.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 10fec3b..55b79de 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2070,7 +2070,7 @@ sub CreateTicket {
 
     my (@Actions);
 
-    my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
+    my $Ticket = delete $ARGS{TicketObj} || RT::Ticket->new( $session{'CurrentUser'} );
 
     my $Queue = RT::Queue->new( $session{'CurrentUser'} );
     unless ( $Queue->Load( $ARGS{'Queue'} ) ) {
@@ -2153,20 +2153,12 @@ sub CreateTicket {
         TransSquelchMailTo => $ARGS{'TransSquelchMailTo'},
     );
 
-    if ($ARGS{'DryRun'}) {
-        $create_args{DryRun} = 1;
-        $create_args{Owner}     ||= $RT::Nobody->Id;
-        $create_args{Requestor} ||= $session{CurrentUser}->EmailAddress;
-        $create_args{Subject}   ||= '';
-        $create_args{Status}    ||= $Queue->Lifecycle->DefaultOnCreate,
-    } else {
-        my @txn_squelch;
-        foreach my $type (qw(Requestor Cc AdminCc)) {
-            push @txn_squelch, map $_->address, Email::Address->parse( $create_args{$type} )
-                if grep $_ eq $type || $_ eq ( $type . 's' ), @{ $ARGS{'SkipNotification'} || [] };
-        }
-        push @{$create_args{TransSquelchMailTo}}, @txn_squelch;
+    my @txn_squelch;
+    foreach my $type (qw(Requestor Cc AdminCc)) {
+        push @txn_squelch, map $_->address, Email::Address->parse( $create_args{$type} )
+            if grep $_ eq $type || $_ eq ( $type . 's' ), @{ $ARGS{'SkipNotification'} || [] };
     }
+    push @{$create_args{TransSquelchMailTo}}, @txn_squelch;
 
     if ( $ARGS{'AttachTickets'} ) {
         require RT::Action::SendEmail;
@@ -2184,7 +2176,6 @@ sub CreateTicket {
     my %links = ProcessLinksForCreate( ARGSRef => \%ARGS );
 
     my ( $id, $Trans, $ErrMsg ) = $Ticket->Create(%create_args, %links, %cfs);
-    return $Trans if $ARGS{DryRun};
 
     unless ($id) {
         Abort($ErrMsg);
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 37c40b0..69fd236 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1641,7 +1641,6 @@ sub _NewTransaction {
         Field     => undef,
         MIMEObj   => undef,
         ActivateScrips => 1,
-        CommitScrips => 1,
         SquelchMailTo => undef,
         @_
     );
@@ -1680,7 +1679,7 @@ sub _NewTransaction {
         ReferenceType => $ref_type,
         MIMEObj   => $args{'MIMEObj'},
         ActivateScrips => $args{'ActivateScrips'},
-        CommitScrips => $args{'CommitScrips'},
+        DryRun => $self->{DryRun},
         SquelchMailTo => $args{'SquelchMailTo'},
     );
 
@@ -1695,7 +1694,7 @@ sub _NewTransaction {
         $self->_UpdateTimeTaken( $args{'TimeTaken'}, Transaction => $trans );
     }
     if ( RT->Config->Get('UseTransactionBatch') and $transaction ) {
-            push @{$self->{_TransactionBatch}}, $trans if $args{'CommitScrips'};
+        push @{$self->{_TransactionBatch}}, $trans;
     }
 
     RT->DatabaseHandle->Commit unless $in_txn;
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 0f1b511..618fb22 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -237,7 +237,6 @@ sub Create {
         Resolved           => undef,
         MIMEObj            => undef,
         _RecordTransaction => 1,
-        DryRun             => 0,
         @_
     );
 
@@ -540,7 +539,6 @@ sub Create {
             Type         => "Create",
             TimeTaken    => $args{'TimeWorked'},
             MIMEObj      => $args{'MIMEObj'},
-            CommitScrips => !$args{'DryRun'},
             SquelchMailTo => $args{'TransSquelchMailTo'},
         );
 
@@ -560,10 +558,6 @@ sub Create {
             return ( 0, 0, $self->loc( "Ticket could not be created due to an internal error"));
         }
 
-        if ( $args{'DryRun'} ) {
-            $RT::Handle->Rollback();
-            return ($self->id, $TransObj, $ErrStr);
-        }
         $RT::Handle->Commit();
         return ( $self->Id, $TransObj->Id, $ErrStr );
     }
@@ -1428,10 +1422,7 @@ Takes a hash with the following attributes:
 If MIMEObj is undefined, Content will be used to build a MIME::Entity for this
 comment.
 
-MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content, DryRun
-
-If DryRun is defined, this update WILL NOT BE RECORDED. Scrips will not be committed.
-They will, however, be prepared and you'll be able to access them through the TransactionObj
+MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content
 
 Returns: Transaction id, Error Message, Transaction Object
 (note the different order from Create()!)
@@ -1446,7 +1437,6 @@ sub Comment {
                  MIMEObj      => undef,
                  Content      => undef,
                  TimeTaken => 0,
-                 DryRun     => 0, 
                  @_ );
 
     unless (    ( $self->CurrentUserHasRight('CommentOnTicket') )
@@ -1456,16 +1446,13 @@ sub Comment {
     $args{'NoteType'} = 'Comment';
 
     $RT::Handle->BeginTransaction();
-    if ($args{'DryRun'}) {
-        $args{'CommitScrips'} = 0;
-    }
 
     my @results = $self->_RecordNote(%args);
 
-    if ( not $results[0] or $args{'DryRun'}) {
-        $RT::Handle->RollBack();
+    if ( not $results[0] ) {
+        $RT::Handle->Rollback();
     } else {
-        $RT::Handle->Commit();
+        $RT::Handle->Commit;
     }
 
     return(@results);
@@ -1478,13 +1465,10 @@ Correspond on this ticket.
 Takes a hashref with the following attributes:
 
 
-MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content, DryRun
+MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content
 
 if there's no MIMEObj, Content is used to build a MIME::Entity object
 
-If DryRun is defined, this update WILL NOT BE RECORDED. Scrips will not be committed.
-They will, however, be prepared and you'll be able to access them through the TransactionObj
-
 Returns: Transaction id, Error Message, Transaction Object
 (note the different order from Create()!)
 
@@ -1507,9 +1491,6 @@ sub Correspond {
     $args{'NoteType'} = 'Correspond';
 
     $RT::Handle->BeginTransaction();
-    if ($args{'DryRun'}) {
-        $args{'CommitScrips'} = 0;
-    }
 
     my @results = $self->_RecordNote(%args);
 
@@ -1527,11 +1508,7 @@ sub Correspond {
             if grep {not $squelch{$_}} $self->Requestors->MemberEmailAddresses;
     }
 
-    if ($args{'DryRun'}) {
-        $RT::Handle->Rollback();
-    } else {
-        $RT::Handle->Commit();
-    }
+    $RT::Handle->Commit;
 
     return (@results);
 
@@ -1558,7 +1535,6 @@ sub _RecordNote {
         Content      => undef,
         NoteType     => 'Correspond',
         TimeTaken    => 0,
-        CommitScrips => 1,
         SquelchMailTo => undef,
         @_
     );
@@ -1620,7 +1596,6 @@ sub _RecordNote {
              Data => ( $args{'MIMEObj'}->head->get('subject') || 'No Subject' ),
              TimeTaken => $args{'TimeTaken'},
              MIMEObj   => $args{'MIMEObj'}, 
-             CommitScrips => $args{'CommitScrips'},
              SquelchMailTo => $args{'SquelchMailTo'},
     );
 
@@ -1635,89 +1610,32 @@ sub _RecordNote {
 
 =head2 DryRun
 
-Builds a MIME object from the given C<UpdateSubject> and
-C<UpdateContent>, then calls L</Comment> or L</Correspond> with
-C<< DryRun => 1 >>, and returns the transaction so produced.
 
 =cut
 
 sub DryRun {
     my $self = shift;
-    my %args = @_;
-    my $action;
-    if (($args{'UpdateType'} || $args{Action}) =~ /^respon(d|se)$/i ) {
-        $action = 'Correspond';
-    } else {
-        $action = 'Comment';
-    }
-
-    my $Message = MIME::Entity->build(
-        Type    => 'text/plain',
-        Subject => defined $args{UpdateSubject} ? Encode::encode_utf8( $args{UpdateSubject} ) : "",
-        Charset => 'UTF-8',
-        Data    => $args{'UpdateContent'} || "",
-    );
 
-    my ( $Transaction, $Description, $Object ) = $self->$action(
-        CcMessageTo  => $args{'UpdateCc'},
-        BccMessageTo => $args{'UpdateBcc'},
-        MIMEObj      => $Message,
-        TimeTaken    => $args{'UpdateTimeWorked'},
-        DryRun       => 1,
-        SquelchMailTo => $args{'SquelchMailTo'},
-    );
-    unless ( $Transaction ) {
-        $RT::Logger->error("Couldn't fire '$action' action: $Description");
-    }
+    my ($subref) = @_;
 
-    return $Object;
-}
-
-=head2 DryRunCreate
-
-Prepares a MIME mesage with the given C<Subject>, C<Cc>, and
-C<Content>, then calls L</Create> with C<< DryRun => 1 >> and returns
-the resulting L<RT::Transaction>.
-
-=cut
+    my @transactions;
 
-sub DryRunCreate {
-    my $self = shift;
-    my %args = @_;
-    my $Message = MIME::Entity->build(
-        Type    => 'text/plain',
-        Subject => defined $args{Subject} ? Encode::encode_utf8( $args{'Subject'} ) : "",
-        (defined $args{'Cc'} ?
-             ( Cc => Encode::encode_utf8( $args{'Cc'} ) ) : ()),
-        Charset => 'UTF-8',
-        Data    => $args{'Content'} || "",
-    );
-
-    my ( $Transaction, $Object, $Description ) = $self->Create(
-        Type            => $args{'Type'} || 'ticket',
-        Queue           => $args{'Queue'},
-        Owner           => $args{'Owner'},
-        Requestor       => $args{'Requestors'},
-        Cc              => $args{'Cc'},
-        AdminCc         => $args{'AdminCc'},
-        InitialPriority => $args{'InitialPriority'},
-        FinalPriority   => $args{'FinalPriority'},
-        TimeLeft        => $args{'TimeLeft'},
-        TimeEstimated   => $args{'TimeEstimated'},
-        TimeWorked      => $args{'TimeWorked'},
-        Subject         => $args{'Subject'},
-        Status          => $args{'Status'},
-        MIMEObj         => $Message,
-        DryRun          => 1,
-    );
-    unless ( $Transaction ) {
-        $RT::Logger->error("Couldn't fire Create action: $Description");
+    $RT::Handle->BeginTransaction();
+    {
+        # Getting nested "commit"s inside this rollback is fine
+        local %DBIx::SearchBuilder::Handle::TRANSROLLBACK;
+        local $self->{DryRun} = \@transactions;
+        eval { $subref->() };
+        warn "Error is $@" if $@;
+        $self->ApplyTransactionBatch;
     }
 
-    return $Object;
-}
+    @transactions = grep {$_} @transactions;
 
+    $RT::Handle->Rollback();
 
+    return wantarray ? @transactions : $transactions[0];
+}
 
 sub _Links {
     my $self = shift;
@@ -2591,7 +2509,8 @@ sub _ApplyTransactionBatch {
     my $types = join ',', grep !$seen{$_}++, grep defined, map $_->__Value('Type'), grep defined, @{$batch};
 
     require RT::Scrips;
-    RT::Scrips->new(RT->SystemUser)->Apply(
+    my $scrips = RT::Scrips->new(RT->SystemUser);
+    $scrips->Prepare(
         Stage          => 'TransactionBatch',
         TicketObj      => $self,
         TransactionObj => $batch->[0],
@@ -2605,7 +2524,16 @@ sub _ApplyTransactionBatch {
         TransactionObj => $batch->[0],
         Type           => $types,
     );
-    RT::Ruleset->CommitRules($rules);
+
+    if ($self->{DryRun}) {
+        my $fake_txn = RT::Transaction->new( $self->CurrentUser );
+        $fake_txn->{scrips} = $scrips;
+        $fake_txn->{rules} = $rules;
+        push @{$self->{DryRun}}, $fake_txn;
+    } else {
+        $scrips->Commit;
+        RT::Ruleset->CommitRules($rules);
+    }
 }
 
 sub DESTROY {
@@ -3039,8 +2967,6 @@ sub Forward {
         Bcc            => '',
         Content        => '',
         ContentType    => 'text/plain',
-        DryRun         => 0,
-        CommitScrips   => 1,
         @_
     );
 
@@ -3071,11 +2997,6 @@ sub Forward {
         )
     );
 
-    if ($args{'DryRun'}) {
-        $RT::Handle->BeginTransaction();
-        $args{'CommitScrips'} = 0;
-    }
-
     my ( $ret, $msg ) = $self->_NewTransaction(
         $args{Transaction}
         ? (
@@ -3088,16 +3009,12 @@ sub Forward {
         ),
         Data  => join( ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc} ),
         MIMEObj => $mime,
-        CommitScrips => $args{'CommitScrips'},
     );
 
     unless ($ret) {
         $RT::Logger->error("Failed to create transaction: $msg");
     }
 
-    if ($args{'DryRun'}) {
-        $RT::Handle->Rollback();
-    }
     return ( $ret, $self->loc('Message recorded') );
 }
 
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index f6df440..e04ff62 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -118,7 +118,7 @@ sub Create {
         NewValue       => undef,
         MIMEObj        => undef,
         ActivateScrips => 1,
-        CommitScrips   => 1,
+        DryRun         => undef,
         ObjectType     => 'RT::Ticket',
         ObjectId       => 0,
         ReferenceType  => undef,
@@ -182,6 +182,8 @@ sub Create {
         return @return;
     }
 
+    push @{$args{DryRun}}, $self if $args{DryRun};
+
     $self->{'scrips'} = RT::Scrips->new(RT->SystemUser);
 
     $RT::Logger->debug('About to prepare scrips for transaction #' .$self->Id); 
@@ -206,7 +208,7 @@ sub Create {
         TransactionObj => $txn,
    );
 
-    if ($args{'CommitScrips'} ) {
+    unless ($args{DryRun} ) {
         $RT::Logger->debug('About to commit scrips for transaction #' .$self->Id);
         $self->{'scrips'}->Commit();
         RT::Ruleset->CommitRules($rules);
diff --git a/share/html/Elements/Crypt/SignEncryptWidget b/share/html/Elements/Crypt/SignEncryptWidget
index f11c0aa..165210c 100644
--- a/share/html/Elements/Crypt/SignEncryptWidget
+++ b/share/html/Elements/Crypt/SignEncryptWidget
@@ -159,11 +159,13 @@ if ( $self->{'Encrypt'} ) {
     my @recipients;
 
     if ( $Operation eq 'Update' ) {
-        @recipients = $TicketObj->DryRun(%$self)->Recipients;
+        @recipients = map {$_->Recipients} $TicketObj->DryRun(
+            sub { ProcessUpdateMessage( ARGSRef => {%$self}, TicketObj => $TicketObj ) } );
     }
     elsif ( $Operation eq 'Create' ) {
         $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
-        @recipients = $TicketObj->DryRunCreate(%$self)->Recipients;
+        @recipients = map {$_->Recipients} $TicketObj->DryRun(
+            sub { CreateTicket( %$self, TicketObj => $TicketObj ); } );
     }
     else {
         $RT::Logger->crit('Incorrect operation: '. $Operation );
diff --git a/share/html/Helpers/PreviewScrips b/share/html/Helpers/PreviewScrips
index 8cceb89..4ec0ab3 100644
--- a/share/html/Helpers/PreviewScrips
+++ b/share/html/Helpers/PreviewScrips
@@ -60,7 +60,18 @@ else {
       unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
 }
 
-my $Object = $TicketObj->DryRun(%ARGS);
+my $Object = $TicketObj->DryRun(
+    sub {
+        local $ARGS{UpdateContent} ||= "Content";
+        ProcessUpdateMessage(ARGSRef  => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketWatchers(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    }
+);
 my %recips;
 $m->abort unless $Object;
 
diff --git a/share/html/Helpers/ShowSimplifiedRecipients b/share/html/Helpers/ShowSimplifiedRecipients
index 26d5ead..87e14a3 100644
--- a/share/html/Helpers/ShowSimplifiedRecipients
+++ b/share/html/Helpers/ShowSimplifiedRecipients
@@ -61,7 +61,18 @@ else {
       unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
 }
 
-my $Object = $TicketObj->DryRun(%ARGS);
+my $Object = $TicketObj->DryRun(
+    sub {
+        local $ARGS{UpdateContent} ||= "Content";
+        ProcessUpdateMessage(ARGSRef  => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketWatchers(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
+        ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
+    }
+);
 $m->abort unless $Object;
 
 my %headers = (To => {}, Cc => {}, Bcc => {});
diff --git a/share/html/Ticket/ModifyPeople.html b/share/html/Ticket/ModifyPeople.html
index ff004fc..bda19d4 100644
--- a/share/html/Ticket/ModifyPeople.html
+++ b/share/html/Ticket/ModifyPeople.html
@@ -108,7 +108,13 @@ unless ($OnlySearchForPeople or $OnlySearchForGroup) {
 }
 
 # Use the ticket's scrips to figure out the new list of recipients.
-my @txns = grep {defined} map {$Ticket->DryRun( Action => $_ )} qw/comment respond/;
+my @txns = $Ticket->DryRun(
+    sub {
+        my $MIME = MIME::Entity->build( Type => "text/plain", Data => "" );
+        $Ticket->Comment(MIMEObj => $MIME);
+        $Ticket->Correspond(MIMEObj => $MIME);
+    }
+);
 my %recips=();
 for my $scrip (map {@{$_->Scrips->Prepared}} @txns) {
     next unless $scrip->ActionObj->Action->isa('RT::Action::SendEmail');
diff --git a/t/web/gnupg-select-keys-on-create.t b/t/web/gnupg-select-keys-on-create.t
index e30b264..0e90373 100644
--- a/t/web/gnupg-select-keys-on-create.t
+++ b/t/web/gnupg-select-keys-on-create.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Test::GnuPG tests => 79, gnupg_options => { passphrase => 'rt-test' };
+use RT::Test::GnuPG tests => undef, gnupg_options => { passphrase => 'rt-test' };
 use RT::Action::SendEmail;
 
 my $queue = RT::Test->load_or_create_queue(
@@ -66,7 +66,7 @@ diag "check that things don't work if there is no key";
     my @mail = RT::Test->fetch_caught_mails;
     ok !@mail, 'there are no outgoing emails';
 
-    $m->next_warning_like(qr/public key not found/) for 1 .. 4;
+    $m->next_warning_like(qr/public key not found/) for 1 .. 2;
     $m->no_leftover_warnings_ok;
 }
 
@@ -273,3 +273,5 @@ diag "check encrypting of attachments";
     $m->no_warnings_ok;
 }
 
+undef $m;
+done_testing;

commit c948e50ad98d0b6401c396148e5169d07f8d8811
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 11 15:25:49 2014 -0400

    Display all scrips which are triggered
    
    Adjust the PreviewScrips and SimplifiedRecipients code to account for
    multiple transactions.

diff --git a/share/html/Helpers/PreviewScrips b/share/html/Helpers/PreviewScrips
index 4ec0ab3..ef7db09 100644
--- a/share/html/Helpers/PreviewScrips
+++ b/share/html/Helpers/PreviewScrips
@@ -60,7 +60,7 @@ else {
       unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
 }
 
-my $Object = $TicketObj->DryRun(
+my @dryrun = $TicketObj->DryRun(
     sub {
         local $ARGS{UpdateContent} ||= "Content";
         ProcessUpdateMessage(ARGSRef  => \%ARGS, TicketObj => $TicketObj );
@@ -73,7 +73,7 @@ my $Object = $TicketObj->DryRun(
     }
 );
 my %recips;
-$m->abort unless $Object;
+$m->abort unless @dryrun;
 
 my %squelched = ProcessTransactionSquelching( \%ARGS );
 </%init>
@@ -82,13 +82,9 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 &>Uncheck boxes to disable notifications to the listed recipients <b>for this transaction only</b>; persistent squelching is managed on the <a href="[_1]">People page</a>.</&>
 </p>
 
-% if ( $Object->Scrips ) {
-%     # Sort scrips with recipients before those without
-%     my @scrips = map { $_->[0] }
-%                  sort { ($b->[1]?1:0) <=> ($a->[1]?1:0) }
-%                  map { [$_, $_->ActionObj->Action->To + $_->ActionObj->Action->Cc + $_->ActionObj->Action->Bcc] }
-%                  grep {$_->ActionObj->Action->isa('RT::Action::SendEmail')}
-%                  @{$Object->Scrips->Prepared};
+% my @scrips = grep {$_->ActionObj->Action->isa('RT::Action::SendEmail')}
+%              map {@{$_->Scrips->Prepared}} @dryrun;
+% if (@scrips) {
 %     for my $scrip (@scrips) {
           <b><% $scrip->Description || loc('Scrip #[_1]',$scrip->id) %></b><br />
           <&|/l, loc($scrip->ConditionObj->Name), loc($scrip->ActionObj->Name), loc($scrip->Template)&>[_1] [_2] with template [_3]</&>
@@ -134,8 +130,9 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 %     }
 % }
 
-% if ( $Object->Rules ) {
-%     for my $rule (@{$Object->Rules}) {
+% my @rules = map {@{$_->Rules}} @dryrun;
+% if ( @rules ) {
+%     for my $rule (@rules) {
 %         next unless $rule->{hints} && $rule->{hints}{class} eq 'SendEmail';
           <b><% $rule->Describe %></b>
 %         my $data = $rule->{hints}{recipients};
@@ -161,4 +158,4 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 % $m->callback( CallbackName => 'AfterRecipients', TicketObj => $TicketObj );
 
 <input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %recips %>" />
-% $m->abort();
\ No newline at end of file
+% $m->abort();
diff --git a/share/html/Helpers/ShowSimplifiedRecipients b/share/html/Helpers/ShowSimplifiedRecipients
index 87e14a3..68e86cc 100644
--- a/share/html/Helpers/ShowSimplifiedRecipients
+++ b/share/html/Helpers/ShowSimplifiedRecipients
@@ -61,7 +61,7 @@ else {
       unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
 }
 
-my $Object = $TicketObj->DryRun(
+my @dryrun = $TicketObj->DryRun(
     sub {
         local $ARGS{UpdateContent} ||= "Content";
         ProcessUpdateMessage(ARGSRef  => \%ARGS, TicketObj => $TicketObj );
@@ -73,12 +73,13 @@ my $Object = $TicketObj->DryRun(
         ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
     }
 );
-$m->abort unless $Object;
+$m->abort unless @dryrun;
 
 my %headers = (To => {}, Cc => {}, Bcc => {});
 my %no_squelch = (To => {}, Cc => {}, Bcc => {});
-if ($Object->Scrips) {
-    for my $scrip (grep $_->ActionObj->Action->isa('RT::Action::SendEmail'), @{$Object->Scrips->Prepared}) {
+my @scrips = map {@{$_->Scrips->Prepared}} @dryrun;
+if (@scrips) {
+    for my $scrip (grep $_->ActionObj->Action->isa('RT::Action::SendEmail'), @scrips) {
         my $action = $scrip->ActionObj->Action;
         for my $type (qw(To Cc Bcc)) {
             for my $addr ($action->$type()) {
@@ -91,8 +92,9 @@ if ($Object->Scrips) {
         }
     }
 }
-if ($Object->Rules) {
-    for my $rule (grep {$_->{hints} and $_->{hints}{class} eq "SendEmail"} @{$Object->Rules}) {
+my @rules = map {@{$_->Rules}} @dryrun;
+if (@rules) {
+    for my $rule (grep {$_->{hints} and $_->{hints}{class} eq "SendEmail"} @rules) {
         for my $type (qw(To Cc Bcc)) {
             $headers{$type}{$_} ||= @{[Email::Address->parse($_)]}[0] # Hate list context
                 for @{$rule->{hints}{recipients}{$type}};

commit 4a33c6625ffe2507aff33383dbb57d2636c28b22
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 11 16:38:16 2014 -0400

    Re-use squelching information for future updates to a ticket in same request
    
    Prior to this, information about squelching was only associated with the
    initial correspond/comment, and not later changes (such as On Owner
    Change), nor TransactionBatch scrips.  When updating tickets via the
    web, store the squelching details on the the ticket object, and re-use
    them for the lifetime of the object -- that is, the checkboxes now seen
    in PreviewScrips for TransactionBatch changes are now effective.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 55b79de..3782a62 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2378,6 +2378,8 @@ sub _ProcessUpdateMessageRecipients {
     $message_args->{SquelchMailTo} = \@txn_squelch
         if @txn_squelch;
 
+    $args{TicketObj}->{TransSquelchMailTo} ||= $message_args->{'SquelchMailTo'};
+
     unless ( $args{'ARGSRef'}->{'UpdateIgnoreAddressCheckboxes'} ) {
         foreach my $key ( keys %{ $args{ARGSRef} } ) {
             next unless $key =~ /^Update(Cc|Bcc)-(.*)$/;
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 69fd236..dc1f750 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1680,7 +1680,7 @@ sub _NewTransaction {
         MIMEObj   => $args{'MIMEObj'},
         ActivateScrips => $args{'ActivateScrips'},
         DryRun => $self->{DryRun},
-        SquelchMailTo => $args{'SquelchMailTo'},
+        SquelchMailTo => $args{'SquelchMailTo'} || $self->{TransSquelchMailTo},
     );
 
     # Rationalize the object since we may have done things to it during the caching.

commit 5cf9d5d19e2de2eab6698317659ebb7f2ff9da1e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jul 23 13:47:42 2014 -0400

    Remove mostly-duplicate code for Rules which can never trigger
    
    PreviewScrips includes a mostly-duplicated block of code to preview
    emails produced by Rules, the mechanism behind Approvals.  However, this
    code is unnecessary because /Ticket/Update.html is not accessible for
    tickets of type 'approval' (the only objects which could currently
    trigger Rules in a stock RT), because /Tickets/autohandler redirects all
    but a small number of files under /Tickets/ to /Approvals/ instead.
    /Ticket/Update.html is not in the whitelist, and thus cannot render for
    Approvals.
    
    Furthermore, the code checks $rule->{hints}{class} to determine if it
    should display the rule; no rule ever has a ->{hints} set on it, and
    never has, since the introduction of this code in 6d14f535.  As such,
    even if /Ticket/Update.html were accessible, or some local customization
    made use of Rules for something other than Approvals, they would still
    not appear in PreviewScrips.
    
    Remove the duplicated and unused code.

diff --git a/share/html/Helpers/PreviewScrips b/share/html/Helpers/PreviewScrips
index ef7db09..a27c8f7 100644
--- a/share/html/Helpers/PreviewScrips
+++ b/share/html/Helpers/PreviewScrips
@@ -130,31 +130,6 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 %     }
 % }
 
-% my @rules = map {@{$_->Rules}} @dryrun;
-% if ( @rules ) {
-%     for my $rule (@rules) {
-%         next unless $rule->{hints} && $rule->{hints}{class} eq 'SendEmail';
-          <b><% $rule->Describe %></b>
-%         my $data = $rule->{hints}{recipients};
-%         for my $type (qw(To Cc Bcc)) {
-%             next unless @{$data->{$type}};
-              <ul>
-%             for my $address (@{$data->{$type}}) {
-                  <li>
-%                 my $checked = not $squelched{$address};
-%                 $m->callback(CallbackName => 'BeforeAddress', Ticket => $TicketObj, Address => Email::Address->parse($address), Type => $type, Checked => \$checked);
-%                 $recips{$address}++;
-                  <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$address%>" id="TxnSendMailTo-<% $address %>-<% $recips{$address} %>" />
-                  <label for="TxnSendMailTo-<% $address %>-<% $recips{$address} %>"><%$address%></label>
-%                 $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => Email::Address->parse($address), Type => $type);
-                  </li>
-%             }
-              </ul>
-%         }
-          <br />
-%     }
-% }
-
 % $m->callback( CallbackName => 'AfterRecipients', TicketObj => $TicketObj );
 
 <input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %recips %>" />
diff --git a/share/html/Helpers/ShowSimplifiedRecipients b/share/html/Helpers/ShowSimplifiedRecipients
index 68e86cc..4c6b60c 100644
--- a/share/html/Helpers/ShowSimplifiedRecipients
+++ b/share/html/Helpers/ShowSimplifiedRecipients
@@ -92,15 +92,6 @@ if (@scrips) {
         }
     }
 }
-my @rules = map {@{$_->Rules}} @dryrun;
-if (@rules) {
-    for my $rule (grep {$_->{hints} and $_->{hints}{class} eq "SendEmail"} @rules) {
-        for my $type (qw(To Cc Bcc)) {
-            $headers{$type}{$_} ||= @{[Email::Address->parse($_)]}[0] # Hate list context
-                for @{$rule->{hints}{recipients}{$type}};
-        }
-    }
-}
 my %recips;
 my %squelched = ProcessTransactionSquelching( \%ARGS );
 </%init>

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


More information about the rt-commit mailing list