[Rt-commit] rt branch, 4.2/update-subject-from-article, created. rt-4.0.2-151-ga0f8c62

Kevin Falcone falcone at bestpractical.com
Fri Aug 26 19:38:35 EDT 2011


The branch, 4.2/update-subject-from-article has been created
        at  a0f8c62259e73e230cbc172a7d2102721d885cd4 (commit)

- Log -----------------------------------------------------------------
commit 02c13b3f67bd74fa99e42d1257cea6fbc641e3bf
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Aug 17 17:35:34 2011 -0400

    Unroll this loop so we can do more work in it

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index cab33c4..bc4afde 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -137,7 +137,10 @@ if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
 
 my %include = (Name => 1, Summary => 1);
 my $cfs = $ClassObj->ArticleCustomFields;
-$include{"CF-Title-".$_->Id} = $include{"CF-Value-".$_->Id} = 1 while $_ = $cfs->Next;
+
+while ( my $cf= $cfs->Next ) {
+    $include{"CF-Title-".$cf->Id} = $include{"CF-Value-".$cf->Id} = 1;
+}
 
 if  ( $Submitted ) {
     if ( $Disabled != $ClassObj->Disabled) {

commit 35e822a8c65b2d5347c435a5fb8be4005e993c74
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 11:29:36 2011 -0400

    Add a dropdown to pick the Subject CF

diff --git a/lib/RT/Class.pm b/lib/RT/Class.pm
index dbd83be..83d1d9b 100644
--- a/lib/RT/Class.pm
+++ b/lib/RT/Class.pm
@@ -450,6 +450,12 @@ sub RemoveFromObject {
     return ( $oid, $msg );
 }
 
+sub SubjectOverride {
+    my $self = shift;
+    my $override = $self->FirstAttribute('SubjectOverride');
+    return $override ? $override->Content : '';
+}
+
 
 
 =head2 id
diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index bc4afde..849cac9 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -90,6 +90,19 @@
 % }
 </ul>
 
+% if ( @$subject_cfs ) {
+<h3>Change email subject:</h3>
+<p><&|/l&>If a Custom Field is selected, the Subject of your outgoing email will be overridden by this article.</&></p>
+
+<& /Widgets/Form/Select,
+    Name         => 'SubjectOverride',
+    DefaultLabel => 'No Subject Override',
+    Values       => $subject_cfs,
+    ValuesLabel  => $subject_cf_labels,
+    CurrentValue => $ClassObj->SubjectOverride,
+&>
+% }
+
 <& /Elements/Submit &>
 </form>
 
@@ -136,10 +149,15 @@ if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
 }
 
 my %include = (Name => 1, Summary => 1);
+my $subject_cfs = [];
+my $subject_cf_labels = {};
+
 my $cfs = $ClassObj->ArticleCustomFields;
 
 while ( my $cf= $cfs->Next ) {
     $include{"CF-Title-".$cf->Id} = $include{"CF-Value-".$cf->Id} = 1;
+    push @$subject_cfs,$cf->Id;
+    $subject_cf_labels->{$cf->Id} = $cf->Name;
 }
 
 if  ( $Submitted ) {

commit 9579e53153843b226c24334d280a5f3a23d1526b
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 18:14:09 2011 -0400

    Store the results of picking your SubjectOverride

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index 849cac9..649061d 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -173,6 +173,16 @@ if  ( $Submitted ) {
             $ClassObj->SetAttribute(Name => "Skip-$_", Content => 1);
         }
     }
+
+    if ( $ARGS{SubjectOverride} ) {
+        my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $ARGS{SubjectOverride} );
+        push @results, $ok ? loc('Added Subject Override: [_1]', $ARGS{SubjectOverride}) :
+                             loc('Unable to add Subject Override: [_1]', $ARGS{SubjectOverride});
+    } else {
+        my ($ok, $msg) = $ClassObj->DeleteAttribute('SubjectOverride');
+        push @results, $ok ? loc('Added Subject Override: [_1]', $ARGS{SubjectOverride}) :
+                             loc('Unable to add Subject Override: [_1]', $ARGS{SubjectOverride});
+    }
 }
 
 $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;

commit 7744ebdbdb1af048246f4e64be708d1387c35fee
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 18:33:53 2011 -0400

    Use the Process method to handle the default value value

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index 649061d..bd409c9 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -174,14 +174,20 @@ if  ( $Submitted ) {
         }
     }
 
-    if ( $ARGS{SubjectOverride} ) {
-        my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $ARGS{SubjectOverride} );
-        push @results, $ok ? loc('Added Subject Override: [_1]', $ARGS{SubjectOverride}) :
-                             loc('Unable to add Subject Override: [_1]', $ARGS{SubjectOverride});
+    my $override = $m->comp('/Widgets/Form/Select:Process',
+        Default   => 1,
+        Arguments => \%ARGS,
+        Name      => 'SubjectOverride'
+    );
+
+    if ( $override ) {
+        my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $override );
+        push @results, $ok ? loc('Added Subject Override: [_1]', $override) :
+                             loc('Unable to add Subject Override: [_1]', $override);
     } else {
         my ($ok, $msg) = $ClassObj->DeleteAttribute('SubjectOverride');
-        push @results, $ok ? loc('Added Subject Override: [_1]', $ARGS{SubjectOverride}) :
-                             loc('Unable to add Subject Override: [_1]', $ARGS{SubjectOverride});
+        push @results, $ok ? loc('Added Subject Override: [_1]', $override) :
+                             loc('Unable to add Subject Override: [_1]', $override);
     }
 }
 

commit d53afd711e102cef2c3e736193a7ed4af67d83ad
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 18:46:42 2011 -0400

    Better messages (not ids)

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index bd409c9..5541b20 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -182,12 +182,12 @@ if  ( $Submitted ) {
 
     if ( $override ) {
         my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $override );
-        push @results, $ok ? loc('Added Subject Override: [_1]', $override) :
-                             loc('Unable to add Subject Override: [_1]', $override);
+        push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
+                             loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
     } else {
         my ($ok, $msg) = $ClassObj->DeleteAttribute('SubjectOverride');
-        push @results, $ok ? loc('Added Subject Override: [_1]', $override) :
-                             loc('Unable to add Subject Override: [_1]', $override);
+        push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
+                             loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
     }
 }
 

commit b9caf8464d02beeca693299979206256b659d54d
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 20:02:21 2011 -0400

    Don't update when this is the already set value
    
    This should really refactor into a SetSubjectOverride routine that uses
    Update from Record

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index 5541b20..ff8124c 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -181,9 +181,11 @@ if  ( $Submitted ) {
     );
 
     if ( $override ) {
-        my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $override );
-        push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
-                             loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
+        if ( $override != $ClassObj->SubjectOverride ) {
+            my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $override );
+            push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
+                loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
+        }
     } else {
         my ($ok, $msg) = $ClassObj->DeleteAttribute('SubjectOverride');
         push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :

commit fabb4d9aedc3886f9d0ef95a7c29458def9db492
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 20:17:29 2011 -0400

    Move the setting into the library
    
    We should do this for all the attribute munging

diff --git a/lib/RT/Class.pm b/lib/RT/Class.pm
index 83d1d9b..d08972a 100644
--- a/lib/RT/Class.pm
+++ b/lib/RT/Class.pm
@@ -456,7 +456,27 @@ sub SubjectOverride {
     return $override ? $override->Content : '';
 }
 
+sub SetSubjectOverride {
+    my $self = shift;
+    my $override = shift;
+
+    if ( $override == $self->SubjectOverride ) {
+        return (0, "SubjectOverride is already set to that");
+    }
 
+    my $cf = RT::CustomField->new($self->CurrentUser);
+    $cf->Load($override);
+
+    if ( $override ) {
+        my ($ok, $msg) = $self->SetAttribute( Name => 'SubjectOverride', Content => $override );
+        return ($ok, $ok ? $self->loc('Added Subject Override: [_1]', $cf->Name) :
+                           $self->loc('Unable to add Subject Override: [_1] [_2]', $cf->Name, $msg));
+    } else {
+        my ($ok, $msg) = $self->DeleteAttribute('SubjectOverride');
+        return ($ok, $ok ? $self->loc('Removed Subject Override') :
+                           $self->loc('Unable to add Subject Override: [_1] [_2]', $cf->Name, $msg));
+    }
+}
 
 =head2 id
 
diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index ff8124c..c949e67 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -128,8 +128,17 @@ if ($Create) {
 }
 
 if ($ClassObj->Id()) {
+
+    if ($ARGS{SubjectOverride}) {
+        $ARGS{SubjectOverride} = $m->comp('/Widgets/Form/Select:Process',
+            Arguments => \%ARGS,
+            Name      => 'SubjectOverride',
+            DefaultValue => (''),
+        );
+    }
+
     $ARGS{HotList} ||= 0 if $Submitted;
-    my @attribs= qw(Description Name HotList);
+    my @attribs= qw(Description Name HotList SubjectOverride);
     push @results, UpdateRecordObject( AttributesRef => \@attribs,
                                        Object => $ClassObj,
                                        ARGSRef => \%ARGS);
@@ -174,23 +183,6 @@ if  ( $Submitted ) {
         }
     }
 
-    my $override = $m->comp('/Widgets/Form/Select:Process',
-        Default   => 1,
-        Arguments => \%ARGS,
-        Name      => 'SubjectOverride'
-    );
-
-    if ( $override ) {
-        if ( $override != $ClassObj->SubjectOverride ) {
-            my ($ok, $msg) = $ClassObj->SetAttribute( Name => 'SubjectOverride', Content => $override );
-            push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
-                loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
-        }
-    } else {
-        my ($ok, $msg) = $ClassObj->DeleteAttribute('SubjectOverride');
-        push @results, $ok ? loc('Added Subject Override: [_1]', $subject_cf_labels->{$override}) :
-                             loc('Unable to add Subject Override: [_1] [_2]', $subject_cf_labels->{$override}, $msg);
-    }
 }
 
 $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;

commit eb5e9cc38e9ea252bc312c2bdadbb5ff3c53eb9f
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Thu Aug 25 19:54:41 2011 -0400

    Redirect after we actually process everything
    
    This also means that messages from the other updates are shown to the
    user.
    (cherry picked from commit c8121d41e4cf3191376e3878f88450eaeefdc3c2)

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index c949e67..b0e289e 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -144,12 +144,6 @@ if ($ClassObj->Id()) {
                                        ARGSRef => \%ARGS);
 }
 
-# This code does automatic redirection if any updates happen.
-MaybeRedirectForResults(
-    Actions     => \@results,
-    Arguments   => { id => $ClassObj->Id },
-);
-
 #we're asking about enabled on the web page but really care about disabled.
 if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
     $Disabled = 0;
@@ -185,6 +179,13 @@ if  ( $Submitted ) {
 
 }
 
+# This code does automatic redirection if any updates happen.
+MaybeRedirectForResults(
+    Actions     => \@results,
+    Arguments   => { id => $ClassObj->Id },
+);
+
+
 $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
 $include{$_} = $include{$_} ? " CHECKED" : "" for keys %include;
 

commit 8d4d5506e9b456cc4367ee2b6f9e27443883cde6
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Aug 26 18:35:54 2011 -0400

    Pass the Queue so that Articles can limit to it
    
    Otherwise you get an ugly error in the logs and Articles refuse to limit
    the Classes to the current Queue.  This means an article in any class or
    a hotlist in any class (given that you can see them) would show up in
    the search, since we're not correctly limiting to the Queue.
    (cherry picked from commit be372d2b90b8d95af4549fe31fe0cf3908fa6c15)

diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 025167b..7adbbb8 100755
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -172,7 +172,7 @@
 <td colspan="6">
 <&|/l&>Describe the issue below</&>:<br />
 % if ( RT->Config->Get('ArticleOnTicketCreate')) {
-<& /Articles/Elements/BeforeMessageBox, %ARGS &>
+<& /Articles/Elements/BeforeMessageBox, %ARGS, QueueObj => $QueueObj &>
 % }
 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
 % if (exists $ARGS{Content}) {

commit a0f8c62259e73e230cbc172a7d2102721d885cd4
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Aug 26 18:59:32 2011 -0400

    Add a second Articles hook to clobber Ticket Subjects.
    
    Add a SubjectOverride element which Create/Update call out to and which
    modifies ARGSRef to change the subject.  This is controlled by the
    SubjectOverride set on the Class page.

diff --git a/share/html/Articles/Elements/SubjectOverride b/share/html/Articles/Elements/SubjectOverride
new file mode 100644
index 0000000..566d199
--- /dev/null
+++ b/share/html/Articles/Elements/SubjectOverride
@@ -0,0 +1,92 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<%INIT>
+foreach my $arg ( keys %$ARGSRef) {
+
+    my $Queue = $QueueObj || RT::Queue->new($session{CurrentUser});
+    if (!$Queue->Id && $Ticket && $Ticket->Id) {
+        $Queue = $Ticket->QueueObj;
+    }
+
+    my $article = RT::Article->new($session{'CurrentUser'});
+    $article->LoadByInclude(
+        Field => $arg,
+        Value => $ARGSRef->{$arg},
+        Queue => $Queue->Id,
+    );
+    next unless $article && $article->id;
+
+    my $class = $article->ClassObj;
+
+    next unless $class->SubjectOverride;
+
+    my $cfs = $class->ArticleCustomFields;
+    $cfs->Limit( FIELD => 'id', VALUE => $class->SubjectOverride );
+
+    my $subjectCF = $cfs->First;
+    next unless $subjectCF;
+
+    my $subject = $article->CustomFieldValuesAsString($subjectCF->Id);
+
+    $m->callback( CallbackName => 'ProcessContent', Ticket => $Ticket, Article => $article, content => \$subject);
+
+    if ( exists $ARGSRef->{UpdateSubject} ) {
+        $ARGSRef->{UpdateSubject} = $subject;
+    } else {
+        $ARGSRef->{Subject} = $subject;
+    }
+}
+return;
+</%INIT>
+<%ARGS>
+$Ticket => undef
+$ARGSRef => undef
+$results => undef
+$QueueObj => undef
+</%ARGS>
+
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 7adbbb8..306a3dd 100755
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -362,6 +362,8 @@ $QueueObj->Load($Queue) || Abort(loc("Queue [_1] could not be loaded.", $Queue))
 
 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
 
+$m->scomp( '/Articles/Elements/SubjectOverride', ARGSRef => \%ARGS, QueueObj => $QueueObj, results => \@results );
+
 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
 
 my $CFs = $QueueObj->TicketCustomFields();
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 0c41491..41faf76 100755
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -210,6 +210,7 @@ my $TicketObj = LoadTicket($id);
 my @results;
 
 $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, checks_failure => \$checks_failure, results => \@results, CallbackName => 'Initial' );
+$m->scomp( '/Articles/Elements/SubjectOverride', Ticket => $TicketObj, ARGSRef => \%ARGS, results => \@results );
 
 unless($DefaultStatus){
     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());

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


More information about the Rt-commit mailing list