[Rt-commit] rt branch, 4.4/queue-include-article, created. rt-4.4.2-59-g0639ea1

Craig Kaiser craig at bestpractical.com
Thu Dec 28 13:42:04 EST 2017


The branch, 4.4/queue-include-article has been created
        at  0639ea1850493b6d9cc1f6d0c26dbf08f057f2ea (commit)

- Log -----------------------------------------------------------------
commit 0639ea1850493b6d9cc1f6d0c26dbf08f057f2ea
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 28 11:26:41 2017 -0500

    Include Article on ticket create, based on queue
    
    Add functionality to include an Articles content automatically on Ticket create
    for the specified Queue. This feature can be set on Queue create and
    Queue modify.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 4c2f5fb..0997ace 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -155,6 +155,7 @@ sub Create {
         CorrespondAddress => '',
         CommentAddress    => '',
         Lifecycle         => 'default',
+        ArticleIncluded   => undef,
         SubjectTag        => undef,
         Sign              => undef,
         SignAuto          => undef,
@@ -198,8 +199,7 @@ sub Create {
         $self->_NewTransaction( Type => "Create" );
     }
     $RT::Handle->Commit;
-
-    for my $attr (qw/Sign SignAuto Encrypt SLA/) {
+    for my $attr (qw/Sign SignAuto Encrypt SLA ArticleIncluded/) {
         next unless defined $args{$attr};
         my $set = "Set" . $attr;
         my ($status, $msg) = $self->$set( $args{$attr} );
@@ -212,7 +212,33 @@ sub Create {
     return ( $id, $self->loc("Queue created") );
 }
 
+sub ArticleIncluded {
+    my $self = shift;
+    my $value = shift;
+
+    my $attr = $self->FirstAttribute('ArticleIncluded') or return 0;
+    return $attr->Content;
+}
+
+sub SetArticleIncluded {
+    my $self = shift;
+    my $value = shift;
 
+    return ( 0, $self->loc('Permission Denied') )
+        unless $self->CurrentUserHasRight('AdminQueue');
+
+    my $MyArticle = RT::Article->new(RT->SystemUser);
+        if ( $MyArticle->ValidateName($value) and $value ){
+            return (0, $self->loc("Invalid Article Name [_1]", $value));
+    }
+
+    my ($status, $msg) = $self->SetAttribute(
+        Name        => 'ArticleIncluded',
+        Description => 'Include Article on ticket create, for Queue.',
+        Content     => $value,
+    );
+    return (0, $self->loc("Article Included updated to [_1]", $value));
+}
 
 sub Delete {
     my $self = shift;
@@ -906,6 +932,16 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 
 =cut
 
+=head2 ArticleIncluded
+
+The article name to be included on create of any ticket created in the queue.
+The ID value of the article will be loaded from the name, and used to get the article content in Ticket.pm.
+
+
+==head2 SetArticleIncluded
+
+Takes a name value and sets the ArticleIncluded attr for the queue to that name.
+
 =head2 SubjectTag
 
 Returns the current value of SubjectTag. 
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 08169fb..418a2bb 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -239,6 +239,7 @@ sub Create {
         SLA                => undef,
         MIMEObj            => undef,
         _RecordTransaction => 1,
+        ArticleIncluded    => undef,
         @_
     );
 
@@ -280,6 +281,16 @@ sub Create {
         $args{'Status'} = $cycle->DefaultOnCreate;
     }
 
+    if ( $QueueObj->ArticleIncluded ) {
+        my $MyArticle = RT::Article->new(RT->SystemUser);
+        my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+        my $MIMEObj = $args{'MIMEObj'};
+        $MyArticle->LoadByCols(Name => $QueueObj->ArticleIncluded);
+        $ObjectCustomFieldValue->LoadByCols(ObjectId => $MyArticle->id);
+        my $ArticleContent = MIME::Entity->build( Type => "text/plain" , Data => $ObjectCustomFieldValue->Content() );
+        $MIMEObj->add_part($ArticleContent);
+    }
+
     $args{'Status'} = lc $args{'Status'};
     unless ( $cycle->IsValid( $args{'Status'} ) ) {
         return ( 0, 0,
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 75b0e65..e59884b 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -80,6 +80,10 @@
 % }
 </td></tr>
 
+<tr><td align="right"><&|/l&>Include Article</&>:</td>
+  <td colspan="3"><input name="ArticleIncluded" value="<% $ARGS{'ArticleIncluded'} || ($Create ? "" : $QueueObj->ArticleIncluded || '' ) %>" size="20"/></td>
+</tr>
+
 <tr><td align="right"><&|/l&>Subject Tag</&>:</td>
 <td colspan="3"><input name="SubjectTag" value="<% $ARGS{'SubjectTag'} || ($Create ? "" : $QueueObj->SubjectTag || '' ) %>" size="60" /></td>
 </tr>
@@ -185,11 +189,10 @@ unless ($Create) {
         $QueueObj->Load($id) || $QueueObj->Load($Name) || Abort(loc("Couldn't load queue '[_1]'", $Name));
     }
 }
-
 if ( $QueueObj->Id ) {
     $title = loc('Configuration for queue [_1]', $QueueObj->Name );
     my @attribs= qw(Description CorrespondAddress CommentAddress Name SortOrder
-        Sign SignAuto Encrypt Lifecycle SubjectTag SLADisabled Disabled);
+        Sign SignAuto Encrypt Lifecycle ArticleIncluded SubjectTag SLADisabled Disabled);
 
     # we're asking about enabled on the web page but really care about disabled
     if ( $SetEnabled ) {
@@ -215,7 +218,6 @@ if ( $QueueObj->Id ) {
         Object => $QueueObj,
         ARGSRef => \%ARGS
     );
-
     $Disabled = $ARGS{'Disabled'} = $Enabled? 0: 1;
 
     $EnabledChecked = "" if $QueueObj->Disabled;
@@ -264,6 +266,7 @@ $Description => undef
 $CorrespondAddress => undef
 $CommentAddress => undef
 $SetSLAEnabled => undef
+$ArticleIncluded => undef
 $SetEnabled => undef
 $SetCrypt => undef
 $SLAEnabled => undef

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


More information about the rt-commit mailing list