[Rt-commit] rt branch, squelch, created. rt-3.8.8-302-g25792ac

Alex Vandiver alexmv at bestpractical.com
Thu Aug 12 17:22:17 EDT 2010


The branch, squelch has been created
        at  25792acd72a7afb4c538c0a449edb59afb726553 (commit)

- Log -----------------------------------------------------------------
commit 4757190e2f716db75ac15b118198c0b2195051ea
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 11 11:35:14 2010 -0400

    Allow pages to override actions on ticket pages

diff --git a/share/html/Ticket/Elements/Tabs b/share/html/Ticket/Elements/Tabs
index b1428b0..b371d72 100755
--- a/share/html/Ticket/Elements/Tabs
+++ b/share/html/Ticket/Elements/Tabs
@@ -265,6 +265,8 @@ if ( ( defined $actions->{A} || defined $actions->{B} || defined $actions->{C} )
     elsif ( defined $actions->{A} ) { $actions->{A}->{separator} = 1 }
 }
 
+$actions = $ARGS{actions} if defined $ARGS{actions};
+
 my $args = '';
 my $has_query = '';
 my %query_args;

commit 3238798a9dee1d606d5a70a7cb964789502ef2b6
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 11 11:39:12 2010 -0400

    Split ticket squelching into a sub-tab

diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 2e7b8ee..1e80b81 100755
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -45,10 +45,13 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, Title => $title &>
+<& /Elements/Header,
+    Title  => $title,
+    onload => "function () { hide(document.getElementById('Ticket-Update-squelch')) }" &>
 <& /Ticket/Elements/Tabs, 
     Ticket => $TicketObj, 
-    Title=> $title &>
+    Title=> $title,
+    actions => $actions &>
     
 % $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $TicketObj);
 <& /Elements/ListActions, actions => \@results &>
@@ -62,6 +65,9 @@
 
 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
 
+<div id="Ticket-Update-basics">
+<a name="basics"></a>
+
 <div id="ticket-update-metadata">
   <&|/Widgets/TitleBox, title => loc('Ticket and Transaction') &>
 <table width="100%" border="0">
@@ -164,6 +170,11 @@
 </&>
   <& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket', id => 'SubmitTicket' &>
 
+</div>
+</div>
+
+<div id="Ticket-Update-squelch">
+<a name="squelch"></a>
 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
   <&|/Widgets/TitleBox, title => loc('Scrips and Recipients'), id => 'previewscrips' &>
     <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
@@ -297,6 +308,15 @@ if ( !$checks_failure && exists $ARGS{SubmitTicket} ) {
     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
 }
+
+my $actions = {
+    A => {
+        html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Update-basics','Ticket-Update-squelch');">] . loc('Show basics') . q[</a>],
+    },
+    B => {
+        html => q[<a href="#squelch" onclick="return switchVisibility('Ticket-Update-squelch','Ticket-Update-basics');">] . loc('Squelch recipients') . q[</a>],
+    },
+};
 </%INIT>
 
 <%ARGS>

commit 5a5c67dc23924f2d31fe81f855bd01b007e5cb1a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 11 17:21:13 2010 -0400

    Remove dead code

diff --git a/share/html/Elements/GnuPG/SignEncryptWidget b/share/html/Elements/GnuPG/SignEncryptWidget
index 023d3b2..ad4d582 100644
--- a/share/html/Elements/GnuPG/SignEncryptWidget
+++ b/share/html/Elements/GnuPG/SignEncryptWidget
@@ -144,12 +144,6 @@ if ( $self->{'Encrypt'} ) {
 
     if ( $Operation eq 'Update' ) {
         # skip any email addresses that we won't be sending mail to
-        my %squelch = $m->comp(
-            '/Ticket/Elements/PreviewScrips:SquelchRecipients',
-            %$self,
-            TicketObj => $TicketObj
-        );
-
         @recipients = $m->comp(
             '/Ticket/Elements/PreviewScrips:GetRecipients',
             %$self, TicketObj => $TicketObj

commit 25792acd72a7afb4c538c0a449edb59afb726553
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Aug 12 17:22:48 2010 -0400

    Refactor PreviewScrips to remove Mason methods

diff --git a/lib/RT/Ticket_Overlay.pm b/lib/RT/Ticket_Overlay.pm
index a9efc46..a0ec561 100755
--- a/lib/RT/Ticket_Overlay.pm
+++ b/lib/RT/Ticket_Overlay.pm
@@ -2203,6 +2203,89 @@ 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,
+    );
+    unless ( $Transaction ) {
+        $RT::Logger->error("Couldn't fire '$action' action: $Description");
+    }
+
+    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
+
+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");
+    }
+
+    return $Object;
+}
+
 # }}}
 
 # {{{ sub _Links 
diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index 2f3ed26..fbcc947 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -1210,6 +1210,37 @@ sub CustomFieldLookupType {
 }
 
 
+=head2 Recipients
+
+Returns the list of email addresses (as L<Email::Address> objects)
+that this transaction would send mail to.  There may be duplicates.
+
+=cut
+
+sub Recipients {
+    my $self = shift;
+    my @recipients;
+    foreach my $scrip ( @{ $self->Scrips->Prepared } ) {
+        my $action = $scrip->ActionObj->Action;
+        next unless $action->isa('RT::Action::SendEmail');
+
+        foreach my $type qw(To Cc Bcc) {
+            push @recipients, $action->$type();
+        }
+    }
+
+    if ( $self->Rules ) {
+        for my $rule (@{$self->Rules}) {
+            next unless $rule->{hints} && $rule->{hints}{class} eq 'SendEmail';
+            my $data = $rule->{hints}{recipients};
+            foreach my $type qw(To Cc Bcc) {
+                push @recipients, map {Email::Address->new($_)} @{$data->{$type}};
+            }
+        }
+    }
+    return @recipients;
+}
+
 =head2 DeferredRecipients($freq, $include_sent )
 
 Takes the following arguments:
diff --git a/share/html/Elements/GnuPG/SignEncryptWidget b/share/html/Elements/GnuPG/SignEncryptWidget
index ad4d582..fe792fd 100644
--- a/share/html/Elements/GnuPG/SignEncryptWidget
+++ b/share/html/Elements/GnuPG/SignEncryptWidget
@@ -143,17 +143,11 @@ if ( $self->{'Encrypt'} ) {
     my @recipients;
 
     if ( $Operation eq 'Update' ) {
-        # skip any email addresses that we won't be sending mail to
-        @recipients = $m->comp(
-            '/Ticket/Elements/PreviewScrips:GetRecipients',
-            %$self, TicketObj => $TicketObj
-        );
+        @recipients = $TicketObj->DryRun(%$self)->Recipients;
     }
     elsif ( $Operation eq 'Create' ) {
-        @recipients = $m->comp(
-            '/Ticket/Elements/PreviewScrips:GetRecipientsOnCreate',
-            %$self,
-        );
+        $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
+        @recipients = $TicketObj->DryRunCreate(%$self)->Recipients;
     }
     else {
         $RT::Logger->crit('Incorrect operation: '. $Operation );
diff --git a/share/html/Ticket/Elements/PreviewScrips b/share/html/Ticket/Elements/PreviewScrips
index 3a117f5..8e08b40 100755
--- a/share/html/Ticket/Elements/PreviewScrips
+++ b/share/html/Ticket/Elements/PreviewScrips
@@ -47,13 +47,25 @@
 %# END BPS TAGGED BLOCK }}}
 <%args>
 $TicketObj => undef
-
 </%args>
 <%init>
-my %squelch = $m->comp('SELF:SquelchRecipients', %ARGS);
-my $Object = $squelch{'Object'};
-my @non_recipients = @{ $squelch{'EmailAddresses'} };
+my $arg = 'Ticket-'.$TicketObj->Id.'-SquelchMailTo';
+my @squelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
+
+foreach my $address (@squelchto) {
+        $TicketObj->SquelchMailTo($address) if ($address);
+}
+
+
+$arg = 'Ticket-'.$TicketObj->Id.'-UnsquelchMailTo';
+my @unsquelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
+
+foreach my $address (@unsquelchto) {
+        $TicketObj->UnsquelchMailTo($address) if ($address);
+}
 
+my $Object = $TicketObj->DryRun(%ARGS);
+my @non_recipients = $TicketObj->SquelchMailTo;
 </%init>
 <h2><&|/l&>This message will be sent to...</&></h2>
 
@@ -116,144 +128,3 @@ my @non_recipients = @{ $squelch{'EmailAddresses'} };
 % }
 </ul>
 <& /Elements/Submit, Name => 'UpdatePreview', Value => 'UpdatePreview', Label => loc('Save Changes')&>
-
-<%METHOD SquelchRecipients>
-<%ARGS>
-$TicketObj => undef
-</%ARGS>
-<%INIT>
-my $arg = 'Ticket-'.$TicketObj->Id.'-SquelchMailTo';
-my @squelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
-
-foreach my $address (@squelchto) {
-        $TicketObj->SquelchMailTo($address) if ($address);
-}
-
-
-$arg = 'Ticket-'.$TicketObj->Id.'-UnsquelchMailTo';
-my @unsquelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
-
-foreach my $address (@unsquelchto) {
-        $TicketObj->UnsquelchMailTo($address) if ($address);
-}
-
-
-my $action;
-
-if (($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' ) || ($ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' )) {
-    $action = 'Correspond';
-}
-else {
-    $action = 'Comment';
-}
-
-my $Message = MakeMIMEEntity(
-    Subject => $ARGS{'UpdateSubject'},
-    Body    => $ARGS{'UpdateContent'},
-);
-
-my ( $Transaction, $Description, $Object ) = $TicketObj->$action(
-    CcMessageTo  => $ARGS{'UpdateCc'},
-    BccMessageTo => $ARGS{'UpdateBcc'},
-    MIMEObj      => $Message,
-    TimeTaken    => $ARGS{'UpdateTimeWorked'},
-    DryRun       => 1
-);
-unless ( $Transaction ) {
-    $RT::Logger->error("Couldn't fire '$action' action: $Description");
-}
-
-
-return (Object => $Object, EmailAddresses => [$TicketObj->SquelchMailTo]);
-</%INIT>
-</%METHOD>
-
-<%METHOD GetRecipients>
-<%ARGS>
-$TicketObj
-</%ARGS>
-<%INIT>
-my $action;
-if ( ( $ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' )
-    || ( $ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' ) )
-{
-    $action = 'Correspond';
-}
-else {
-    $action = 'Comment';
-}
-
-my $Message = MakeMIMEEntity(
-    Subject => $ARGS{'UpdateSubject'},
-    Body    => $ARGS{'UpdateContent'},
-);
-
-my ( $id, $msg, $txn ) = $TicketObj->$action(
-    CcMessageTo  => $ARGS{'UpdateCc'},
-    BccMessageTo => $ARGS{'UpdateBcc'},
-    MIMEObj      => $Message,
-    TimeTaken    => $ARGS{'UpdateTimeWorked'},
-    DryRun       => 1
-);
-unless ( $id && $txn ) {
-    $RT::Logger->error("Couldn't fire '$action' action: $msg");
-    return ();
-}
-
-my @recipients;
-foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
-    my $action = $scrip->ActionObj->Action;
-    next unless $action->isa('RT::Action::SendEmail');
-
-    foreach my $type qw(To Cc Bcc) {
-        push @recipients, $action->$type();
-    }
-}
-return @recipients;
-</%INIT>
-</%METHOD>
-
-<%METHOD GetRecipientsOnCreate>
-<%INIT>
-my $action;
-my $Message = MakeMIMEEntity(
-    Subject => $ARGS{'Subject'},
-    Cc => $ARGS{'Cc'},
-    Body    => $ARGS{'Content'},
-);
-
-my $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
-my ( $id, $txn, $msg ) = $TicketObj->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 ( $id && $txn ) {
-    $RT::Logger->error("Couldn't fire '$action' action: $msg");
-    return ();
-}
-
-my @recipients;
-foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
-    my $action = $scrip->ActionObj->Action;
-    next unless $action->isa('RT::Action::SendEmail');
-
-    foreach my $type qw(To Cc Bcc) {
-        push @recipients, $action->$type();
-    }
-}
-return @recipients;
-</%INIT>
-</%METHOD>

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


More information about the Rt-commit mailing list